1+ # #######################################
2+ # First stage of multistage build
3+ # #######################################
4+ # Use Build image with label `builder
5+ # #######################################
6+ # use
7+ FROM node:lts-alpine AS builder
8+
9+ # Setup working directory for project
10+ WORKDIR /app
11+
12+ COPY ./package.json ./
13+ COPY ./package-lock.json ./
14+ COPY ./tsconfig.json ./
15+
16+ # install node modules
17+ # use `npm ci` instead of `npm install`
18+ # to install exact version from `package-lock.json`
19+ RUN npm ci
20+
21+ # Copy project files
22+ COPY src ./src
23+
24+ # Build project
25+ RUN npm run build:ts
26+
27+ # sets environment to production
28+ # and removes packages from devDependencies
29+ RUN npm prune --production
30+
31+ # #######################################
32+ # Second stage of multistage build
33+ # #######################################
34+ # Use other build image as the final one
35+ # that won't have source codes
36+ # #######################################
37+ FROM node:lts-alpine
38+
39+ # Setup working directory for project
40+ WORKDIR /app
41+
42+ # Copy published in previous stage binaries
43+ # from the `builder` image
44+ COPY --from=builder /app/dist ./dist
45+ COPY --from=builder /app/node_modules ./node_modules
46+
47+ # Set URL that App will be exposed
48+ EXPOSE 5000
49+
50+ # sets entry point command to automatically
51+ # run application on `docker run`
52+ ENTRYPOINT ["node" , "./dist/index.js" ]
0 commit comments