diff --git a/.gitea/workflows/image.yaml b/.gitea/workflows/image.yaml index fbd6cc9..f2218b6 100644 --- a/.gitea/workflows/image.yaml +++ b/.gitea/workflows/image.yaml @@ -14,6 +14,8 @@ name: image # Images go to //, and to docker.io// # 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}" diff --git a/README.md b/README.md index 9861d17..7789970 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,12 @@ input of a called workflow arrives as `false`. An expression like `tag` (the timestamp tag), `version`, `tags` (the full image references). +### Image size + +After a push, the compressed size of each platform (the sum of its layer sizes, what a pull +downloads) is read back from the registry and printed to the log and the job summary. Builds +with `push: "false"` skip it: a multi-platform build isn't kept locally. + ### Tags | Tag | When |