-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
96 lines (71 loc) · 2.65 KB
/
Copy pathDockerfile
File metadata and controls
96 lines (71 loc) · 2.65 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
90
91
92
93
94
95
96
# Multi-stage build for optimized production image
# Stage 0: Fetch PocketBase binary
FROM ghcr.io/muchobien/pocketbase:latest AS pocketbase-fetcher
# Stage 1: Dependencies
FROM node:20-alpine AS deps
WORKDIR /app
# Install dependencies based on the package manager
COPY package.json package-lock.json ./
RUN npm ci --only=production
# Stage 2: Builder
FROM node:20-alpine AS builder
WORKDIR /app
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
COPY package.json package-lock.json ./
# Install all dependencies (including dev dependencies for build)
RUN npm ci
# Copy source code
COPY . .
# Set environment variables for build
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
# Build the Next.js application
# Using --webpack flag to mitigate Google Fonts optimization issues
RUN npm run build -- --webpack
# Copy public assets to standalone output for proper deployment
RUN mkdir -p .next/standalone/public && cp -r public/* .next/standalone/public/ || true
# Stage 3: Runner
FROM node:20-alpine AS runner
WORKDIR /app
# Set environment
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Install ffmpeg (provides ffprobe for video duration detection)
RUN apk add --no-cache ffmpeg
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Create courses directory for volume mount
RUN mkdir -p /courses && chown nextjs:nodejs /courses
# Create PocketBase directories
RUN mkdir -p /pb /pb_data /pb_migrations
# Copy necessary files from builder
# Copy public assets from standalone output (includes static files)
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone/public ./public
COPY --from=builder /app/package.json ./package.json
# Copy built application
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/version-history.md ./version-history.md
# Copy PocketBase binary and migrations
COPY --from=pocketbase-fetcher /usr/local/bin/pocketbase /pb/pocketbase
COPY pocketbase/pb_migrations /pb_migrations
# Copy entrypoint script
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
# Set permissions (must run as root before switching user)
RUN chmod +x /pb/pocketbase \
&& chown -R nextjs:nodejs /pb_data \
&& chmod -R 555 /pb_migrations \
&& chmod +x /app/docker-entrypoint.sh \
&& chown nextjs:nodejs /app/docker-entrypoint.sh
# Switch to non-root user
USER nextjs
# Expose ports
EXPOSE 3000
# EXPOSE 8090
# Set environment variable for port
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Start via entrypoint
CMD ["/app/docker-entrypoint.sh"]