Skip to content

Commit

Permalink
OS base image, ESM, Chromium, and dependency upgrades (#383)
Browse files Browse the repository at this point in the history
- Upgrade Alpine 3.17 -> 3.19
- Upgrade Debian Bullseye -> Bookworm
- Prefer `debian` tag over `bullseye-slim`
- Upgrade Chromium 112 -> 121
- Migrate codebase to `"type": "module"`
- Update all dependencies to latest
  • Loading branch information
claabs authored Mar 3, 2024
1 parent 734c18d commit 435b2e9
Show file tree
Hide file tree
Showing 43 changed files with 4,694 additions and 2,622 deletions.
18 changes: 8 additions & 10 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
module.exports = {
root: true,
env: {
node: true
node: true,
es2023: true,
},
extends: [
'airbnb-base',
'plugin:@typescript-eslint/recommended',
'airbnb-typescript/base',
'plugin:prettier/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
sourceType: 'module'
sourceType: 'module',
},
rules: {
'import/extensions': 0,
'import/prefer-default-export': 0,
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error'],
},
ignorePatterns: ['dist/**', 'node_modules/**', '**/*.config.js', '.eslintrc.js', 'docs/**'],
}
ignorePatterns: ['dist', 'node_modules', '!.*.cjs', 'docs/**'],
};
4 changes: 4 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
printWidth: 100,
singleQuote: true,
};
4 changes: 0 additions & 4 deletions .prettierrc.js

This file was deleted.

8 changes: 3 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
"type": "node",
"request": "launch",
"name": "Debug Main",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"autoAttachChildProcesses": true,
"program": "${workspaceRoot}/node_modules/vite-node/dist/cli.mjs",
"args": [
"${workspaceFolder}/src/index.ts"
],
"outputCapture": "std",
"console": "integratedTerminal"
}
},
]
}
17 changes: 7 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
########
# BASE
########
FROM node:18-alpine3.17 as base
FROM node:18-alpine3.19 as base

ENV DISTRO=alpine
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
Expand All @@ -13,15 +13,12 @@ WORKDIR /usr/app
########
FROM base as deps

# Go to https://hub.docker.com/_/node/ and note the latest stable Alpine version available (e.g. alpine3.17).
# Go to https://pkgs.alpinelinux.org/package/v3.17/community/x86_64/chromium (replace with the latest Alpine version)
# and note the Chromium version available. Then go to https://github.com/puppeteer/puppeteer/releases?q=chromium&expanded=true
# and find the latest puppeteer version that supports that Chromium version, and update it in the package.json.
# Go to https://hub.docker.com/_/node/ and note the latest stable Alpine version available (e.g. alpine3.19).
# Go to https://pkgs.alpinelinux.org/package/v3.19/community/x86_64/chromium (replace with the latest Alpine version)
# and note the Chromium version available. Then go to https://pptr.dev/chromium-support
# and find the latest version that supports that Chromium version, and update it in the package.json.
RUN apk add --no-cache \
'chromium=~112' \
nss \
freetype \
harfbuzz \
'chromium=~121' \
ca-certificates \
ttf-freefont \
# App dependencies
Expand Down Expand Up @@ -74,7 +71,7 @@ LABEL org.opencontainers.image.title="epicgames-freegames-node" \
org.opencontainers.image.name="epicgames-freegames-node" \
org.opencontainers.image.revision=${COMMIT_SHA} \
org.opencontainers.image.ref.name=${BRANCH} \
org.opencontainers.image.base.name="node:18-alpine3.17" \
org.opencontainers.image.base.name="node:18-alpine3.19" \
org.opencontainers.image.version="latest"

ENV NODE_ENV=production \
Expand Down
7 changes: 3 additions & 4 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
########
# BASE
########
FROM node:18-bullseye-slim as base
FROM node:18-bookworm-slim as base

ENV DISTRO=debian
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
Expand All @@ -13,7 +13,6 @@ WORKDIR /usr/app
########
FROM base as deps

# Chromium dependencies https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker
# The Google Chrome apt list only seems to provide the latest version, so version compatibility with puppeteer is questionable
RUN apt-get update \
&& apt-get install -y wget gnupg procps \
Expand Down Expand Up @@ -77,8 +76,8 @@ LABEL org.opencontainers.image.title="epicgames-freegames-node" \
org.opencontainers.image.name="epicgames-freegames-node" \
org.opencontainers.image.revision=${COMMIT_SHA} \
org.opencontainers.image.ref.name=${BRANCH} \
org.opencontainers.image.base.name="node:18-bullseye-slim" \
org.opencontainers.image.version="bullseye-slim"
org.opencontainers.image.base.name="node:18-bookworm-slim" \
org.opencontainers.image.version="debian"

ENV NODE_ENV=production \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable \
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ This image is available from both [GitHub Container Registry](https://github.com

If you're [experiencing issues with Chromium starting](https://github.com/claabs/epicgames-freegames-node/issues/164) (hangs on login/notification), you can try the Debian image:

* `ghcr.io/claabs/epicgames-freegames-node:bullseye-slim`
* `charlocharlie/epicgames-freegames:bullseye-slim`
* `ghcr.io/claabs/epicgames-freegames-node:debian`
* `charlocharlie/epicgames-freegames:debian`

If you are using full JSON configuration, the only remaining Docker configurables are the [port](#ports) and [volume](#volumes).

Expand Down
8 changes: 4 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
TEMP_CONFIG="/tmp/config.json"

# Resolve and output the below variables to /tmp/config.json
npm run entrypoint-config
node --enable-source-maps /usr/app/dist/src/entrypoint-config.js
TZ=$(cat $TEMP_CONFIG | jq -r ".timezone")
RUN_ON_STARTUP=$(cat $TEMP_CONFIG | jq -r ".runOnStartup")
RUN_ONCE=$(cat $TEMP_CONFIG | jq -r ".runOnce")
Expand All @@ -18,7 +18,7 @@ echo "$TZ" > /etc/timezone
# If runOnStartup is set, run it once before setting up the schedule
echo "Run on startup: ${RUN_ON_STARTUP}"
if [ "$RUN_ON_STARTUP" = "true" ]; then
node /usr/app/dist/src/index.js
node --enable-source-maps /usr/app/dist/src/index.js
fi

# If runOnce is not set, schedule the process
Expand All @@ -27,14 +27,14 @@ if [ "$RUN_ONCE" = "false" ]; then
echo "Setting cron schedule as ${CRON_SCHEDULE}"
if [ "$DISTRO" = "alpine" ]; then
# Add the command to the crontab
echo "${CRON_SCHEDULE} cd /usr/app && node /usr/app/dist/src/index.js" | crontab -
echo "${CRON_SCHEDULE} cd /usr/app && node --enable-source-maps /usr/app/dist/src/index.js" | crontab -
# Run the cron process. The container should halt here and wait for the schedule.
/usr/sbin/crond -f -l 8
else
# Debian cron wipes the environment, so we save it to a script to load in cron
printenv | sed 's/^\(.*\)$/export \1/g' > /root/project_env.sh
# Add the command to the crontab. Debian cron doesn't ensure single instance, so we use flock to ensure it
echo "${CRON_SCHEDULE} . /root/project_env.sh && cd /usr/app && flock -n /var/lock/epicgames.lock node /usr/app/dist/src/index.js > /proc/1/fd/1 2>/proc/1/fd/2" | crontab -
echo "${CRON_SCHEDULE} . /root/project_env.sh && cd /usr/app && flock -n /var/lock/epicgames.lock node --enable-source-maps /usr/app/dist/src/index.js > /proc/1/fd/1 2>/proc/1/fd/2" | crontab -
# Run the cron process. The container should halt here and wait for the schedule.
cron -f
fi
Expand Down
Loading

0 comments on commit 435b2e9

Please sign in to comment.