Skip to content

Commit

Permalink
Showing squash stats
Browse files Browse the repository at this point in the history
  • Loading branch information
menny committed Nov 23, 2024
1 parent 5e5a726 commit ea64033
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/docker_build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -e

docker build ${DOCKER_FILE_PATH} --build-arg IMAGE_VERSION="${IMAGE_VERSION}" --build-arg NDK_VERSION="${NDK_VERSION}" --build-arg BAZELISK_VERSION="${BAZELISK_VERSION}" --compress -t "menny/${IMAGE_NAME}:${IMAGE_VERSION}-raw"

SQUASH_MSG=""
if [[ "SQUASH" == "${SQUASH_IMAGE}" ]]; then
# Squashing
pip install docker-squash
Expand All @@ -16,21 +17,24 @@ if [[ "SQUASH" == "${SQUASH_IMAGE}" ]]; then
echo "******"

COMMITS_COUNT="$(docker history menny/${IMAGE_NAME}:${IMAGE_VERSION}-raw | grep 'buildkit.dockerfile' | wc -l)"
IMAGE_SIZE_RAW=$(docker inspect -f "{{ .Size }}" "menny/${IMAGE_NAME}:${IMAGE_VERSION}-raw")
echo "** docker-squash $COMMITS_COUNT layers"
docker-squash -f "$COMMITS_COUNT" -t "menny/${IMAGE_NAME}:${IMAGE_VERSION}" menny/${IMAGE_NAME}:${IMAGE_VERSION}-raw
echo "******"

echo "** Docker images on machine after squash:"
docker images
echo "******"
SQUASH_MSG=" Layers ${COMMITS_COUNT}. Size before squashing: ${IMAGE_SIZE_RAW}"
else
echo "Skipping squashing"
SQUASH_MSG=" No squash."
docker tag "menny/${IMAGE_NAME}:${IMAGE_VERSION}-raw" "menny/${IMAGE_NAME}:${IMAGE_VERSION}"
fi

IMAGE_SIZE_RAW=$(docker inspect -f "{{ .Size }}" menny/${IMAGE_NAME}:${IMAGE_VERSION})
IMAGE_SIZE=$(echo $IMAGE_SIZE_RAW | numfmt --to=si)
SIZE_MESSAGE="Image size for \`menny/${IMAGE_NAME}:${IMAGE_VERSION}\` is ${IMAGE_SIZE} (or $IMAGE_SIZE_RAW bytes)."
SIZE_MESSAGE="Image size for \`menny/${IMAGE_NAME}:${IMAGE_VERSION}\` is ${IMAGE_SIZE} (or $IMAGE_SIZE_RAW bytes).${SQUASH_MSG}"
echo "${SIZE_MESSAGE}"

if [[ -n "$GITHUB_COMMENT_URL" ]]; then
Expand Down

0 comments on commit ea64033

Please sign in to comment.