-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
80 lines (63 loc) · 2.34 KB
/
Dockerfile
File metadata and controls
80 lines (63 loc) · 2.34 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
# /Dockerfile
# =============================================
# Stage 1: Build Dependencies for BOTH projects
# =============================================
FROM node:20-alpine AS deps
WORKDIR /app
# Install root (Next.js) dependencies first
COPY package.json package-lock.json* ./
RUN npm ci
# Install worker dependencies separately
COPY worker/package.json worker/package-lock.json* ./worker/
RUN cd worker && npm ci
# =============================================
# Stage 2: Build the Application
# =============================================
FROM node:20-alpine AS builder
WORKDIR /app
# Copy dependencies for BOTH projects from the previous stage
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/worker/node_modules ./worker/node_modules
# Copy all source code over
COPY . .
# Pass and set the required build-time environment variables
ARG APP_REGION
ARG ENABLE_INTERNATIONAL_API
ARG NEXTAUTH_URL
ARG ENABLE_VIDEO_CAPTURE
ENV APP_REGION=$APP_REGION
ENV ENABLE_INTERNATIONAL_API=$ENABLE_INTERNATIONAL_API
ENV NEXTAUTH_URL=$NEXTAUTH_URL
ENV ENABLE_VIDEO_CAPTURE=$ENABLE_VIDEO_CAPTURE
# Increase memory for the build process just in case
ENV NODE_OPTIONS="--max-old-space-size=4096"
# Run the build script which will now succeed
RUN npm run build
# =============================================
# Stage 3: Final Production Image
# =============================================
FROM node:20-alpine AS runner
WORKDIR /app
# Install FFmpeg using the Alpine package manager so the video scripts can use it
RUN apk add --no-cache ffmpeg
# Set environment to production
ENV NODE_ENV production
# Unset the build-time memory option for runtime
ENV NODE_OPTIONS=""
# Copy all necessary production files
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/start.sh ./start.sh
COPY --from=builder /app/worker/dist ./worker/dist
COPY --from=builder /app/worker/package.json ./worker/package.json
COPY --from=builder /app/worker/node_modules ./worker/node_modules
COPY --from=builder /app/scripts ./scripts
# Make the startup script executable
RUN chmod +x ./start.sh
# Expose ports for Next.js app and the worker
EXPOSE 3000
EXPOSE 4000
# This command will run the start.sh script
CMD ["./start.sh"]