-
Notifications
You must be signed in to change notification settings - Fork 23
/
Dockerfile
57 lines (38 loc) · 1.13 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
50
51
52
53
54
55
56
57
# Declare a Docker build-time variable
ARG NODE_IMAGE_VERSION=20-alpine
### Builder Stage ###
FROM node:${NODE_IMAGE_VERSION} as builder
WORKDIR /usr/src/app
RUN npm install -g pnpm
COPY .husky/install.mjs .husky/install.mjs
COPY package.json ./
COPY pnpm-lock.yaml ./
COPY patches ./patches
RUN ls -al
RUN pnpm install --frozen-lockfile
# Copy files from host to container then list it
COPY ./ ./
RUN ls -al
# Build project
RUN pnpm build:prod
# List files under build directory for reference
RUN ls -al build
### Final Stage ###
FROM node:${NODE_IMAGE_VERSION} as app
ENV NODE_ENV=production
EXPOSE 8080
WORKDIR /usr/src/app
# Copy the necessary files from the builder stage to this stage
COPY .husky/install.mjs .husky/install.mjs
COPY --chown=node:node --from=builder /usr/src/app/build .
RUN npm install -g pnpm
COPY pnpm-lock.yaml ./
COPY patches ./patches
# Install production dependencies only
RUN pnpm install --frozen-lockfile --prod
# List the final directory for reference
RUN ls -al
RUN ls ./src -al
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#non-root-user
USER node
CMD ["node", "./src/app.js"]