-
Notifications
You must be signed in to change notification settings - Fork 2
spike: wait for image for specific commit #87
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,10 @@ spec: | |||||
| - name: IMAGE | ||||||
| description: Image reference. | ||||||
| type: string | ||||||
| - name: DESIRED_GIT_REF | ||||||
| valueFrom: | ||||||
| fieldRef: | ||||||
| fieldPath: metadata.labels['pipelinesascode.tekton.dev/sha'] | ||||||
| results: | ||||||
| - name: IMAGE_DIGEST | ||||||
| description: Image digest in the format `sha256:abcdef0123`. | ||||||
|
|
@@ -27,27 +31,30 @@ spec: | |||||
|
|
||||||
| echo "Waiting for image $(params.IMAGE) to become available..." | ||||||
| while true; do | ||||||
| if skopeo inspect --raw "docker://$(params.IMAGE)"; then | ||||||
| raw_info="$(skopeo inspect \ | ||||||
| --retry-times 10 \ | ||||||
| --format '{{.Digest}} {{ index .Labels "vcs-ref" }} {{ index .Labels "source-location" }}' \ | ||||||
| --no-tags \ | ||||||
| "docker://$(params.IMAGE)")" | ||||||
|
Comment on lines
+34
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If $ foo="$(/bin/false)"
$ echo $?
1
$ foo="$(/bin/true)"
$ echo $?
0It's possible to assign in #!/usr/bin/env bash
set -euo pipefail
if blah="pre-$(/bin/false)-post"; then
echo "success"
else
echo "failure"
fi
echo "blah:|$blah|"$ ./a.sh
failure
blah:|pre--post|Not the most elegant but can't offer anything better. |
||||||
|
|
||||||
| # Turning raw_info into an array for easier handling. | ||||||
| infos=( $raw_info ) | ||||||
| if [[ "${#infos[@]}" -ne 3 ]]; then | ||||||
| >&2 echo "ERROR: Not all required information was found. Verify that the 'vcs-ref' and 'source-location' labels are set on the image $(params.IMAGE)." | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| if [[ "${infos[1]}" == "$(params.DESIRED_GIT_REF)" ]]; then | ||||||
| break | ||||||
| else | ||||||
| >&2 echo "ERROR: The Git reference of the image $(params.IMAGE) does not match the desired Git reference $(params.DESIRED_GIT_REF)." | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Subjective] Well, if it's an expected situation, calling it an error could be a bit of a stretch. Error is more for a situation we foresee but don't know how to handle. In this case, we do know how to handle: try wait more.
Suggested change
|
||||||
| # Continue waiting | ||||||
| sleep 1m | ||||||
| fi | ||||||
| sleep 1m | ||||||
| done | ||||||
|
|
||||||
| echo "Image $(params.IMAGE) found." | ||||||
|
|
||||||
| raw_info="$(skopeo inspect \ | ||||||
| --retry-times 10 \ | ||||||
| --format '{{.Digest}} {{ index .Labels "vcs-ref" }} {{ index .Labels "source-location" }}' \ | ||||||
| --no-tags \ | ||||||
| "docker://$(params.IMAGE)")" | ||||||
|
|
||||||
| # Turning raw_info into an array for easier handling. | ||||||
| infos=( $raw_info ) | ||||||
| if [[ "${#infos[@]}" -ne 3 ]]; then | ||||||
| >&2 echo "ERROR: Not all required information was found. Verify that the 'vcs-ref' and 'source-location' labels are set on the image $(params.IMAGE)." | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
|
|
||||||
| # Output | ||||||
| echo -n "${infos[0]}" | tee "$(results.IMAGE_DIGEST.path)" | ||||||
| echo | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description:here to say what the default thing does and how to turn it off.