-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
60 lines (43 loc) · 1.39 KB
/
Dockerfile
File metadata and controls
60 lines (43 loc) · 1.39 KB
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
# Stage 1: Build
FROM node:lts-alpine AS build
# Set the working directory inside the container
WORKDIR /app
# Enable Corepack and use the specified Yarn version
RUN corepack enable && corepack prepare yarn@stable --activate
# Copy package manager configuration files
COPY package.json yarn.lock .yarnrc.yml ./
# Copy Yarn berry files
COPY .yarn ./.yarn
# Install dependencies
RUN yarn install --immutable
# Copy the entire application code
COPY . .
# Build the application
RUN yarn build
# Verify the build output exists
RUN ls -la dist && \
if [ ! -f dist/main.js ]; then \
echo "dist/main.js not found!" && exit 1; \
fi
# Stage 2: Run
FROM node:lts-alpine AS production
# Install curl for health checks
RUN apk add --no-cache curl
# Set the working directory inside the container
WORKDIR /app
# Enable Corepack and use the specified Yarn version
RUN corepack enable && corepack prepare yarn@stable --activate
# Copy necessary files from the build stage
COPY --from=build /app/package.json /app/yarn.lock /app/.yarnrc.yml ./
COPY --from=build /app/.yarn ./.yarn
COPY --from=build /app/dist ./dist
COPY --from=build /app/nest-cli.json ./
COPY --from=build /app/tsconfig.json ./
# Install production dependencies only
RUN yarn install --immutable
# Switch to non-root user for security
USER node
# Expose the application port
EXPOSE 3030
# Start the application
CMD ["node", "dist/main.js"]