Skip to content

Commit

Permalink
Adds compose v2 support to ecs deploy (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
spamoom authored Jan 5, 2022
1 parent 96aae8a commit acaf8dc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
4 changes: 4 additions & 0 deletions app/Commands/DeployEcsServiceUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ protected function determineControllingTags($taskDefinition, array $targetImages
// Seperate out the tags we want from the target images
return collect($images)
->filter(function ($image) use ($targetImages) {
if (!str_contains($image, ':')) {
return false;
}

[$image, $tag] = explode(':', $image);

return in_array($image, $targetImages);
Expand Down
18 changes: 2 additions & 16 deletions app/Commands/DockerBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ protected function callBuild(string $tag, string $service = null): bool

protected function buildCommandParts(string $service = null): array
{
$composeVersion = $this->determineComposeVersion();
$composeVersion = $this->helpers->docker()->determineComposeVersion();

// Conservatively implement 2.0.0 functionality - some params are duplicated to ensure future compatability
if ($composeVersion >= '2.0.0' && $composeVersion < '2.1.0') {
if ($composeVersion >= '2.0.0') {
return array_filter([
'docker', 'compose',
'-f', 'docker-compose.yml',
Expand All @@ -125,19 +125,5 @@ protected function buildCommandParts(string $service = null): array
]);
}

protected function determineComposeVersion(): string
{
try {
preg_match(
'/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/',
$this->helpers->process()->withCommand(['docker-compose', '-v'])->run(),
$versionMatches
);

return $versionMatches[0];
} catch (ProcessFailed $e) {
// We couldn't determine the docker-compose version, so lets fall back to standard functionality
return false;
}
}
}
46 changes: 38 additions & 8 deletions app/Helpers/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ public function __construct(Command $command, Helpers $helpers)
$this->helpers = $helpers;
}

public function determineComposeVersion(): string
{
try {
preg_match(
'/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/',
$this->helpers->process()->withCommand(['docker-compose', '-v'])->run(),
$versionMatches
);

return $versionMatches[0];
} catch (ProcessFailed $e) {
// We couldn't determine the docker-compose version, so lets fall back to standard functionality
return '1.0.0';
}
}

public function tagImages(?string $service, string $sourceTag, array $newTags): bool
{
$services = $this->getImageUrlsForServices($service ? [$service] : []);
Expand Down Expand Up @@ -116,14 +132,28 @@ public function prefixedTag(): string
public function fetchComposeConfig(): ?array
{
try {
$dockerComposeYml = $this->helpers->process()->withCommand([
'docker-compose',
'-f', 'docker-compose.yml',
'-f', 'docker-compose.prod.yml',
'--log-level', 'ERROR',
'config',
])
->run();

$composeVersion = $this->determineComposeVersion();

// Conservatively implement 2.0.0 functionality - some params are duplicated to ensure future compatability
if ($composeVersion >= '2.0.0') {
$dockerComposeYml = $this->helpers->process()->withCommand([
'docker', 'compose',
'-f', 'docker-compose.yml',
'-f', 'docker-compose.prod.yml',
'config',
])
->run();
} else {
$dockerComposeYml = $this->helpers->process()->withCommand([
'docker-compose',
'-f', 'docker-compose.yml',
'-f', 'docker-compose.prod.yml',
'--log-level', 'ERROR',
'config',
])
->run();
}
} catch (ProcessFailed $e) {
$this->command->error("Unable to get generated config from docker-compose.");
return null;
Expand Down

0 comments on commit acaf8dc

Please sign in to comment.