fix(image): read the pushed digest from the kaniko log #2

Merged
Defame1297 merged 2 commits from fix/image-digest-after-build into main 2026-10-25 10:40:43 +00:00
+19 -9
View File
@@ -236,29 +236,39 @@ jobs:
# Context: this commit of this repository, cloned by kaniko (#<ref>#<sha>: # 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. # 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:}"; digest="${digest:0:71}" ;;
esac
done < <(/kaniko/executor \
--context "git://${registry}/${REPO}.git#${REF}#${SHA}" \ --context "git://${registry}/${REPO}.git#${REF}#${SHA}" \
--context-sub-path images/molecule-ubuntu2404 \ --context-sub-path images/molecule-ubuntu2404 \
--dockerfile Dockerfile \ --dockerfile Dockerfile \
"${dests[@]}" \ "${dests[@]}" \
--digest-file /kaniko/digest \
--snapshot-mode=redo \ --snapshot-mode=redo \
--cache=false \ --cache=false \
--push-retry 3 \ --push-retry 3 \
--image-fs-extract-retry 3 \ --image-fs-extract-retry 3 \
--force --force 2>&1)
wait "$!"
# The filesystem now holds the built image; read and echo are builtins. if ! [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]; then
read -r digest < /kaniko/digest echo "::error::kaniko finished but no pushed image digest was found in its output."
read -r method < /kaniko/credential-method exit 1
echo "Pushed with credential: $method" fi
echo "Pinned reference: ${image}@${digest}" echo "Pinned reference: ${image}@${digest}"
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
{ {
echo "### molecule-ubuntu2404 pushed" echo "### molecule-ubuntu2404 pushed"
echo echo
echo "Credential: ${method}"
echo
echo "Pin it by digest: \`${image}@${digest}\`" echo "Pin it by digest: \`${image}@${digest}\`"
} >> "$GITHUB_STEP_SUMMARY" || true } >> "$GITHUB_STEP_SUMMARY" || true
fi fi