-
Notifications
You must be signed in to change notification settings - Fork 42
/
Dockerfile
44 lines (29 loc) · 1.4 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Image selected based on https://snyk.io/blog/choosing-the-best-node-js-docker-image/
# Used best practices from https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/
# --------------> The build image
FROM node:18.17.1-bullseye-slim as build
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends git dumb-init
WORKDIR /usr/src/app
# Copy in main package.json and yarn.lock
COPY package.json /usr/src/app/
COPY yarn.lock /usr/src/app/
# Copy in workspace package.json files
COPY packages/api/package.json /usr/src/app/packages/api/
COPY packages/models/package.json /usr/src/app/packages/models/
RUN yarn install --pure-lockfile --production
COPY . /usr/src/app
RUN yarn create-version-file
# --------------> The production image
FROM node:18.17.1-bullseye-slim
ENV NODE_ENV=production
COPY --from=build /usr/bin/dumb-init /usr/bin/dumb-init
USER node
WORKDIR /usr/src/app
COPY --chown=node:node --from=build /usr/src/app/node_modules /usr/src/app/node_modules
COPY --chown=node:node --from=build /usr/src/app/version.js /usr/src/app/version.js
COPY --chown=node:node . /usr/src/app
# Remove unused files and folders
RUN rm -rf .git .scripts
# Create and change ownership of folder to store uploaded images
RUN mkdir -p /usr/src/app/dist/userimages && chown node:node /usr/src/app/dist/userimages
CMD ["dumb-init", "node", "packages/api/app.js"]