fix(image): read the pushed digest from the kaniko log #2
@@ -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:}"; digest="${digest:0:71}" ;;
|
||||
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