-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
49 lines (37 loc) · 1.19 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
45
46
47
48
49
# Download and install the dependenciees for building the app
FROM node:20-alpine AS build-dependencies
WORKDIR /src
COPY package*.json ./
RUN npm ci
# Download and install the dependencies for running the app
FROM node:20-alpine AS production-dependencies
ENV NODE_ENV=production
WORKDIR /src
COPY package*.json ./
RUN npm ci
# Build the app
FROM node:20-alpine AS build
ARG COMMIT_SHA
ENV APP_VERSION=$COMMIT_SHA
# Create app directory
WORKDIR /src
# Copy the build dependencies
COPY --from=build-dependencies /src/node_modules /src/node_modules
# Required files are whitelisted in dockerignore
COPY . ./
RUN npm run build
# Final image that runs the app
FROM node:20.18.1-alpine3.20
USER node
ENV NODE_ENV=production
ENV npm_config_cache=/tmp/.npm
ARG COMMIT_SHA
ENV APP_VERSION=$COMMIT_SHA
WORKDIR /home/node/src
# Move only the files to the final image that are really needed
COPY --chown=node:node package*.json LICENSE SECURITY.md ./
COPY --chown=node:node --from=production-dependencies /src/node_modules/ ./node_modules/
COPY --chown=node:node --from=build /src/build/server ./build/server
COPY --chown=node:node --from=build /src/build/client ./build/client
EXPOSE 3000
CMD ["npm", "run", "start"]