-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
45 lines (31 loc) · 986 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
39
40
41
42
43
44
45
# Base image for building the application
FROM node:20-bookworm AS builder
# Set working directory
WORKDIR /app
# Copy package.json and package-lock.json to the container
COPY package.json yarn.lock ./
# Install dependencies
RUN yarn install
# Copy the rest of the application code
COPY . .
# Build the application
RUN yarn build
# Separate stage for validation (build and test)
FROM builder AS validator
# Run tests as part of the validation
RUN yarn test
# Final image for running the application
FROM node:20-slim-bookworm
LABEL author="X Author Name"
# Set working directory
WORKDIR /app
# Copy built application code and node_modules from builder
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY package.json yarn.lock ./
# Expose the port the app runs on
EXPOSE 3000
# Define a health check
HEALTHCHECK --start-period=30s CMD curl -f http://localhost:3000 || exit 1
# Start the application
CMD ["node", "dist/index.js"]