Skip to content

Commit a06ba1c

Browse files
authored
devops: add utility to count compressed docker image size (#2920)
This adds a new script to calculate docker image size with all parent layers. Note: take this metrics with a grain of salt, since in reality docker compresses and reuses layers. Some historic stats obtained with this script: - **`208MB`** (-33MB) chore(docker): skip "recommended" dependencies (#2917) (1cebf87) - **`241MB`** (-29MB) chore(docker): trim some of the gstreamer dependencies (#2897) (bce4b1a) - **`272MB`** (-1MB) devops: do cache busting for APT (#2656) (bb34418) - **`273MB`** (+49MB) fix(webkit): update Docker file to include gstreamer (#2636) (5c6c659) - **`224MB`** (+0MB) chore: fix emojis for CR and FF in Dockerfile (#2522) (24316ad) - **`224MB`** (-1MB) fix: Dockerfile for Firefox (#1937) (b516ac4) - **`225MB`** (+49MB) devops(docker): Install ffmpeg dependency, adding codecs necessary for video playback in Firefox (#1627) (222d01c) - **`176MB`** (+32MB) chore(docs): optionally install XVFB in docker(ec3ee66) - **`144MB`** (+144MB) feat: add a playwright-ready docker image (#1161)(1781ae7)
1 parent d58a57c commit a06ba1c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

docs/docker/CURRENT_DOCKER_IMAGE_SIZE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(generated with docker-image-size.sh)
2+
224M

docs/docker/docker-image-size.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -e
3+
set +x
4+
5+
# This script computes **compressed image size with all its layers**.
6+
# This solution is based on https://stackoverflow.com/a/55156181/314883
7+
8+
DOCKER_IMAGE_NAME="docker-image-to-count-compressed-size"
9+
FILE_NAME="docker-image-to-count-compressed-size"
10+
11+
function cleanup() {
12+
echo "-- Removing .tar if any"
13+
rm -f "${FILE_NAME}.tar"
14+
echo "-- Removing .tar.gz if any"
15+
rm -f "${FILE_NAME}.tar.gz"
16+
echo "-- Removing docker image if any"
17+
docker rmi "${DOCKER_IMAGE_NAME}:bionic" >/dev/null
18+
}
19+
20+
trap "cleanup; cd $(pwd -P)" EXIT
21+
cd "$(dirname "$0")"
22+
23+
echo "-- Building image..."
24+
docker build -t "${DOCKER_IMAGE_NAME}:bionic" -f Dockerfile.bionic . >/dev/null
25+
echo "-- Saving .tar of the image..."
26+
docker save "${DOCKER_IMAGE_NAME}:bionic" > "${FILE_NAME}.tar"
27+
echo "-- Compressing image..."
28+
gzip "${FILE_NAME}.tar" >/dev/null
29+
30+
echo "(generated with docker-image-size.sh)" > CURRENT_DOCKER_IMAGE_SIZE
31+
du -sh ${FILE_NAME}.tar.gz | cut -f1 | xargs >> CURRENT_DOCKER_IMAGE_SIZE
32+

0 commit comments

Comments
 (0)