From 3d17f4b4fde9db58d2798a4f0329df4af1b47d4a Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Mon, 13 Jan 2025 22:30:37 +0100 Subject: [PATCH] Pass labels from image to manifest Also fix a duplication bug which will reduce the amount of push builds we're doing --- utils/create-manifest-command.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/utils/create-manifest-command.php b/utils/create-manifest-command.php index b1b0fe6..59528ec 100644 --- a/utils/create-manifest-command.php +++ b/utils/create-manifest-command.php @@ -11,21 +11,33 @@ foreach (array_unique( array_map( - static fn (string $tag): string => str_replace( - array_map( - static fn (string $tag): string => '-' . $tag, - $archs + static fn (string $tag): string => trim( + str_replace( + array_map( + static fn (string $tag): string => '-' . $tag, + $archs + ), + '', + $tag, ), - '', - $tag, ), file('tags-to-push.list') ) ) as $image) { - $dockerFilename = 'docker-file-' . md5($argv[1] . "/" . trim($image)); - file_put_contents($dockerFilename, 'FROM ' . $argv[1] . "/" . trim($image) . '-${TARGETARCH}'); + $labels = []; + $imageName = $argv[1] . "/" . trim($image); - file_put_contents('./command.sh', "\ndocker buildx build -f " . $dockerFilename . " --platform=linux/" . implode(",linux/", $archs) . " -t \"" . $argv[1] . "/" . trim($image) . "\" --push .\n", \FILE_APPEND); + $jsonString = null; + exec('docker inspect --format=\'{{json .Config.Labels}}\' ' . $imageName . '-' . $archs[0], $jsonString); + $json = json_decode($jsonString[0], true); + foreach ($json as $labelKey => $labelValue) { + $labels[] = '--label ' . $labelKey . '="' . $labelValue . '"'; + } + + $dockerFilename = 'docker-file-' . md5($imageName); + file_put_contents($dockerFilename, 'FROM ' . $imageName . '-${TARGETARCH}'); + + file_put_contents('./command.sh', "\ndocker buildx build " . implode(' ', $labels) . " -f " . $dockerFilename . " --platform=linux/" . implode(",linux/", $archs) . " -t \"" . $imageName . "\" --push .\n", \FILE_APPEND); } file_put_contents(