Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use built-in buildah --retry #1663

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 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 @@ -559,41 +559,33 @@ 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"
cp -vf $ca_bundle /etc/pki/ca-trust/source/anchors
update-ca-trust
fi
retries=5
# Push to a unique tag based on the TaskRun name to avoid race conditions
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
# Push to a tag based on the git revision
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
26 changes: 9 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 @@ -659,41 +659,33 @@ 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"
cp -vf $ca_bundle /etc/pki/ca-trust/source/anchors
update-ca-trust
fi
retries=5
# Push to a unique tag based on the TaskRun name to avoid race conditions
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
# Push to a tag based on the git revision
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
26 changes: 9 additions & 17 deletions task/buildah-remote/0.2/buildah-remote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -637,43 +637,35 @@ 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"
cp -vf $ca_bundle /etc/pki/ca-trust/source/anchors
update-ca-trust
fi

retries=5
# Push to a unique tag based on the TaskRun name to avoid race conditions
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

# Push to a tag based on the git revision
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
26 changes: 9 additions & 17 deletions task/buildah/0.2/buildah.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -500,43 +500,35 @@ 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"
cp -vf $ca_bundle /etc/pki/ca-trust/source/anchors
update-ca-trust
fi
retries=5
# Push to a unique tag based on the TaskRun name to avoid race conditions
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
# Push to a tag based on the git revision
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
Loading