OnyxMunk/AudioForge
0
1# ============================================
2# AudioForge Frontend - Production Dockerfile
3# ============================================
4# Multi-stage build with optimized caching
5# Production-ready Next.js deployment
6
7FROM node:20-alpine AS base
8
9# Install security updates
10RUN apk upgrade --no-cache && \
11 apk add --no-cache libc6-compat curl
12
13# ============================================
14# Dependencies Stage
15# ============================================
16FROM base AS deps
17
18WORKDIR /app
19
20# Enable pnpm
21RUN corepack enable && corepack prepare pnpm@9.1.0 --activate
22
23# Copy dependency files
24COPY package.json pnpm-lock.yaml* ./
25
26# Install dependencies (allow lockfile update for flexibility)
27RUN pnpm install --no-frozen-lockfile --prod=false
28
29# ============================================
30# Builder Stage
31# ============================================
32FROM base AS builder
33
34WORKDIR /app
35
36# Copy dependency files first for better caching
37COPY package.json package-lock.json* ./
38
39# Install ALL dependencies
40RUN npm install
41
42# Copy source code
43COPY . .
44
45# Remove test files and vitest config to avoid build conflicts
46RUN rm -rf src/**/*.test.ts src/**/*.test.tsx src/test vitest.config.ts
47
48# Set build environment variables
49ENV NEXT_TELEMETRY_DISABLED=1 \
50 NODE_ENV=production
51
52# Build application
53RUN npm run build
54
55# ============================================
56# Production Runner Stage
57# ============================================
58FROM base AS runner
59
60WORKDIR /app
61
62# Set production environment
63ENV NODE_ENV=production \
64 NEXT_TELEMETRY_DISABLED=1 \
65 PORT=3000 \
66 HOSTNAME="0.0.0.0"
67
68# Create system user for security
69RUN addgroup --system --gid 1001 nodejs && \
70 adduser --system --uid 1001 nextjs
71
72# Copy built application
73COPY --from=builder /app/public ./public
74COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
75COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
76
77# Switch to non-root user
78USER nextjs
79
80# Health check
81HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
82 CMD curl -f http://localhost:3000/ || exit 1
83
84# Expose port
85EXPOSE 3000
86
87# Labels for metadata
88LABEL maintainer="AudioForge Team" \
89 version="1.0.0" \
90 description="AudioForge Frontend - Production Ready" \
91 org.opencontainers.image.source="https://github.com/audioforge/audioforge"
92
93# Start application
94CMD ["node", "server.js"]
95 