-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
67 lines (55 loc) · 1.89 KB
/
Dockerfile
File metadata and controls
67 lines (55 loc) · 1.89 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
# TaskFlow Dockerfile
# Multi-stage build for optimized production image using Next.js standalone output
# Stage 1: Base image with bun
FROM oven/bun:1-alpine AS base
# Install libc6-compat for better compatibility with Prisma and native modules
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Stage 2: Install dependencies
FROM base AS deps
# Copy package files
COPY package.json bun.lockb* ./
# Install dependencies using bun for reproducible builds
RUN bun install --frozen-lockfile
# Stage 3: Build the application
FROM base AS builder
WORKDIR /app
# Copy installed dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
# Copy source code
COPY . .
# Generate Prisma client (required for database access)
RUN bunx prisma generate
# Disable Next.js telemetry
ENV NEXT_TELEMETRY_DISABLED=1
# Build the application with standalone output
RUN bun run build
# Stage 4: Production runner
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Create a non-root user for security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy necessary files from builder
# Standalone server and dependencies (minimal output from Next.js)
COPY --from=builder /app/.next/standalone ./
# Static files (CSS, JS chunks)
COPY --from=builder /app/.next/static ./.next/static
# Prisma schema and migrations
COPY --from=builder /app/prisma ./prisma
# Prisma client and engine (required for database operations)
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
# Set ownership to non-root user
RUN chown -R nextjs:nodejs /app
# Switch to non-root user
USER nextjs
# Expose the application port
EXPOSE 3000
# Set environment variables for the server
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Start the server using the standalone server.js
CMD ["node", "server.js"]