Skip to content

Commit

Permalink
Add --cache-from arguments to build command
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdannbv committed May 7, 2024
1 parent 32b7a04 commit 59a8f02
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions generate-matrix-strategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'os' => 'ubuntu-latest',
'tags' => $tags,
'runs' => [
'build' => getBuildCommand($tags, $dir),
'build' => getBuildCommand($tags, $dir, latest: $isLatest),
'push' => getPushCommand($tags),
],
];
Expand Down Expand Up @@ -66,10 +66,19 @@ function getVersionTags(string $repository, string $version, string $variant, bo
return $tags;
}

function getBuildCommand(array $tags, string $dir, string $platform = 'linux/amd64'): string
function getBuildCommand(array $tags, string $dir, string $platform = 'linux/amd64', bool $latest = false): string
{
$tagArgs = implode(' ', array_map(fn($tag) => '--tag ' . $tag, $tags));
return sprintf('docker build --platform %s %s %s', $platform, $tagArgs, $dir);

$cacheTags = $tags;
array_shift($cacheTags);
if ($latest) {
array_pop($cacheTags);
}
$cacheFromArgs = implode(' ', array_map(fn($tag) => '--cache-from ' . $tag, $cacheTags));


return sprintf('docker build --platform %s %s %s %s', $platform, $cacheFromArgs, $tagArgs, $dir);
}

function getPushCommand(array $tags): string
Expand Down

0 comments on commit 59a8f02

Please sign in to comment.