-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.optimized
More file actions
85 lines (66 loc) · 2.66 KB
/
Dockerfile.optimized
File metadata and controls
85 lines (66 loc) · 2.66 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
74
75
76
77
78
79
80
81
82
83
84
85
# =============================================================================
# OPTIMIZED SYPHON DOCKERFILE - SPEED FOCUSED
# =============================================================================
FROM node:22-alpine AS base
# Minimal package install for faster builds
RUN apk add --no-cache libc6-compat dumb-init
# =============================================================================
# DEPENDENCIES - Use npm ci with optimizations
# =============================================================================
FROM base AS deps
WORKDIR /app
# Copy package files
COPY package.json package-lock.json* ./
# Optimized npm install with aggressive caching
RUN npm ci --omit=dev --frozen-lockfile --prefer-offline --no-audit --no-fund --progress=false && \
npm cache clean --force
# =============================================================================
# BUILDER - Optimized build stage
# =============================================================================
FROM base AS builder
WORKDIR /app
# Copy package files
COPY package.json package-lock.json* ./
# Install with build optimizations
RUN npm ci --frozen-lockfile --prefer-offline --no-audit --no-fund --progress=false && \
npm cache clean --force
# Copy source (use .dockerignore to exclude unnecessary files)
COPY . .
# Build with optimizations
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
ENV SKIP_ENV_VALIDATION=1
# Single optimized build command
RUN npx prisma generate && \
npm run build && \
npm cache clean --force && \
rm -rf ~/.npm && \
rm -rf .git && \
rm -rf src && \
find . -name "*.map" -delete
# =============================================================================
# RUNTIME - Minimal production image
# =============================================================================
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3001
# Create user
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy only essential files
COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
COPY --from=builder --chown=nextjs:nodejs /app/generated ./generated
# Prisma setup
RUN find /app -name "*query_engine*" -exec chmod +x {} \; || true
USER nextjs
EXPOSE 3001
# Minimal healthcheck
HEALTHCHECK --interval=60s --timeout=5s --start-period=30s --retries=2 \
CMD curl -f http://localhost:3001/api/health || exit 1
ENTRYPOINT ["dumb-init", "--"]
CMD ["npm", "start"]