-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (46 loc) · 1.74 KB
/
Dockerfile
File metadata and controls
58 lines (46 loc) · 1.74 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
# Dockerfile
# Stage 1: Install dependencies
FROM node:22.12-alpine3.21 AS deps
# Install security updates
RUN apk upgrade --no-cache
# Install pnpm using corepack with specific version
RUN corepack enable && corepack prepare pnpm@9.15.4 --activate
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --prod --frozen-lockfile
# Stage 2: Build the application
FROM node:22.12-alpine3.21 AS builder
RUN apk upgrade --no-cache
RUN corepack enable && corepack prepare pnpm@9.15.4 --activate
WORKDIR /app
# Accept build arguments for NEXT_PUBLIC_ environment variables
ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
ENV NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=$NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
# Accept OPENAI_API_KEY for build time
ARG OPENAI_API_KEY
ENV OPENAI_API_KEY=$OPENAI_API_KEY
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm run build
# Stage 3: Production server (Runner)
FROM node:22.12-alpine3.21 AS runner
# Install security updates
RUN apk upgrade --no-cache && \
apk add --no-cache dumb-init
WORKDIR /app
ENV NODE_ENV=production
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy the standalone output from the builder stage
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
USER nextjs
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Use dumb-init to handle signals properly
CMD ["dumb-init", "node", "server.js"]