Skip to content

Commit

Permalink
Merge pull request #10 from infosiftr/deploy-retries
Browse files Browse the repository at this point in the history
Retry each crane command on 429 after a sleep
  • Loading branch information
tianon authored Dec 15, 2023
2 parents 6b0ba20 + 8a4c026 commit 88f2840
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
36 changes: 20 additions & 16 deletions Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,8 @@ node('multiarch-' + env.BASHBREW_ARCH) { ansiColor('xterm') {
set -Eeuo pipefail -x

jq -L.scripts -r '
include "meta";
reduce (.[] | select(.build.resolved and .build.arch == env.BASHBREW_ARCH)) as $i ({};
.[ $i.source.arches[].archTags[] ] += [
$i.build.resolved
| .index.ref // .manifest.ref
]
)
| to_entries[]
| .key as $target
| .value
| if length == 1 then
@sh "crane copy \\(.) \\($target)"
else
@sh "crane index append --tag \\($target) " + (map("--manifest " + @sh) | join(" ")) + " --flatten"
end
include "jenkins";
crane_deploy_commands | @sh
' builds.json
''').trim()

Expand All @@ -89,7 +76,24 @@ node('multiarch-' + env.BASHBREW_ARCH) { ansiColor('xterm') {
sh """#!/usr/bin/env bash
set -Eeuo pipefail

${ shell }
commands=( ${ shell } )
for c in "${commands[@]}"; do
tries=3
while ! output="$( { $c; } |& tee /dev/stderr )"; then
# check to see if we hit the docker hub rate limit
if grep -q 'TOOMANYREQUESTS' <<<"$output"; then
if [ "$(( --tries ))" -le 0 ]; then
echo >&2 'failed to copy image 3 times'
exit 1
fi
echo 'sleeping before retrying...'
sleep 60
else
# non 429 error
exit 1
fi
fi
done
"""
}
}
Expand Down
18 changes: 18 additions & 0 deletions jenkins.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# input: list of build objects i.e., builds.json
# output: stream of crane copy command strings
def crane_deploy_commands:
reduce (.[] | select(.build.resolved and .build.arch == env.BASHBREW_ARCH)) as $i ({};
.[ $i.source.arches[].archTags[] ] += [
$i.build.resolved
| .index.ref // .manifest.ref
]
)
| to_entries[]
| .key as $target
| .value
| if length == 1 then
@sh "crane copy \(.) \($target)"
else
@sh "crane index append --tag \($target) " + (map("--manifest " + @sh) | join(" ")) + " --flatten"
end
;

0 comments on commit 88f2840

Please sign in to comment.