Skip to content

Commit

Permalink
Handling failures of docker build and push commands
Browse files Browse the repository at this point in the history
  • Loading branch information
spamoom committed May 14, 2020
1 parent 7b4234e commit db8b984
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
19 changes: 15 additions & 4 deletions app/Commands/DockerBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ public function handle()
$this->line("Building docker images for services with tag {$tag}: " . implode(',', $services));

foreach ($services as $service) {
$this->callBuild($tag, $service);
if (!$this->callBuild($tag, $service)) {
return 1;
}
}

$this->info("Docker images built.");
}

protected function callBuild(string $tag, string $service = null): void
protected function callBuild(string $tag, string $service = null): bool
{
$process = new Process([
'docker-compose',
Expand All @@ -89,9 +91,18 @@ protected function callBuild(string $tag, string $service = null): void
], null, 1200); // 20min timeout

$process->start();
$process->wait();

foreach ($process as $data) {
echo $data;
if ($process->getExitCode() !== 0) {
foreach ($process as $data) {
echo $data;
}

$this->error("Unable to push all items to AWS, check the above output for reasons why.");
return false;
}

echo $process->getOutput();
return true;
}
}
19 changes: 15 additions & 4 deletions app/Commands/DockerPushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ public function handle()
$this->line("Pushing docker images for services with tag {$tag}: " . implode(',', $services));

foreach ($services as $service) {
$this->callPush($tag, $service);
if (!$this->callPush($tag, $service)) {
return 1;
}
}

$this->info("Docker images pushed.");
}

protected function callPush(string $tag, string $service = null): void
protected function callPush(string $tag, string $service = null): bool
{
$process = new Process([
'docker-compose',
Expand All @@ -101,9 +103,18 @@ protected function callPush(string $tag, string $service = null): void
], null, 1200); // 20min timeout

$process->start();
$process->wait();

foreach ($process as $data) {
echo $data;
if ($process->getExitCode() !== 0) {
foreach ($process as $data) {
echo $data;
}

$this->error("Unable to push all items to AWS, check the above output for reasons why.");
return false;
}

echo $process->getOutput();
return true;
}
}

0 comments on commit db8b984

Please sign in to comment.