forked from cerinoligutom/GraphQL-Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
59 lines (39 loc) · 1.24 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
58
59
# Declare a Docker build-time variable
ARG NODE_IMAGE_VERSION=18-alpine
### Builder Stage ###
FROM node:${NODE_IMAGE_VERSION} as builder
WORKDIR /usr/src/app
RUN npm install -g pnpm
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 --chown=node:node --from=builder /usr/src/app/build .
RUN npm install -g pnpm
# On npm@9, `npm set-script` has been removed: https://github.blog/changelog/2022-10-24-npm-v9-0-0-released/
# This is mainly for disabling Husky on Docker and CI.
RUN npm pkg set scripts.prepare=" "
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"]