-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
44 lines (29 loc) · 1.16 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
FROM node:16.16.0-alpine AS builder
# Create app directory
WORKDIR /usr/src/app
# node-gyp dependencies
RUN apk add --update --no-cache python3 make g++ && rm -rf /var/cache/apk/*
RUN npm i -g pnpm
# Files required by pnpm install
COPY .npmrc package.json pnpm-lock.yaml ./
# Install dependencies from pnpm-lock.yaml
RUN pnpm i --frozen-lockfile
COPY . .
RUN pnpm build
# Remove the packages specified in devDependencie
RUN pnpm prune --prod --no-optional
# By using the FROM statement again, we are telling Docker that it should create a new,
# fresh image without any connection to the previous one.
FROM node:16.16.0-alpine AS build
# Create app directory
WORKDIR /usr/src/app
COPY package.json ./
# Copy node_modules from builder. This will contains only production dependencies
COPY --from=builder /usr/src/app/node_modules ./node_modules
# Copy the built /dist folder from the builder image.
# This way we are only getting the /dist directory, without the devDependencies,
# installed in our final image.
COPY --from=builder /usr/src/app/dist ./dist
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
CMD [ "npm", "run", "start:prod" ]