-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
60 lines (45 loc) · 1.4 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
60
# Stage 1: Install dependencies
FROM node:20-alpine AS deps
WORKDIR /app
# Install pnpm globally in the deps stage
RUN npm install -g pnpm
COPY package.json pnpm-lock.yaml ./
COPY prisma ./prisma
# Install dependencies using pnpm
RUN pnpm install
# Stage 2: Build application
FROM node:20-alpine AS builder
WORKDIR /app
# Install pnpm globally in the builder stage
RUN npm install -g pnpm
COPY . .
COPY --from=deps /app/node_modules ./node_modules
ARG SECRET
ARG DATABASE_URL
ARG NEXT_PUBLIC_URL
ARG NEXT_PUBLIC_API_URL
ARG NEXT_PUBLIC_SMTP_HOST
ARG NEXT_PUBLIC_SMTP_USER
ARG NEXT_PUBLIC_SMTP_PASS
ENV SECRET=$SECRET
ENV DATABASE_URL=$DATABASE_URL
ENV NEXT_PUBLIC_URL=$NEXT_PUBLIC_URL
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_SMTP_HOST=$NEXT_PUBLIC_SMTP_HOST
ENV NEXT_PUBLIC_SMTP_USER=$NEXT_PUBLIC_SMTP_USER
ENV NEXT_PUBLIC_SMTP_PASS=$NEXT_PUBLIC_SMTP_PASS
# Use pnpm to build the app
RUN pnpm run build
# Stage 3: Prepare production image
FROM node:20-alpine AS prod
WORKDIR /app
COPY --from=builder /app/public ./public
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml
# Ensure pnpm is installed in the production image
RUN npm install -g pnpm
# Use pnpm to run the app
CMD ["pnpm", "run", "start"]