Skip to content

Commit c529081

Browse files
authored
Merge pull request #259 from WyriHaximusNet/pass-labels-from-image-to-manifest
Pass labels from image to manifest
2 parents 3e838ee + 3d17f4b commit c529081

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

utils/create-manifest-command.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,33 @@
1111

1212
foreach (array_unique(
1313
array_map(
14-
static fn (string $tag): string => str_replace(
15-
array_map(
16-
static fn (string $tag): string => '-' . $tag,
17-
$archs
14+
static fn (string $tag): string => trim(
15+
str_replace(
16+
array_map(
17+
static fn (string $tag): string => '-' . $tag,
18+
$archs
19+
),
20+
'',
21+
$tag,
1822
),
19-
'',
20-
$tag,
2123
),
2224
file('tags-to-push.list')
2325
)
2426
) as $image) {
25-
$dockerFilename = 'docker-file-' . md5($argv[1] . "/" . trim($image));
26-
file_put_contents($dockerFilename, 'FROM ' . $argv[1] . "/" . trim($image) . '-${TARGETARCH}');
27+
$labels = [];
28+
$imageName = $argv[1] . "/" . trim($image);
2729

28-
file_put_contents('./command.sh', "\ndocker buildx build -f " . $dockerFilename . " --platform=linux/" . implode(",linux/", $archs) . " -t \"" . $argv[1] . "/" . trim($image) . "\" --push .\n", \FILE_APPEND);
30+
$jsonString = null;
31+
exec('docker inspect --format=\'{{json .Config.Labels}}\' ' . $imageName . '-' . $archs[0], $jsonString);
32+
$json = json_decode($jsonString[0], true);
33+
foreach ($json as $labelKey => $labelValue) {
34+
$labels[] = '--label ' . $labelKey . '="' . $labelValue . '"';
35+
}
36+
37+
$dockerFilename = 'docker-file-' . md5($imageName);
38+
file_put_contents($dockerFilename, 'FROM ' . $imageName . '-${TARGETARCH}');
39+
40+
file_put_contents('./command.sh', "\ndocker buildx build " . implode(' ', $labels) . " -f " . $dockerFilename . " --platform=linux/" . implode(",linux/", $archs) . " -t \"" . $imageName . "\" --push .\n", \FILE_APPEND);
2941
}
3042

3143
file_put_contents(

0 commit comments

Comments
 (0)