-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
59 lines (40 loc) · 1.36 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
# Stage 1: Build the NestJS application
FROM node:18-alpine AS builder
# Set working directory
WORKDIR /app
# Install bash to use it in production stage for running multiple commands
RUN apk add --no-cache bash
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
# Generate Prisma client
RUN npx prisma generate
# Build the NestJS application
RUN npm run build
# Stage 2: Create a lightweight production image
FROM node:18-alpine AS production
# Set working directory
WORKDIR /app
# Install bash
RUN apk add --no-cache bash
# Copy the package.json and package-lock.json to the production image
COPY package*.json ./
# Install only production dependencies
RUN npm install --only=production
# Copy the build output from the builder stage
COPY --from=builder /app/dist ./dist
# Copy Prisma schema and migrations
COPY --from=builder /app/prisma ./prisma
# Copy the generated Prisma client
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
COPY public ./public
# Expose the port the app runs on
EXPOSE 3000
# Set the NODE_ENV to production
ENV NODE_ENV=production
# Command to run Prisma migrations and start the application
CMD ["bash", "-c", "npx prisma migrate deploy && node dist/main"]