File size: 2,003 Bytes
ebde876
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2299ca
424374d
b2299ca
ebde876
 
 
 
 
 
 
 
424374d
ebde876
 
424374d
ebde876
 
424374d
ebde876
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# ==========================================
# STAGE 1: Builder
# ==========================================
FROM ubuntu:22.04 AS builder

# Prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive

# Update system and install build dependencies
# curl, ca-certificates, gnupg: for Node.js
# openssl: for Prisma
RUN apt-get update && apt-get install -y \
    curl \
    ca-certificates \
    openssl \
    gnupg \
    && rm -rf /var/lib/apt/lists/*

# Install Node.js 20 (LTS)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy package files first for caching
COPY package*.json ./
COPY prisma ./prisma/

# Install dependencies (including devDependencies for build)
RUN npm install

# Copy source code
COPY . .

# Generate Prisma Client and Build
# Prisma client will be generated for "native" and "debian-openssl-*" targets per schema
RUN npx prisma generate
RUN npm run build

# ==========================================
# STAGE 2: Runner
# ==========================================
FROM ubuntu:22.04 AS runner

# Prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive

# Update system and install runtime dependencies
# We need openssl for Prisma runtime
RUN apt-get update && apt-get install -y \
    curl \
    ca-certificates \
    openssl \
    && rm -rf /var/lib/apt/lists/*

# Install Node.js 20 (LTS) - Optimized for runtime
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Set environment to production
ENV NODE_ENV=production

# Copy built artifacts from builder stage
# We use the specific path from the builder's output
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/.next/standalone ./

# Expose port
EXPOSE 3000

ENV HOSTNAME="0.0.0.0"
ENV PORT=3000

# Start server
CMD ["node", "server.js"]