chore: update Docker configuration

This commit is contained in:
Matthew Lopez 2024-07-02 15:30:25 -04:00
parent 95fab2bae9
commit 58600b945e
No known key found for this signature in database
GPG Key ID: 302A6EE3D63B7E0E
4 changed files with 51 additions and 24 deletions

View File

@ -1,5 +1,6 @@
.git
.env
node_modules
config.json
certs
src/logs
dist
logs
uploads

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ node_modules
config.json
certs
src/logs
uploads

View File

@ -1,15 +1,52 @@
FROM node:18-alpine
# syntax=docker/dockerfile:1
RUN apk add --no-cache python3 make gcc g++
WORKDIR /app
ARG app_dir="/home/node/app"
COPY "docker/entrypoint.sh" ./
COPY package*.json ./
RUN npm install
# * Base Node.js image
FROM node:20-alpine AS base
ARG app_dir
WORKDIR ${app_dir}
COPY . ./
VOLUME [ "/app/config.json", "/app/certs" ]
# * Installing production dependencies
FROM base AS dependencies
CMD ["sh", "entrypoint.sh"]
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 . .
# TODO: re-enable after TypeScript migration
#RUN npm run build
# * Running the final application
FROM base AS final
ARG app_dir
RUN mkdir -p ${app_dir}/src/logs && chown node:node ${app_dir}/src/logs \
&& mkdir -p ${app_dir}/uploads && chown node:node ${app_dir}/uploads
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} ${app_dir}
# TODO: change back after TypeScript migration
#COPY --from=build ${app_dir}/dist ${app_dir}/dist
CMD ["node", "."]

View File

@ -1,12 +0,0 @@
#!/bin/sh
files='config.json certs/access/private.pem certs/access/aes.key'
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
exec node src/server.js