Skip to content

Commit

Permalink
Adds basic docker-compose v2.0.0 support (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigsansam authored Oct 27, 2021
1 parent 79c5fe7 commit 7bd13b1
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions app/Commands/DockerBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,8 @@ public function handle()

protected function callBuild(string $tag, string $service = null): bool
{
// Filter ensures we don't send a null value in the array
$commandParts = array_filter([
'docker-compose',
'-f', 'docker-compose.yml',
'-f', 'docker-compose.prod.yml',
'build', '--no-cache', $service
]);

try {
$this->helpers->process()->withCommand($commandParts)
$this->helpers->process()->withCommand($this->buildCommandParts($service))
->withEnvironmentVars(['TAG' => $tag])
->withTimeout(1200) // 20mins
->echoLineByLineOutput(true)
Expand All @@ -107,4 +99,42 @@ protected function callBuild(string $tag, string $service = null): bool

return true;
}

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

// Conservatively implement 2.0.0 functionality - some params are duplicated to ensure future compatability
if ($composeVersion >= '2.0.0' && $composeVersion < '2.1.0') {
return array_filter([
'docker', 'compose',
'-f', 'docker-compose.yml',
'-f', 'docker-compose.prod.yml',
'build', '--no-cache', $service
]);
}

return array_filter([
'docker-compose',
'-f', 'docker-compose.yml',
'-f', 'docker-compose.prod.yml',
'build', '--no-cache', $service
]);
}

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;
}
}
}

0 comments on commit 7bd13b1

Please sign in to comment.