Skip to content

Commit

Permalink
refactor: use built-in buildah --retry
Browse files Browse the repository at this point in the history
- Retries were achieved by writing a loop around the buildah command
- buildah actually has a `--retry` option
- Use the built-in option in order to simplify the code
  • Loading branch information
tnevrlka committed Nov 28, 2024
1 parent 0a78a6d commit 2f70235
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 68 deletions.
24 changes: 7 additions & 17 deletions task/buildah-oci-ta/0.2/buildah-oci-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -632,19 +632,6 @@ spec:
#!/bin/bash
set -e
retry() {
status=-1
max_run=5
sleep_sec=10
for run in $(seq 1 $max_run); do
status=0
[ "$run" -gt 1 ] && sleep $sleep_sec
"$@" && break || status=$?
done
return $status
}
ca_bundle=/mnt/trusted-ca/ca-bundle.crt
if [ -f "$ca_bundle" ]; then
echo "INFO: Using mounted CA bundle: $ca_bundle"
Expand All @@ -665,21 +652,24 @@ spec:
buildah commit "${BUILDAH_ARGS[@]}" $container $IMAGE
retries=5
echo "Pushing to ${IMAGE%:*}:${TASKRUN_NAME}"
if ! retry buildah push \
if ! buildah push \
--retry "$retries" \
--tls-verify="$TLSVERIFY" \
"$IMAGE" \
"docker://${IMAGE%:*}:$(context.taskRun.name)"; then
echo "Failed to push sbom image to ${IMAGE%:*}:$(context.taskRun.name) after ${max_run} tries"
echo "Failed to push sbom image to ${IMAGE%:*}:$(context.taskRun.name) after ${retries} tries"
exit 1
fi
echo "Pushing to ${IMAGE}"
if ! retry buildah push \
if ! buildah push \
--retry "$retries" \
--tls-verify="$TLSVERIFY" \
--digestfile "/var/workdir/image-digest" "$IMAGE" \
"docker://$IMAGE"; then
echo "Failed to push sbom image to $IMAGE after ${max_run} tries"
echo "Failed to push sbom image to $IMAGE after ${retries} tries"
exit 1
fi
Expand Down
24 changes: 7 additions & 17 deletions task/buildah-remote-oci-ta/0.2/buildah-remote-oci-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -750,19 +750,6 @@ spec:
export IMAGE
fi
retry() {
status=-1
max_run=5
sleep_sec=10
for run in $(seq 1 $max_run); do
status=0
[ "$run" -gt 1 ] && sleep $sleep_sec
"$@" && break || status=$?
done
return $status
}
ca_bundle=/mnt/trusted-ca/ca-bundle.crt
if [ -f "$ca_bundle" ]; then
echo "INFO: Using mounted CA bundle: $ca_bundle"
Expand All @@ -783,21 +770,24 @@ spec:
buildah commit "${BUILDAH_ARGS[@]}" $container $IMAGE
retries=5
echo "Pushing to ${IMAGE%:*}:${TASKRUN_NAME}"
if ! retry buildah push \
if ! buildah push \
--retry "$retries" \
--tls-verify="$TLSVERIFY" \
"$IMAGE" \
"docker://${IMAGE%:*}:$(context.taskRun.name)"; then
echo "Failed to push sbom image to ${IMAGE%:*}:$(context.taskRun.name) after ${max_run} tries"
echo "Failed to push sbom image to ${IMAGE%:*}:$(context.taskRun.name) after ${retries} tries"
exit 1
fi
echo "Pushing to ${IMAGE}"
if ! retry buildah push \
if ! buildah push \
--retry "$retries" \
--tls-verify="$TLSVERIFY" \
--digestfile "/var/workdir/image-digest" "$IMAGE" \
"docker://$IMAGE"; then
echo "Failed to push sbom image to $IMAGE after ${max_run} tries"
echo "Failed to push sbom image to $IMAGE after ${retries} tries"
exit 1
fi
Expand Down
24 changes: 7 additions & 17 deletions task/buildah-remote/0.2/buildah-remote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -728,19 +728,6 @@ spec:
export IMAGE
fi
retry () {
status=-1
max_run=5
sleep_sec=10
for run in $(seq 1 $max_run); do
status=0
[ "$run" -gt 1 ] && sleep $sleep_sec
"$@" && break || status=$?
done
return $status
}
ca_bundle=/mnt/trusted-ca/ca-bundle.crt
if [ -f "$ca_bundle" ]; then
echo "INFO: Using mounted CA bundle: $ca_bundle"
Expand All @@ -761,23 +748,26 @@ spec:
buildah commit "${BUILDAH_ARGS[@]}" $container $IMAGE
retries=5
echo "Pushing to ${IMAGE%:*}:${TASKRUN_NAME}"
if ! retry buildah push \
if ! buildah push \
--retry "$retries" \
--tls-verify="$TLSVERIFY" \
"$IMAGE" \
"docker://${IMAGE%:*}:$(context.taskRun.name)";
then
echo "Failed to push sbom image to ${IMAGE%:*}:$(context.taskRun.name) after ${max_run} tries"
echo "Failed to push sbom image to ${IMAGE%:*}:$(context.taskRun.name) after ${retries} tries"
exit 1
fi
echo "Pushing to ${IMAGE}"
if ! retry buildah push \
if ! buildah push \
--retry "$retries" \
--tls-verify="$TLSVERIFY" \
--digestfile "$(workspaces.source.path)/image-digest" "$IMAGE" \
"docker://$IMAGE";
then
echo "Failed to push sbom image to $IMAGE after ${max_run} tries"
echo "Failed to push sbom image to $IMAGE after ${retries} tries"
exit 1
fi
Expand Down
24 changes: 7 additions & 17 deletions task/buildah/0.2/buildah.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -577,19 +577,6 @@ spec:
#!/bin/bash
set -e
retry () {
status=-1
max_run=5
sleep_sec=10
for run in $(seq 1 $max_run); do
status=0
[ "$run" -gt 1 ] && sleep $sleep_sec
"$@" && break || status=$?
done
return $status
}
ca_bundle=/mnt/trusted-ca/ca-bundle.crt
if [ -f "$ca_bundle" ]; then
echo "INFO: Using mounted CA bundle: $ca_bundle"
Expand All @@ -610,23 +597,26 @@ spec:
buildah commit "${BUILDAH_ARGS[@]}" $container $IMAGE
retries=5
echo "Pushing to ${IMAGE%:*}:${TASKRUN_NAME}"
if ! retry buildah push \
if ! buildah push \
--retry "$retries" \
--tls-verify="$TLSVERIFY" \
"$IMAGE" \
"docker://${IMAGE%:*}:$(context.taskRun.name)";
then
echo "Failed to push sbom image to ${IMAGE%:*}:$(context.taskRun.name) after ${max_run} tries"
echo "Failed to push sbom image to ${IMAGE%:*}:$(context.taskRun.name) after ${retries} tries"
exit 1
fi
echo "Pushing to ${IMAGE}"
if ! retry buildah push \
if ! buildah push \
--retry "$retries" \
--tls-verify="$TLSVERIFY" \
--digestfile "$(workspaces.source.path)/image-digest" "$IMAGE" \
"docker://$IMAGE";
then
echo "Failed to push sbom image to $IMAGE after ${max_run} tries"
echo "Failed to push sbom image to $IMAGE after ${retries} tries"
exit 1
fi
Expand Down

0 comments on commit 2f70235

Please sign in to comment.