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(