Skip to content

Commit

Permalink
Adding size report AFTER push
Browse files Browse the repository at this point in the history
  • Loading branch information
menny committed Nov 30, 2024
1 parent 81a3252 commit 8abb5ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/docker_build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fi
IMAGE_SIZE_RAW=$(docker inspect -f "{{ .Size }}" menny/${IMAGE_NAME}:${IMAGE_VERSION})
IMAGE_SIZE=$(echo $IMAGE_SIZE_RAW | numfmt --to=si)
PREVIOUS_SIZE="$(docker manifest inspect menny/${IMAGE_NAME}:latest | jq -r '.config.size + ([.layers[].size] | add)')"
SIZE_MESSAGE="Image size for \`menny/${IMAGE_NAME}:${IMAGE_VERSION}\` is ${IMAGE_SIZE} (or $IMAGE_SIZE_RAW bytes).${SQUASH_MSG} Previous size was ${PREVIOUS_SIZE}."
SIZE_MESSAGE="Image size for \`menny/${IMAGE_NAME}:${IMAGE_VERSION}\` is ${IMAGE_SIZE} (or $IMAGE_SIZE_RAW bytes).${SQUASH_MSG} Previous (compressed) size was ${PREVIOUS_SIZE}."

echo "${SIZE_MESSAGE}"

Expand Down
19 changes: 19 additions & 0 deletions .github/docker_push_image.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
set -e

PREVIOUS_SIZE="$(docker manifest inspect menny/${IMAGE_NAME}:latest | jq -r '.config.size + ([.layers[].size] | add)')"

docker image tag menny/${IMAGE_NAME}:${IMAGE_VERSION} menny/${IMAGE_NAME}:latest
docker image tag menny/${IMAGE_NAME}:${IMAGE_VERSION} ghcr.io/menny/${IMAGE_NAME}:${IMAGE_VERSION}
docker image tag menny/${IMAGE_NAME}:${IMAGE_VERSION} ghcr.io/menny/${IMAGE_NAME}:latest
Expand All @@ -9,3 +11,20 @@ docker push menny/${IMAGE_NAME}:${IMAGE_VERSION}
docker push menny/${IMAGE_NAME}:latest
docker push ghcr.io/menny/${IMAGE_NAME}:${IMAGE_VERSION}
docker push ghcr.io/menny/${IMAGE_NAME}:latest

# removing to ensure we're pull the right size
docker rmi menny/${IMAGE_NAME}:latest
CURRENT_SIZE="$(docker manifest inspect menny/${IMAGE_NAME}:latest | jq -r '.config.size + ([.layers[].size] | add)')"

SIZES_MSG="Pushed image 'menny/${IMAGE_NAME}:${IMAGE_VERSION}'. Previous size was ${PREVIOUS_SIZE} and current is ${CURRENT_SIZE}."

echo "$SIZES_MSG"

if [[ -n "$GITHUB_COMMENT_URL" ]]; then
JSON_DATA=$(jq --null-input --arg body "${SIZE_MESSAGE}" '{ "body": $body }')
curl -s -X POST \
$GITHUB_COMMENT_URL \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
--data "${JSON_DATA}" > /dev/null
fi

0 comments on commit 8abb5ba

Please sign in to comment.