fix(image): read the pushed digest from the kaniko log, not from /kaniko
The first run on main built and pushed the image, then failed on `read -r digest < /kaniko/digest`: the executor replaces the job container's filesystem with the built image and removes /kaniko, so the digest file and the credential-method file are gone by then. Take the digest from the "Pushed <image>@sha256:<digest>" log line into a shell variable, validate its shape, and drop the credential-method echo (the prepare step already logs the credential in use). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
1 parent
dcfcbd105e
commit
8719271d05
1 file changed
+19
-9
@@ -236,29 +236,39 @@ jobs:
|
||||
|
||||
# Context: this commit of this repository, cloned by kaniko (#<ref>#<sha>:
|
||||
# clone <ref>, check out <sha>). The Dockerfile has no COPY, so only it is read.
|
||||
/kaniko/executor \
|
||||
#
|
||||
# When it finishes the executor has replaced the job container's filesystem with
|
||||
# the built image and removed /kaniko, so nothing written there (a --digest-file,
|
||||
# the credential method) can be read back. Take the digest from its
|
||||
# "Pushed <image>@sha256:<digest>" log line into a variable of this shell, which
|
||||
# needs only builtins by then.
|
||||
digest=""
|
||||
while IFS= read -r line; do
|
||||
printf '%s\n' "$line"
|
||||
case "$line" in
|
||||
*"Pushed "*"@sha256:"*) digest="sha256:${line##*@sha256:}" ;;
|
||||
esac
|
||||
done < <(/kaniko/executor \
|
||||
--context "git://${registry}/${REPO}.git#${REF}#${SHA}" \
|
||||
--context-sub-path images/molecule-ubuntu2404 \
|
||||
--dockerfile Dockerfile \
|
||||
"${dests[@]}" \
|
||||
--digest-file /kaniko/digest \
|
||||
--snapshot-mode=redo \
|
||||
--cache=false \
|
||||
--push-retry 3 \
|
||||
--image-fs-extract-retry 3 \
|
||||
--force
|
||||
--force 2>&1)
|
||||
wait "$!"
|
||||
|
||||
# The filesystem now holds the built image; read and echo are builtins.
|
||||
read -r digest < /kaniko/digest
|
||||
read -r method < /kaniko/credential-method
|
||||
echo "Pushed with credential: $method"
|
||||
if ! [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]; then
|
||||
echo "::error::kaniko finished but no pushed image digest was found in its output."
|
||||
exit 1
|
||||
fi
|
||||
echo "Pinned reference: ${image}@${digest}"
|
||||
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
|
||||
{
|
||||
echo "### molecule-ubuntu2404 pushed"
|
||||
echo
|
||||
echo "Credential: ${method}"
|
||||
echo
|
||||
echo "Pin it by digest: \`${image}@${digest}\`"
|
||||
} >> "$GITHUB_STEP_SUMMARY" || true
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user