Skip to content

Commit d93487b

Browse files
authored
Merge pull request #199 from willroberts/upgrade-node
Upgrades Node.js to v18
2 parents c4aed71 + 50b6320 commit d93487b

File tree

12 files changed

+77
-21
lines changed

12 files changed

+77
-21
lines changed

.github/workflows/build_app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: install node.js
2727
uses: actions/setup-node@v3
2828
with:
29-
node-version: 16
29+
node-version: 18
3030

3131
# Caching node_modules saves 50s on builds which don't modify dependencies.
3232
# Compared to yarn caching, it saves an additional 27 seconds.

.github/workflows/integration_tests.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ on:
1919
jobs:
2020
integration_tests:
2121
runs-on: ubuntu-latest
22-
container: node:16
22+
container: node:18-slim
2323
services:
2424
redis:
2525
image: redis:6
@@ -31,6 +31,9 @@ jobs:
3131
POSTGRES_DB: duelyst
3232

3333
steps:
34+
- name: install bcrypt dependencies and git
35+
run: apt-get update && apt-get -y install python3 make gcc g++ git
36+
3437
- name: check out code
3538
uses: actions/checkout@v3
3639

.github/workflows/lint_coffeescript.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: install node.js
2626
uses: actions/setup-node@v3
2727
with:
28-
node-version: 16
28+
node-version: 18
2929

3030
# Caching node_modules saves 50s on builds which don't modify dependencies.
3131
# Compared to yarn caching, it saves an additional 27 seconds.

.github/workflows/lint_javascript.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: install node.js
3535
uses: actions/setup-node@v3
3636
with:
37-
node-version: 16
37+
node-version: 18
3838

3939
# Caching node_modules saves 50s on builds which don't modify dependencies.
4040
# Compared to yarn caching, it saves an additional 27 seconds.

.github/workflows/unit_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: install node.js
3030
uses: actions/setup-node@v3
3131
with:
32-
node-version: 16
32+
node-version: 18
3333

3434
# Caching node_modules saves 50s on builds which don't modify dependencies.
3535
# Compared to yarn caching, it saves an additional 27 seconds.

desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "duelyst-desktop",
33
"productName": "Duelyst",
44
"license": "CC0-1.0",
5-
"version": "1.97.6",
5+
"version": "1.97.7",
66
"main": "desktop.js",
77
"dependencies": {
88
"electron-debug": "^2.0.0",

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3.9"
22

33
x-base-service: &base
4-
image: node:16-alpine
4+
image: node:18-slim
55
entrypoint: sh
66
working_dir: /app
77
volumes:

docker/nodejs.Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
# This image is 114MB vs. 856MB for node:lts.
2-
FROM node:16-alpine
1+
# Slim images are based on Debian, but with a smaller size footprint.
2+
FROM node:18-slim
3+
4+
# Install bcrypt dependencies and git.
5+
# TODO: Isolate bcrypt dependencies to API images only.
6+
RUN apt-get update && apt-get -y install python3 make gcc g++ git
37

48
# Work around boneskull/yargs dependency using the deprecated git protocol.
5-
RUN apk add git
69
RUN git config --global url."https://github.com/".insteadOf git@github.com:
710
RUN git config --global url."https://".insteadOf git://
811

9-
# Add Python and other build utils for bcrypt.
10-
# TODO: Put this into an intermediate layer to reduce Game/Migrate/SP image size.
11-
RUN apk add python3 make gcc g++
12-
1312
# Include Node.js dependencies in the image.
1413
WORKDIR /duelyst
1514
COPY package.json /duelyst/

docker/start.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env bash
22

3+
# Install bcrypt dependencies and git.
4+
# TODO: Isolate bcrypt dependencies to API images only.
5+
apt-get update && apt-get install -y python3 make gcc g++ git
6+
37
# Work around boneskull/yargs dependency using the deprecated git protocol.
4-
apk add git
58
git config --global url."https://github.com/".insteadOf git@github.com:
69
git config --global url."https://".insteadOf git://
710

8-
# Install node-gyp dependencies for bcrypt in API and worker
9-
apk add python3 make gcc g++
10-
1111
# Install dependencies.
12-
yarn install --production
12+
yarn install --production && yarn cache clean
1313

1414
# Use exec to take over the PID from the shell, enabling signal handling.
1515
exec yarn $1

docs/DOCKER.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,57 @@ Tag and publish a container image:
3434
# <repo> is your AWS ECR repository name
3535
scripts/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

Comments
 (0)