-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
47 lines (35 loc) · 1.21 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
# This Dockerfile uses multi-stage build process.
# See https://docs.docker.com/develop/develop-images/multistage-build/
# Stage 1: Downloading dependencies and building the application
FROM node:18-bookworm-slim AS builder
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR /home/node
# Install app dependencies
COPY package*.json ./
RUN npm ci
# Copy sources and build the app
COPY --chown=node . .
RUN npm run build
# Remove dev packages
# (the rest will be copied to the production image at stage 2)
RUN npm prune --production
# Stage 2: Building the production image
FROM node:18-bookworm-slim
# Set the working directory
WORKDIR /home/node
# Copy dependencies
COPY --from=builder --chown=node /home/node/node_modules node_modules/
# Copy the app
COPY --from=builder --chown=node \
/home/node/package*.json \
/home/node/user-function.desc \
./
COPY --from=builder --chown=node /home/node/proto ./proto
COPY --from=builder --chown=node /home/node/dist ./dist
# Run the app as an unprivileged user for extra security.
USER node
# Run
EXPOSE 8080
# Call node directly to get SIGTERM for graceful shutdown
CMD ["node", "dist/src/index.js"]