chore: update Dockerfile for production use

This uses a standard Node.js Dockerfile template and removes the old, unused entrypoint script.
This commit is contained in:
Matthew Lopez 2024-06-24 15:00:47 -04:00
parent 7e2b47ce75
commit 41977cf7af
No known key found for this signature in database
GPG Key ID: 302A6EE3D63B7E0E
3 changed files with 52 additions and 50 deletions

View File

@ -1,6 +1,4 @@
.git
config.json
logs
certs
cdn
node_modules
.git
node_modules
dist
logs

View File

@ -1,16 +1,48 @@
FROM node:18-alpine
RUN apk add --no-cache python3 make gcc g++
WORKDIR /app
COPY "docker/entrypoint.sh" ./
COPY package*.json ./
RUN npm install bcrypt && npm rebuild bcrypt --build-from-source
RUN npm install
COPY . ./
VOLUME [ "/app/config.json", "/app/certs" ]
CMD ["sh", "entrypoint.sh"]
# syntax=docker/dockerfile:1
ARG app_dir="/home/node/app"
# * Base Node.js image
FROM node:20-alpine AS base
ARG app_dir
WORKDIR ${app_dir}
# * Installing production dependencies
FROM base AS dependencies
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci --omit=dev
# * Installing development dependencies and building the application
FROM base AS build
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci
COPY . .
RUN npm run build
# * Running the final application
FROM base AS final
ARG app_dir
RUN mkdir -p ${app_dir}/logs
RUN chown node:node ${app_dir}/logs
ENV NODE_ENV production
USER node
COPY package.json .
COPY --from=dependencies ${app_dir}/node_modules ${app_dir}/node_modules
COPY --from=build ${app_dir}/dist ${app_dir}/dist
CMD ["node", "."]

View File

@ -1,28 +0,0 @@
#!/bin/sh
# this doesnt check game server specific certs, only static file paths
files='config.json'
for file in $files; do
if [ ! -f $file ]; then
echo "$PWD/$file file does not exist. Please mount and try again."
exit 1
fi
done
# check for keys
keys='certs/nex/datastore/secret.key certs/service/account/secret.key certs/service/account/aes.key certs/service/account/private.pem certs/service/account/public.pem'
for file in $keys; do
if [ ! -f "$file" ]; then
if [ x"${GENERATE_NEW_KEYS}" = "x" ]; then
echo "$PWD/$file file does not exist. Please mount and try again."
exit 1
else
echo "$PWD/$file file does not exist. Generating a temporary one"
node generate-keys.js nex datastore
node generate-keys.js account
fi
fi
done
exec node src/server.js