forked from Open-audit-foundation/Open-Audit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.web
More file actions
89 lines (69 loc) · 2.8 KB
/
Copy pathDockerfile.web
File metadata and controls
89 lines (69 loc) · 2.8 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
86
87
88
89
# ============================================================================
# Dockerfile for Next.js Web Server with WebSocket
# ============================================================================
# This Dockerfile builds the Next.js application with:
# - HTTP server for Next.js pages/API routes
# - WebSocket server for real-time event streaming
# - Redis subscription for receiving events from worker
#
# Build: docker build -f Dockerfile.web -t open-audit-web .
# Run: docker run -p 3000:3000 --env-file .env open-audit-web
# ============================================================================
FROM node:20-alpine AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Copy package files
COPY package.json package-lock.json* ./
RUN npm ci
# ============================================================================
# Builder stage - Build Next.js application
# ============================================================================
FROM base AS builder
WORKDIR /app
# Copy dependencies
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Generate Prisma client
RUN if [ -d "prisma" ]; then npx prisma generate; fi
# Build Next.js
# This will generate the .next folder
RUN npm run build
# ============================================================================
# Runner stage - Production image
# ============================================================================
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy Next.js build output
COPY --from=builder /app/public ./public
# Set correct permissions for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Automatically leverage output traces to reduce image size
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy additional files needed for custom server
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/lib ./lib
COPY --from=builder /app/server-decoupled.ts ./
COPY --from=builder /app/tsconfig.json ./
COPY --from=builder /app/tsconfig.server.json ./
# Copy Prisma files if exists
COPY --from=builder /app/prisma ./prisma
# Set permissions
RUN chown -R nextjs:nodejs /app
# Switch to non-root user
USER nextjs
# Expose Next.js port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Start the custom Next.js server with WebSocket
CMD ["npx", "ts-node", "--project", "tsconfig.server.json", "server-decoupled.ts"]