@@ -34,3 +34,57 @@ Tag and publish a container image:
3434# <repo> is your AWS ECR repository name
3535scripts/publish_container.sh <service> <version> <registry> <repo>
3636```
37+
38+ ## Notes on Image Sizes
39+
40+ There are a few strategies we use to keep image sizes small:
41+
42+ 1 . Use an alternative base image, i.e. ` node:18-slim ` instead of ` node:18 `
43+ 2 . Avoid installing Node.js ` devDependencies ` in container builds
44+ 3 . Purge the Yarn cache from container builds
45+
46+ #### Comparison of Base Images
47+
48+ Sizes of Docker images built by ` scripts/build_container.sh ` :
49+
50+ | Service | Image | Size | ECR Size | 50 GB Limit |
51+ | ---------| ----------------| ---------| ----------| -------------|
52+ | Node.js | node:18 | 942 MB | N/A | N/A |
53+ | Node.js | node:18-slim | 234 MB | N/A | N/A |
54+ | Node.js | node:18-alpine | 165 MB | N/A | N/A |
55+ | Node.js | node:16 | 858 MB | N/A | N/A |
56+ | Node.js | node:16-slim | 174 MB | N/A | N/A |
57+ | Node.js | node:16-alpine | 114 MB | N/A | N/A |
58+ | API | node:18 | 1170 MB | 425 MB | 117 / 23 ea |
59+ | API | node:18-slim | 767 MB | 254 MB | 196 / 39 ea |
60+ | API | node:18-alpine | 626 MB | 187 MB | 267 / 53 ea |
61+ | API | node:16 | 1040 MB | 396 MB | 126 / 25 ea |
62+ | API | node:16-slim | 615 MB | 214 MB | 233 / 46 ea |
63+ | API | node:16-alpine | 530 MB | 169 MB | 295 / 59 ea |
64+
65+ Image sizes reported by ` docker image ls ` include all layers, and are much
66+ higher than the image sizes reported by ECR. ECR gives us 50 GB of storage
67+ for free, so the 50 GB Limit column shows how many total images we can store
68+ for each image, and how many we can store for each of the five services we
69+ build.
70+
71+ The ` -alpine ` images pull Node.js builds from unofficial-builds.nodejs.org,
72+ while the default and ` -slim ` images pull official builds from nodejs.org.
73+ While the ` -slim ` images are 25-35% larger than the ` -alpine ` images, they're
74+ still small enough to allow us to store several dozen versions in ECR before we
75+ start to approach the 50 GB ECR limit. Additionally, the ` -slim ` images are
76+ based on Debian, which comes with a more familiar toolchain.
77+
78+ Similarly, Node.js v18 images are 10-20% larger than Node.js v16 images, but we
79+ may be able to get some of this size back by replacing Mocha, Axios, and other
80+ dependencies with their new native counterparts in Node.js v18.
81+
82+ #### Regarding ` bcrypt `
83+
84+ We could further reduce image sizes by removing the ` bcrypt ` dependencies from
85+ the base image layer. These currently include ` python3 ` , ` make ` , ` gcc ` , and
86+ ` g++ ` . The ` bcrypt ` dependency is only used by the API service, during the
87+ login flow in ` server/routes/session.coffee ` . One option here could be to move
88+ authentication flows (such as JWT signing, granting, and validation) to their
89+ own microservice to isolate this dependency, reducing the image size of all
90+ other services.
0 commit comments