Add optional "--dry-run" flag for pre-testing "heavy" pushes

This commit is contained in:
Tianon Gravi 2019-05-10 16:55:53 -07:00
parent db8b401468
commit d1cb5996f7
1 changed files with 10 additions and 1 deletions

View File

@ -11,6 +11,8 @@ use Mojo::UserAgent;
use Mojo::Util;
my $publicProxy = $ENV{DOCKERHUB_PUBLIC_PROXY} || die 'missing DOCKERHUB_PUBLIC_PROXY env (https://github.com/tianon/dockerhub-public-proxy)';
my $dryRun = ($ARGV[0] || '') eq '--dry-run';
shift @ARGV if $dryRun;
my $ua = Mojo::UserAgent->new->max_redirects(10)->connect_timeout(120)->inactivity_timeout(120);
$ua->transactor->name(join ' ',
@ -381,6 +383,8 @@ Mojo::Promise->map({ concurrency => 8 }, sub ($img) {
return head_manifest_p($org, $repo, $manifestListDigest)->then(sub ($exists) {
# if we already have the manifest we're planning to push in the namespace where we plan to push it, we can skip all blob mounts! \m/
return if $exists;
# (we can also skip if we're in "dry run" mode since we only care about the final manifest matching in that case)
return if $dryRun;
return (
@neededArtifactPromises
@ -426,7 +430,12 @@ Mojo::Promise->map({ concurrency => 8 }, sub ($img) {
# let's do one final check of the tag we're pushing to see if it's already the manifest we expect it to be (to avoid making literally every image constantly "Updated a few seconds ago" all the time)
return get_manifest_p($org, $repo, $tag)->then(sub ($manifestData = undef) {
if ($manifestData && $manifestData->{digest} eq $manifestListDigest) {
say "Skipping $org/$repo:$tag ($manifestListDigest)";
say "Skipping $org/$repo:$tag ($manifestListDigest)" unless $dryRun; # if we're in "dry run" mode, we need clean output
return;
}
if ($dryRun) {
say "Would push $org/$repo:$tag ($manifestListDigest)";
return;
}