-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
62 lines (43 loc) · 1.69 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
60
61
62
# Build Stage
FROM node:18-alpine AS builder
# cd into working directory
WORKDIR /usr/src/app
# Copy over the the package, lock file, and local .npmrc
COPY package*.json ./
COPY /*.npmrc ./
# Use docker secrets to install all dependencies
RUN --mount=type=secret,id=npm,target=/root/.npmrc npm ci --ignore-scripts
# Copy over everything else and build the project
COPY . .
RUN npm run build
# Remove build info from the compiled output
RUN rm build/.tsbuildinfo
# Remove all development dependencies and install only dependencies required to run in production
RUN rm -rf node_modules
RUN --mount=type=secret,id=npm,target=/root/.npmrc npm ci --production --ignore-scripts
# Production stage
FROM node:18-alpine as base
# cd into working directory
WORKDIR /usr/src/app
# Chown the directory
RUN chown node:node .
# Switch to service user
USER node
# IMPORTANT. The following code ONLY copies over:
# 1. The `build` folder, the compiled version of `src`
# 2. The `node_modules` with production dependencies only
# 3. All `.env` files in the root of the project
# This is to keep our images nice and clean.
# If this service requires additional code or configuration, make sure to add it here
# Copy over package.json
COPY package.json ./
# Copy the build from the first stage
COPY --from=builder /usr/src/app/build/ build/
# Copy the production node_modules from the first stage
COPY --from=builder /usr/src/app/node_modules/ node_modules/
# Copy over all configuration files we need to run
COPY .env* ./
# Expose the port
EXPOSE 8080
# Start the service, exposing the node process directly to Kubernetes
CMD [ "node", "--experimental-specifier-resolution=node", "--enable-source-maps", "build/index.js" ]