-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
46 lines (32 loc) · 992 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
46
# Stage 1: Build Stage
FROM node:20-slim as build
# Install git (required by npm install)
RUN apt-get update
# Set the working directory in the container
WORKDIR /app
# Copy only package.json and package-lock.json to leverage Docker cache
COPY package*.json ./
# Install all dependencies for building (including dev dependencies)
RUN npm install
# Copy all files into the container (including .ts files)
COPY . .
# Build the TypeScript files
RUN npm run build
# Stage 2: Production Stage
FROM node:20-slim
# Set the working directory in the container
WORKDIR /app
# Copy only necessary files from the build stage
COPY --from=build /app/package*.json ./
COPY --from=build /app/dist ./dist
# Install only production dependencies
RUN apt-get update && npm install --omit=dev
# Set NODE_ENV to production for better performance
ENV NODE_ENV=production
ARG BUILD_MODE
ENV MODE=$BUILD_MODE
ENV PORT=3000
# Expose port
EXPOSE 3000
# Run the application
CMD ["npm", "run", "start:prod"]