forked from IamLiuLv/compoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (53 loc) · 1.88 KB
/
Dockerfile
File metadata and controls
73 lines (53 loc) · 1.88 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# --------- Dependencies Installation Stage -----------
FROM node:18.17-alpine AS deps
WORKDIR /app
ARG proxy
RUN apk add --no-cache libc6-compat && npm install -g pnpm@9.8.0
# If proxy is provided, set npm mirror
RUN [ -z "$proxy" ] || pnpm config set registry https://registry.npmmirror.com/
# Copy dependency manifests
COPY package.json pnpm-lock.yaml* ./
# Check if lockfile exists
RUN [ -f pnpm-lock.yaml ] || (echo "Lockfile not found." && exit 1)
# Install dependencies with frozen lockfile for better reproducibility
RUN pnpm install --frozen-lockfile
# --------- Build Stage -----------
FROM node:18.17-alpine AS builder
WORKDIR /app
ARG proxy
RUN apk add --no-cache libc6-compat && npm install -g pnpm@9.8.0
# Copy dependencies
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build application
RUN pnpm build
# --------- Runtime Stage -----------
FROM node:18.17-alpine AS runner
WORKDIR /app
ARG proxy
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN apk add --no-cache curl ca-certificates \
&& update-ca-certificates
# Copy build artifacts
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.mjs ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy package.json for version information
COPY --from=builder /app/package.json ./package.json
# Copy data directory if it exists
COPY --from=builder /app/data ./data
# Set production environment
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
ENV PORT 3000
EXPOSE 3000
# Switch to non-root user
USER nextjs
# Health check to validate application is running properly
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:3000/ || exit 1
# Start application
CMD ["node", "server.js"]