-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
59 lines (43 loc) · 1.62 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
ARG NODE_VERSION=21.7.3
################################################################################
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine as base
################################################################################
# Create a stage for installing production dependencies.
FROM base as deps
# Install build-base.
RUN apk add build-base python3
# Set working directory.
WORKDIR /app
# Download dependencies as a separate step to take advantage of Docker's caching.
COPY ./package.json ./
RUN npm install
################################################################################
# Create a stage for building the application.
FROM deps as build
ARG PUBLIC_PROJECT_ID
ARG PUBLIC_METADATA_NAME
ARG PUBLIC_METADATA_DESCRIPTION
# Set working directory.
WORKDIR /app
# Copy the rest of the source files into the image.
COPY . .
# Run the build script.
RUN npm run build
################################################################################
# Create a new stage to run the application with minimal runtime dependencies
# where the necessary files are copied from the build stage.
FROM base as final
# Use production node environment by default.
ENV NODE_ENV production
# Run the application as a non-root user.
USER node
# Set working directory.
WORKDIR /app
# Copy the production dependencies from the deps stage and also
# the built application from the build stage into the image.
COPY --from=deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY --from=build /app/server ./server
# Run the application.
ENTRYPOINT [ "node", "server/entry.express" ]