-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
38 lines (28 loc) · 974 Bytes
/
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
# Stage 1: Build the source code
FROM node:20-alpine3.18 AS build_src
WORKDIR /app
RUN apk update && apk add --no-cache g++ make python3 && rm -rf /var/cache/apk/*
COPY . .
# Install dependencies and build the project
RUN yarn install
RUN yarn build
# Stage 2: Build the dependencies
FROM node:20-alpine3.18 AS build_deps
WORKDIR /app
RUN apk update && apk add --no-cache g++ make python3 && rm -rf /var/cache/apk/*
ENV NODE_ENV=production
# Copy ./build files from the previous stage
COPY --from=build_src /app/dist ./dist
COPY --from=build_src /app/package.json ./
# Install production dependencies
RUN yarn install --frozen-lockfile --production
RUN yarn cache clean --all
# Stage 3: Create the final image
FROM node:20-alpine3.18
WORKDIR /app
# Copy files from the previous build stage
COPY --from=build_deps /app .
# Use a non-root user if possible
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
ENTRYPOINT ["node", "./dist/index.js"]