Commit f2d2f58b authored by David Johnson's avatar David Johnson

Fix new API-related bugs in the create-docker-image script and lib.

parent 7a71e8d3
#!/usr/bin/perl -w
#!/usr/bin/perl
#
# Copyright (c) 2017 University of Utah and the Flux Group.
#
......@@ -24,6 +24,7 @@
use English;
use Getopt::Std;
use strict;
use warnings;
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
......@@ -60,6 +61,7 @@ use libgenvnode;
#use libvnode;
use libutil;
use dockerclient;
use JSON::PP;
#
# No configure vars.
......@@ -124,6 +126,9 @@ if (!$usecli) {
$client = dockerclient->new();
$client->debug($debug);
}
if ($debug) {
TBDebugTimeStampsOn();
}
#
# First, try to login to the registry with user/pass.
......@@ -188,7 +193,7 @@ if ($usecli) {
}
else {
my ($code,$content,$resp) = $client->container_commit(
$vnodeid,$fullimagename,$user,$pass);
$vnodeid,"$registry/$repo",$tag);
$? = $code;
}
if ($?) {
......@@ -204,7 +209,7 @@ if ($initstatus ne VNODE_STATUS_STOPPED()) {
}
else {
my ($code,$content,$resp) = $client->container_start($vnodeid);
$? = code;
$? = $code;
}
if ($?) {
print STDERR "WARNING: error restarting container $vnodeid; ignoring!\n";
......@@ -222,7 +227,26 @@ while ($i > 0) {
system("docker push $fullimagename");
}
else {
my ($code,$content,$resp) = $client->image_push($fullimagename);
my ($code,$content,$resp) = $client->image_push(
$fullimagename,undef,$user,$pass,
sub {
eval {
my $json = decode_json($_[0]);
if (exists($json->{"id"})) {
print $json->{"id"}.": ".$json->{"status"};
if (exists($json->{"progress"})) {
print " ".$json->{"progress"};
}
print "\n";
}
elsif (exists($json->{"status"})) {
print $json->{"status"}."\n";
}
};
if ($@) {
print $_[0];
}
});
$? = $code;
}
if ($? == 0) {
......
......@@ -160,7 +160,7 @@ sub _handle_response($$) {
$content = $content->{"message"};
}
}
$self->dprint(5,"response decoded content = ".Dumper($content)."\n");
$self->dprint(6,"response decoded content = ".Dumper($content)."\n");
}
if ($success) {
return (0,$content,$resp);
......@@ -669,9 +669,13 @@ sub image_pull($$;$$) {
$registry = "$1$2";
}
my $auth = encode_base64url(
'{"username":"'.$user.'","password":"'.$pass.'"}'."");
'{"serveraddress":"$registry","username":"'.$user.'","password":"'.$pass.'"}'."");
chomp($auth);
$auth =~ tr/\r\n//;
my $pc = (3 - (length($auth) % 3));
if ($pc) {
$auth .= '=' x $pc;
}
$headers->header('X-Registry-Auth' => $auth);
}
my $uimage = uri_escape($image);
......@@ -681,14 +685,15 @@ sub image_pull($$;$$) {
$METHODS{'image_push'} = {
'required' => ['image'],
'optional' => ['user','pass'],
'optional' => ['tag','user','pass'],
'help' => "Push the given image",
'phelp' => { 'id' => "The full image name or id",
'tag' => "The image tag to push",
'user' => "The username to authenticate to the registry",
'pass' => "The password to authenticate to the registry" }
};
sub image_push($$;$$) {
my ($self,$image,$user,$pass) = @_;
sub image_push($$;$$$$) {
my ($self,$image,$tag,$user,$pass,$callback) = @_;
my $headers = HTTP::Headers->new();
if (defined($user) && $user ne "") {
......@@ -699,14 +704,22 @@ sub image_push($$;$$) {
$registry = "$1$2";
}
my $auth = encode_base64url(
'{"username":"'.$user.'","password":"'.$pass.'"}'."");
'{"serveraddress":"$registry","username":"'.$user.'","password":"'.$pass.'"}'."");
chomp($auth);
$auth =~ tr/\r\n//;
my $pc = (3 - (length($auth) % 3));
if ($pc) {
$auth .= '=' x $pc;
}
$headers->header('X-Registry-Auth' => $auth);
}
my $uimage = uri_escape($image);
my $uri = "/images/$uimage/push";
if (defined($tag) and $tag ne '') {
$uri .= "?tag=$tag";
}
return $self->_post("/images/$uimage/push",$headers);
return $self->_post($uri,$headers,undef,$callback);
}
$METHODS{'image_build_from_tar_bytes'} = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment