From c4b3438e920872aaa441a235e8e6a11bb0a3eaeb Mon Sep 17 00:00:00 2001 From: Tom Martensen Date: Thu, 18 Dec 2025 13:31:53 +0100 Subject: [PATCH] spike: wait for image for specific commit --- tasks/wait-for-image-task.yaml | 39 ++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/tasks/wait-for-image-task.yaml b/tasks/wait-for-image-task.yaml index 582a0b1..db29d73 100644 --- a/tasks/wait-for-image-task.yaml +++ b/tasks/wait-for-image-task.yaml @@ -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)")" + + # 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)." + # 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