Skip to content

Commit

Permalink
[backend] fix publishing of virtual containers
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Jun 8, 2018
1 parent f2d4cbd commit c64ef30
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/backend/bs_publish
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,6 @@ sub publish {
if (!$blobdir) {
$blobdir = "$uploaddir/publisher.$$.blobs";
BSUtil::cleandir($blobdir);
rmdir($blobdir) || die("rmdir $blobdir: $!\n");
mkdir_p($blobdir);
}
if (! -e "$blobdir/$bin") {
Expand Down Expand Up @@ -1621,12 +1620,12 @@ sub publish {
$p = "$bin";
} elsif ($bin =~ /\.containerinfo$/) {
# handle the case wjere there is a containerinfo with no tar file
eval { $containerinfo = BSRepServer::Containerinfo::readcontainerinfo($r, "$1.containerinfo") };
eval { $containerinfo = BSRepServer::Containerinfo::readcontainerinfo($r, $bin) };
next unless $containerinfo;
next unless $containerinfo->{'tar_manifest'} && $containerinfo->{'file'} =~ /\.tar$/ && ! -e "$r/$containerinfo->{'file'}";
$containerinfo->{'arch'} = $arch;
$p = "$arch/$containerinfo->{'file'}";
$containers{$p} = $containerinfo;
$p = $multicontainer ? "$arch/$containerinfo->{'file'}" : $containerinfo->{'file'};
$containers{$p} = $containerinfo;
if ($bin =~ /((.*-Build\d.*?)(?:\.docker)?)\.containerinfo$/) {
$kiwimedium{$p} = "$arch/$2" if -e "$r/$2.packages";
} elsif ($bin =~ /(.*)\.containerinfo$/) {
Expand Down Expand Up @@ -2811,6 +2810,7 @@ sub upload_all_containers {
}

for my $p (sort keys %allrefs_pp_lastp) {
mkdir_p($extrep);
if (@{$allrefs_pp{$p} || []}) {
# write readme file where to find the container
unlink("$extrep/$p");
Expand Down
46 changes: 25 additions & 21 deletions src/backend/bs_regpush
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@ sub tags_from_digestfile {
}

sub construct_container_tar {
my ($containerinfo) = @_;
my ($containerinfofile) = @_;

die("Must specify a blobdir for containerinfos\n") unless $blobdir;
my $containerinfo_json = readstr($containerinfofile);
my $containerinfo = JSON::XS::decode_json($containerinfo_json);
my $manifest = $containerinfo->{'tar_manifest'};
my $mtime = $containerinfo->{'tar_mtime'};
my $blobids = $containerinfo->{'tar_blobids'};
Expand All @@ -358,6 +362,20 @@ sub construct_container_tar {
return \@tar;
}

sub open_tarfile {
my ($tarfile) = @_;

my ($tar, $tarfd);
if ($tarfile =~ /\.containerinfo$/) {
$tar = construct_container_tar($tarfile);
} else {
open($tarfd, '<', $tarfile) || die("$tarfile: $!\n");
$tar = BSTar::list($tarfd);
$_->{'file'} = $tarfd for @$tar;
}
return ($tar, $tarfd);
}

sub die_with_usage {
die <<'END';
usage: bs_regpush [options] <registryserver> repository tar [tar...]
Expand Down Expand Up @@ -468,12 +486,9 @@ if ($use_image_tags && @tarfiles > 1) {
# make sure all tar files contain the same tags
my $imagetags;
for my $tarfile (@tarfiles) {
local *TAR;
open(TAR, '<', $tarfile) || die("$tarfile: $!\n");
my $tar = BSTar::list(\*TAR);
$_->{'file'} = \*TAR for @$tar;
my ($tar, $tarfd) = open_tarfile($tarfile);
my %tar = map {$_->{'name'} => $_} @$tar;
my $manifest = BSContar::get_manifest(\%tar);
my ($manifest_ent, $manifest) = BSContar::get_manifest(\%tar);
my @imagetags = @{$manifest->{'RepoTags'} || []};
s/.*:// for @imagetags;
my $it = join(', ', sort(BSUtil::unify(@imagetags)));
Expand All @@ -482,26 +497,15 @@ if ($use_image_tags && @tarfiles > 1) {
$imagetags = $it;
push @tags, @imagetags;
}
close(TAR);
close $tarfd if $tarfd;
}
$use_image_tags = 0;
}

my @multimanifests;
my %multiplatforms;
for my $tarfile (@tarfiles) {
local *TAR;
my $tar;
if ($tarfile =~ /\.containerinfo$/) {
die("Must specify a blobdir for containerinfos\n") unless $blobdir;
my $containerinfo_json = readstr($tarfile);
my $containerinfo = JSON::XS::decode_json($containerinfo_json);
$tar = construct_container_tar($containerinfo);
} else {
open(TAR, '<', $tarfile) || die("$tarfile: $!\n");
$tar = BSTar::list(\*TAR);
$_->{'file'} = \*TAR for @$tar;
}
my ($tar, $tarfd) = open_tarfile($tarfile);
my %tar = map {$_->{'name'} => $_} @$tar;

my ($manifest_ent, $manifest) = BSContar::get_manifest(\%tar);
Expand All @@ -526,7 +530,7 @@ for my $tarfile (@tarfiles) {
my $platformstr = "architecture:$config->{'architecture'} os:$config->{'os'}";
if ($multiplatforms{$platformstr}) {
print "ignoring $tarfile, already have $platformstr\n";
close TAR;
close $tarfd if $tarfd;
next;
}
$multiplatforms{$platformstr} = 1;
Expand Down Expand Up @@ -579,7 +583,7 @@ for my $tarfile (@tarfiles) {
# upload to server
blob_upload($blobid, $layer_ent);
}
close TAR;
close $tarfd if $tarfd;

my $mani = {
'xxx1_schemaVersion' => 2,
Expand Down

0 comments on commit c64ef30

Please sign in to comment.