Skip to content

Commit

Permalink
Merge pull request #199 from willroberts/upgrade-node
Browse files Browse the repository at this point in the history
Upgrades Node.js to v18
  • Loading branch information
willroberts authored Oct 26, 2022
2 parents c4aed71 + 50b6320 commit d93487b
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: install node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

# Caching node_modules saves 50s on builds which don't modify dependencies.
# Compared to yarn caching, it saves an additional 27 seconds.
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/integration_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
jobs:
integration_tests:
runs-on: ubuntu-latest
container: node:16
container: node:18-slim
services:
redis:
image: redis:6
Expand All @@ -31,6 +31,9 @@ jobs:
POSTGRES_DB: duelyst

steps:
- name: install bcrypt dependencies and git
run: apt-get update && apt-get -y install python3 make gcc g++ git

- name: check out code
uses: actions/checkout@v3

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_coffeescript.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: install node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

# Caching node_modules saves 50s on builds which don't modify dependencies.
# Compared to yarn caching, it saves an additional 27 seconds.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_javascript.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: install node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

# Caching node_modules saves 50s on builds which don't modify dependencies.
# Compared to yarn caching, it saves an additional 27 seconds.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: install node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

# Caching node_modules saves 50s on builds which don't modify dependencies.
# Compared to yarn caching, it saves an additional 27 seconds.
Expand Down
2 changes: 1 addition & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "duelyst-desktop",
"productName": "Duelyst",
"license": "CC0-1.0",
"version": "1.97.6",
"version": "1.97.7",
"main": "desktop.js",
"dependencies": {
"electron-debug": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.9"

x-base-service: &base
image: node:16-alpine
image: node:18-slim
entrypoint: sh
working_dir: /app
volumes:
Expand Down
13 changes: 6 additions & 7 deletions docker/nodejs.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# This image is 114MB vs. 856MB for node:lts.
FROM node:16-alpine
# Slim images are based on Debian, but with a smaller size footprint.
FROM node:18-slim

# Install bcrypt dependencies and git.
# TODO: Isolate bcrypt dependencies to API images only.
RUN apt-get update && apt-get -y install python3 make gcc g++ git

# Work around boneskull/yargs dependency using the deprecated git protocol.
RUN apk add git
RUN git config --global url."https://github.com/".insteadOf [email protected]:
RUN git config --global url."https://".insteadOf git://

# Add Python and other build utils for bcrypt.
# TODO: Put this into an intermediate layer to reduce Game/Migrate/SP image size.
RUN apk add python3 make gcc g++

# Include Node.js dependencies in the image.
WORKDIR /duelyst
COPY package.json /duelyst/
Expand Down
10 changes: 5 additions & 5 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bash

# Install bcrypt dependencies and git.
# TODO: Isolate bcrypt dependencies to API images only.
apt-get update && apt-get install -y python3 make gcc g++ git

# Work around boneskull/yargs dependency using the deprecated git protocol.
apk add git
git config --global url."https://github.com/".insteadOf [email protected]:
git config --global url."https://".insteadOf git://

# Install node-gyp dependencies for bcrypt in API and worker
apk add python3 make gcc g++

# Install dependencies.
yarn install --production
yarn install --production && yarn cache clean

# Use exec to take over the PID from the shell, enabling signal handling.
exec yarn $1
54 changes: 54 additions & 0 deletions docs/DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,57 @@ Tag and publish a container image:
# <repo> is your AWS ECR repository name
scripts/publish_container.sh <service> <version> <registry> <repo>
```

## Notes on Image Sizes

There are a few strategies we use to keep image sizes small:

1. Use an alternative base image, i.e. `node:18-slim` instead of `node:18`
2. Avoid installing Node.js `devDependencies` in container builds
3. Purge the Yarn cache from container builds

#### Comparison of Base Images

Sizes of Docker images built by `scripts/build_container.sh`:

| Service | Image | Size | ECR Size | 50 GB Limit |
|---------|----------------|---------|----------|-------------|
| Node.js | node:18 | 942 MB | N/A | N/A |
| Node.js | node:18-slim | 234 MB | N/A | N/A |
| Node.js | node:18-alpine | 165 MB | N/A | N/A |
| Node.js | node:16 | 858 MB | N/A | N/A |
| Node.js | node:16-slim | 174 MB | N/A | N/A |
| Node.js | node:16-alpine | 114 MB | N/A | N/A |
| API | node:18 | 1170 MB | 425 MB | 117 / 23 ea |
| API | node:18-slim | 767 MB | 254 MB | 196 / 39 ea |
| API | node:18-alpine | 626 MB | 187 MB | 267 / 53 ea |
| API | node:16 | 1040 MB | 396 MB | 126 / 25 ea |
| API | node:16-slim | 615 MB | 214 MB | 233 / 46 ea |
| API | node:16-alpine | 530 MB | 169 MB | 295 / 59 ea |

Image sizes reported by `docker image ls` include all layers, and are much
higher than the image sizes reported by ECR. ECR gives us 50 GB of storage
for free, so the 50 GB Limit column shows how many total images we can store
for each image, and how many we can store for each of the five services we
build.

The `-alpine` images pull Node.js builds from unofficial-builds.nodejs.org,
while the default and `-slim` images pull official builds from nodejs.org.
While the `-slim` images are 25-35% larger than the `-alpine` images, they're
still small enough to allow us to store several dozen versions in ECR before we
start to approach the 50 GB ECR limit. Additionally, the `-slim` images are
based on Debian, which comes with a more familiar toolchain.

Similarly, Node.js v18 images are 10-20% larger than Node.js v16 images, but we
may be able to get some of this size back by replacing Mocha, Axios, and other
dependencies with their new native counterparts in Node.js v18.

#### Regarding `bcrypt`

We could further reduce image sizes by removing the `bcrypt` dependencies from
the base image layer. These currently include `python3`, `make`, `gcc`, and
`g++`. The `bcrypt` dependency is only used by the API service, during the
login flow in `server/routes/session.coffee`. One option here could be to move
authentication flows (such as JWT signing, granting, and validation) to their
own microservice to isolate this dependency, reducing the image size of all
other services.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "open-duelyst",
"license": "CC0-1.0",
"version": "1.97.6",
"version": "1.97.7",
"engines": {
"yarn": ">= 1.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "1.97.6"
"version": "1.97.7"
}

0 comments on commit d93487b

Please sign in to comment.