Skip to content

Commit

Permalink
Also parse the base container annotation for kiwi container builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Oct 2, 2024
1 parent 8febaf7 commit 0bf579a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Build/Docker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,19 @@ sub parse {
}

sub showcontainerinfo {
my ($disturl, $release);
my ($disturl, $release, $annotationfile);
while (@ARGV) {
if (@ARGV > 2 && $ARGV[0] eq '--disturl') {
(undef, $disturl) = splice(@ARGV, 0, 2);
} elsif (@ARGV > 2 && $ARGV[0] eq '--release') {
(undef, $release) = splice(@ARGV, 0, 2);
} elsif (@ARGV > 2 && $ARGV[0] eq '--annotationfile') {
(undef, $annotationfile) = splice(@ARGV, 0, 2);
} else {
last;
}
}
my ($fn, $image, $taglist, $annotationfile) = @ARGV;
my ($fn, $image, $taglist) = @ARGV;
local $Build::Kiwi::urlmapper = sub { return $_[0] };
my $cf = { '__dockernoname' => 1 };
$cf->{'buildrelease'} = $release if defined $release;
Expand Down
32 changes: 31 additions & 1 deletion Build/Kiwi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ sub unify {
return grep(delete($h{$_}), @_);
}

sub slurp {
my ($fn) = @_;
local *F;
return undef unless open(F, '<', $fn);
local $/ = undef; # Perl slurp mode
my $content = <F>;
close F;
return $content;
}

sub expandFallBackArchs {
my ($fallbackArchXML, @archs) = @_;
my %fallbacks;
Expand Down Expand Up @@ -607,7 +617,7 @@ sub show {
}

sub showcontainerinfo {
my ($disturl, $arch, $buildflavor, $release);
my ($disturl, $arch, $buildflavor, $release, $annotationfile);
while (@ARGV) {
if (@ARGV > 2 && $ARGV[0] eq '--disturl') {
(undef, $disturl) = splice(@ARGV, 0, 2);
Expand All @@ -617,6 +627,8 @@ sub showcontainerinfo {
(undef, $buildflavor) = splice(@ARGV, 0, 2);
} elsif (@ARGV > 2 && $ARGV[0] eq '--release') {
(undef, $release) = splice(@ARGV, 0, 2);
} elsif (@ARGV > 2 && $ARGV[0] eq '--annotationfile') {
(undef, $annotationfile) = splice(@ARGV, 0, 2);
} else {
last;
}
Expand Down Expand Up @@ -644,6 +656,16 @@ sub showcontainerinfo {
$profile = $d->{'profiles'}->[0];
}

# parse annotation file
my $annotation;
if ($annotationfile) {
$annotation = slurp($annotationfile);
$annotation = $annotation ? Build::SimpleXML::parse($annotation) : undef;
$annotation = $annotation && ref($annotation) eq 'HASH' ? $annotation->{'annotation'} : undef;
$annotation = $annotation && ref($annotation) eq 'ARRAY' ? $annotation->[0] : undef;
$annotation = undef unless ref($annotation) eq 'HASH';
}

my @repos;
for my $repo (@{$d->{'imagerepos'} || []}) {
push @repos, { 'url' => $repo->{'url'}, '_type' => {'priority' => 'number'} };
Expand All @@ -663,6 +685,14 @@ sub showcontainerinfo {
$containerinfo->{'file'} = $image if defined $image;
$containerinfo->{'disturl'} = $disturl if defined $disturl;
$containerinfo->{'milestone'} = $d->{'milestone'} if defined $d->{'milestone'};
if ($annotation && $d->{'basecontainer'}) {
for (qw{registry_refname registry_digest registry_fatdigest}) {
next unless $annotation->{$_} && ref($annotation->{$_}) eq 'ARRAY';
my $v = $annotation->{$_}->[0];
$v = $v->{'_content'} if $v && ref($v) eq 'HASH';
$containerinfo->{"base_$_"} = $v if $v;
}
}
print Build::SimpleJSON::unparse($containerinfo)."\n";
}

Expand Down
3 changes: 2 additions & 1 deletion build-recipe-docker
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ recipe_build_docker() {
args=()
test -n "$DISTURL" && args=("${args[@]}" --disturl "$DISTURL")
test -n "$RELEASE" && args=("${args[@]}" --release "$RELEASE")
perl -I$BUILD_DIR -MBuild::Docker -e Build::Docker::showcontainerinfo -- "${args[@]}" "$BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE" "$FILENAME.tar" "$ALLTAGS" containers/annotation > "$BUILD_ROOT$TOPDIR/DOCKER/$FILENAME.containerinfo"
test -s "containers/annotation" && args=("${args[@]}" --annotationfile containers/annotation)
perl -I$BUILD_DIR -MBuild::Docker -e Build::Docker::showcontainerinfo -- "${args[@]}" "$BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE" "$FILENAME.tar" "$ALLTAGS" > "$BUILD_ROOT$TOPDIR/DOCKER/$FILENAME.containerinfo"

# copy over .packages files
for i in basepackages packages ; do
Expand Down
3 changes: 2 additions & 1 deletion build-recipe-fissile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ recipe_build_fissile() {
args=()
test -n "$DISTURL" && args=("${args[@]}" --disturl "$DISTURL")
test -n "$RELEASE" && args=("${args[@]}" --release "$RELEASE")
perl -I$BUILD_DIR -MBuild::Docker -e Build::Docker::showcontainerinfo -- "${args[@]}" '' "$filename.tar" "$image" containers/annotation > "$BUILD_ROOT$TOPDIR/FISSILE/$filename.containerinfo"
test -s "containers/annotation" && args=("${args[@]}" --annotationfile containers/annotation)
perl -I$BUILD_DIR -MBuild::Docker -e Build::Docker::showcontainerinfo -- "${args[@]}" '' "$filename.tar" "$image" > "$BUILD_ROOT$TOPDIR/FISSILE/$filename.containerinfo"
done

recipe_cleanup_fissile
Expand Down
2 changes: 2 additions & 0 deletions build-recipe-kiwi
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ postprocess_kiwi_containers() {
local args=(--arch "${BUILD_ARCH%%:*}" --buildflavor "$BUILD_FLAVOR")
test -n "$DISTURL" && args=("${args[@]}" --disturl "$DISTURL")
test -n "$RELEASE" && args=("${args[@]}" --release "$RELEASE")
test -s "containers/annotation" && args=("${args[@]}" --annotationfile containers/annotation)

for r in $BUILD_ROOT/$TOPDIR/KIWI/*.tar ; do
test -e "$r" && perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::showcontainerinfo -- "${args[@]}" $BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE "$r" > "${r%.tar}.containerinfo"
if test -s "${r%.tar}.containerinfo" ; then
Expand Down

0 comments on commit 0bf579a

Please sign in to comment.