add image size to job summary

This commit is contained in:
2026-10-21 12:36:17 +02:00
parent e15f7896cb
commit b1403046e5
2 changed files with 37 additions and 1 deletions
+31 -1
View File
@@ -14,6 +14,8 @@ name: image
# Images go to <registry>/<project>/<image>, and to docker.io/<dockerhub-username>/<image>
# when the Docker Hub secrets are passed.
#
# After a push, the compressed size per platform is printed to the log and the job summary.
#
# One image per call: Gitea 1.27.0 can't expand a matrix built from inputs in a called
# workflow (the run is silently not created).
#
@@ -156,7 +158,8 @@ jobs:
username: ${{ secrets.dockerhub-username }}
password: ${{ secrets.dockerhub-token }}
- uses: docker/build-push-action@v7
- id: build
uses: docker/build-push-action@v7
with:
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile || format('{0}/Dockerfile', inputs.context) }}
@@ -167,3 +170,30 @@ jobs:
build-args: ${{ inputs.build-args }}
cache-from: ${{ inputs.cache == 'true' && format('type=registry,ref={0}:buildcache', env.IMAGE) || '' }}
cache-to: ${{ inputs.cache == 'true' && inputs.push == 'true' && format('type=registry,ref={0}:buildcache,mode=max,image-manifest=true,oci-mediatypes=true', env.IMAGE) || '' }}
# Compressed size per platform (sum of the layer sizes, what a pull downloads), read
# back from the registry. Only after a push: a multi-platform build isn't kept locally.
- if: inputs.push == 'true'
env:
DIGEST: ${{ steps.build.outputs.digest }}
PLATFORMS: ${{ inputs.platforms }}
run: |
raw="$(docker buildx imagetools inspect --raw "${IMAGE}@${DIGEST}")"
# a single-platform push without attestations is a plain manifest, not an index
if echo "${raw}" | jq -e '.manifests' >/dev/null; then
list="$(echo "${raw}" | jq -r '.manifests[]
| select(.annotations["vnd.docker.reference.type"] != "attestation-manifest")
| "\(.platform.os)/\(.platform.architecture)\(if .platform.variant then "/" + .platform.variant else "" end) \(.digest)"')"
else
list="${PLATFORMS} ${DIGEST}"
fi
{
echo "### ${IMAGE}"
echo ""
echo "| Platform | Compressed size |"
echo "|---|---|"
echo "${list}" | while read -r platform digest; do
bytes="$(docker buildx imagetools inspect --raw "${IMAGE}@${digest}" | jq '[.layers[].size] | add')"
echo "| ${platform} | $(numfmt --to=iec --suffix=B "${bytes}") |"
done
} | tee -a "${GITHUB_STEP_SUMMARY:-/dev/null}"