-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (44 loc) · 1.41 KB
/
Dockerfile
File metadata and controls
58 lines (44 loc) · 1.41 KB
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
# syntax=docker/dockerfile:1.5
########################
# 🔧 Base image for building
########################
FROM --platform=$BUILDPLATFORM node:20-slim AS base
WORKDIR /app
# Install libc compatibility for native modules like sharp and update all packages
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends libc6 && \
rm -rf /var/lib/apt/lists/*
########################
# 📦 Install dependencies (cached)
########################
FROM base AS deps
WORKDIR /app
COPY app/package.json app/package-lock.json* ./
RUN npm ci
########################
# 🛠 Build the Next.js app
########################
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY app .
ENV NODE_ENV=production
RUN npm run build
########################
# 🚀 Production image
########################
FROM node:20-slim AS runner
WORKDIR /app
ARG BUILD_TIMESTAMP
LABEL org.opencontainers.image.created=$BUILD_TIMESTAMP
ENV NODE_ENV=production
ENV PORT=3000
COPY --from=deps /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
# Generate runtime env file at container start
COPY app/scripts/generate-runtime-env.js ./scripts/generate-runtime-env.js
EXPOSE 3000
ENTRYPOINT ["sh", "-c", "node ./scripts/generate-runtime-env.js && npx next start"]