diff --git a/rickshaw-run b/rickshaw-run index bf62eb60..5298e5f6 100755 --- a/rickshaw-run +++ b/rickshaw-run @@ -118,9 +118,9 @@ my $roadblock_exit_abort_waiting = 6; my $abort_via_roadblock = 0; my $workshop_base_cmd; my $workshop_force_builds; -my $workshop_refresh_timestamps_token_file; -my $workshop_refresh_timestamps_token; -my $workshop_refresh_timestamps_api_url; +my $quay_refresh_expiration_token_file; +my $quay_refresh_expiration_token; +my $quay_refresh_expiration_api_url; my $quay_image_expiration; my $cs_conf_file; my %cs_conf; @@ -1053,14 +1053,14 @@ sub source_container_image { push(@local_images, $userenv_image); } my $x = 0; - my $refresh_timestamp; - if (defined $workshop_refresh_timestamps_token && defined $workshop_refresh_timestamps_api_url) { + my $refresh_expiration; + if (defined $quay_refresh_expiration_token && defined $quay_refresh_expiration_api_url) { if ($quay_image_expiration =~ m/([0-9]+)w/) { - # weeks days/week hours/day min/hour seconds/min - $refresh_timestamp = time() + ($1 * 7 * 24 * 60 * 60); + # weeks days/week hours/day min/hour seconds/min + $refresh_expiration = time() + ($1 * 7 * 24 * 60 * 60); - my $refresh_timestamp_str = localtime($refresh_timestamp); - printf "Going to refresh image expiration timestamps with this value: %d (%s)\n", $refresh_timestamp, $refresh_timestamp_str; + my $refresh_expiration_str = localtime($refresh_expiration); + printf "Going to refresh image expiration with this value: %d (%s)\n", $refresh_expiration, $refresh_expiration_str; } else { print "Failed to determine quay image expiration weeks\n"; exit 1; @@ -1068,23 +1068,23 @@ sub source_container_image { } while ($x < $i) { printf "Processing stage %d (%s)...\n", $x + 1, $workshop_args[$x]{'tag'}; - if (defined $workshop_refresh_timestamps_token && defined $workshop_refresh_timestamps_api_url) { + if (defined $quay_refresh_expiration_token && defined $quay_refresh_expiration_api_url) { if (remote_image_found($workshop_args[$x]{'tag'})) { my $query_cmd = 'curl --silent' . - ' -X GET -H "Authorization: Bearer ' . $workshop_refresh_timestamps_token . '"' . - ' "' . $workshop_refresh_timestamps_api_url . + ' -X GET -H "Authorization: Bearer ' . $quay_refresh_expiration_token . '"' . + ' "' . $quay_refresh_expiration_api_url . '/tag/?limit=1&specificTag=' . $workshop_args[$x]{'tag'} . '"'; ($query_cmd, my $query_status, my $query_rc) = run_cmd($query_cmd); chomp($query_status); - my $current_timestamp; + my $current_expiration; if ($query_rc == 0) { my $coder = JSON::XS->new; my $query_ref = $coder->decode($query_status); if (defined $$query_ref{'tags'}[0]) { - $current_timestamp = $$query_ref{'tags'}[0]{'end_ts'}; + $current_expiration = $$query_ref{'tags'}[0]{'end_ts'}; } else { print "\tTag information returned from query is incomplete\n"; print Dumper $query_ref; @@ -1095,26 +1095,26 @@ sub source_container_image { exit 1; } - if ($current_timestamp >= $refresh_timestamp) { - printf "\tThe current expiration timestamp (%d) is greater than or equal to the refresh timestamp so not refreshing\n", $current_timestamp; + if ($current_expiration >= $refresh_expiration) { + printf "\tThe current expiration (%d) is greater than or equal to the refresh expiration so not refreshing\n", $current_expiration; } else { my $refresh_cmd = 'curl --silent' . - ' -X PUT -H "Authorization: Bearer ' . $workshop_refresh_timestamps_token . '"' . - ' -H "Content-type: application/json" -d \'{ "expiration": ' . $refresh_timestamp . ' }\'' . - ' ' . $workshop_refresh_timestamps_api_url . '/tag/' . $workshop_args[$x]{'tag'}; + ' -X PUT -H "Authorization: Bearer ' . $quay_refresh_expiration_token . '"' . + ' -H "Content-type: application/json" -d \'{ "expiration": ' . $refresh_expiration . ' }\'' . + ' ' . $quay_refresh_expiration_api_url . '/tag/' . $workshop_args[$x]{'tag'}; ($refresh_cmd, my $refresh_status, my $refresh_rc) = run_cmd($refresh_cmd); chomp($refresh_status); if (($refresh_rc == 0) && ($refresh_status eq "\"Updated\"")) { - print "\tRefreshed expiration timestamp\n"; + print "\tRefreshed expiration\n"; } else { - print "\tFailed to refresh expiration timestamp\n"; + print "\tFailed to refresh expiration\n"; exit 1; } } } else { - print "\tskipping refresh timestamp because remote image does not exist (!!)\n"; + print "\tskipping expiration refresh because remote image does not exist (!!)\n"; } } print "\tReady\n"; @@ -1829,32 +1829,32 @@ sub load_settings_info() { exit 1; } - ($rc, $workshop_refresh_timestamps_token_file) = get_json_setting("workshop.refresh-timestamps.token-file", $jsonsettings); + ($rc, $quay_refresh_expiration_token_file) = get_json_setting("quay.refresh-expiration.token-file", $jsonsettings); if ($rc != 0) { - print "load_settings_info(): failed to load workshop refresh-timestamps token-file\n"; + print "load_settings_info(): failed to load workshop refresh-expiration token-file\n"; exit 1; } else { - if (defined $workshop_refresh_timestamps_token_file) { - if (open(TOKEN, "<", $workshop_refresh_timestamps_token_file)) { - $workshop_refresh_timestamps_token = ; - chomp($workshop_refresh_timestamps_token); + if (defined $quay_refresh_expiration_token_file) { + if (open(TOKEN, "<", $quay_refresh_expiration_token_file)) { + $quay_refresh_expiration_token = ; + chomp($quay_refresh_expiration_token); close TOKEN; } else { - printf "load_settings_file(): failed to load token from workshop refresh-timestamps token-file\n"; + printf "load_settings_file(): failed to load token from workshop refresh-expiration token-file\n"; exit 1; } - printf "load_settings_info(): loaded workshop refresh-timestamps token-file: %s\n", $workshop_refresh_timestamps_token_file; + printf "load_settings_info(): loaded workshop refresh-expiration token-file: %s\n", $quay_refresh_expiration_token_file; } } - ($rc, $workshop_refresh_timestamps_api_url) = get_json_setting("workshop.refresh-timestamps.api-url", $jsonsettings); + ($rc, $quay_refresh_expiration_api_url) = get_json_setting("quay.refresh-expiration.api-url", $jsonsettings); if ($rc != 0) { - print "load_settings_info(): failed to load workshop refresh-timestamps api-url\n"; + print "load_settings_info(): failed to load workshop refresh-expiration api-url\n"; exit 1; } else { - if (defined $workshop_refresh_timestamps_api_url) { - printf "load_settings_info(): loaded workshop refresh-timestamps api-url: %s\n", $workshop_refresh_timestamps_api_url; + if (defined $quay_refresh_expiration_api_url) { + printf "load_settings_info(): loaded workshop refresh-expiration api-url: %s\n", $quay_refresh_expiration_api_url; } } diff --git a/rickshaw-settings.json b/rickshaw-settings.json index cff2fc8b..84b77157 100644 --- a/rickshaw-settings.json +++ b/rickshaw-settings.json @@ -20,13 +20,13 @@ } }, "workshop": { - "force-builds": "false", - "refresh-timestamps": { + "force-builds": "false" + }, + "quay": { + "image-expiration": "2w", + "refresh-expiration": { "token-file": null, "api-url": null } - }, - "quay": { - "image-expiration": "2w" } }