Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
130 lines (104 loc) · 4.7 KB
/
Copy pathDockerfile
File metadata and controls
130 lines (104 loc) · 4.7 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# syntax=docker/dockerfile:1
# ---- Stage 1: Base ----
FROM node:22-alpine AS base
ARG ALPINE_MIRROR=""
ARG NPM_REGISTRY=""
RUN if [ -n "$ALPINE_MIRROR" ]; then \
sed -i "s|dl-cdn.alpinelinux.org|$ALPINE_MIRROR|g" /etc/apk/repositories; \
fi && \
apk add --no-cache libc6-compat
RUN npm_registry="$NPM_REGISTRY"; \
while [ "${npm_registry%/}" != "$npm_registry" ]; do \
npm_registry="${npm_registry%/}"; \
done; \
if [ -n "$npm_registry" ]; then \
export COREPACK_NPM_REGISTRY="$npm_registry"; \
fi && \
corepack enable && \
corepack prepare pnpm@10.28.0 --activate
WORKDIR /app
# ---- Stage 2: Dependencies ----
FROM base AS deps
ARG NPM_REGISTRY
# Native build tools for sharp, @napi-rs/canvas
RUN apk add --no-cache python3 build-base g++ cairo-dev pango-dev jpeg-dev giflib-dev librsvg-dev
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY packages/ ./packages/
COPY scripts/ ./scripts/
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
npm_registry="$NPM_REGISTRY"; \
while [ "${npm_registry%/}" != "$npm_registry" ]; do \
npm_registry="${npm_registry%/}"; \
done; \
if [ -n "$npm_registry" ]; then \
pnpm config set registry "$npm_registry"; \
fi && \
pnpm install --frozen-lockfile --ignore-scripts
# ---- Stage 3: Builder ----
FROM base AS builder
ARG ALLOWED_FRAME_ANCESTORS
ARG NEXT_PUBLIC_MAIC_EDITOR_ENABLED
ARG NEXT_PUBLIC_MAIC_EDITOR_RENDERER_ENABLED
ARG NEXT_PUBLIC_MAIC_PLAYBACK_RENDERER_ENABLED
ARG NEXT_PUBLIC_PI_CHAT_ENABLED
ARG NEXT_PUBLIC_COURSEWARE_REFERENCE_ENABLED
ARG NEXT_PUBLIC_SHOW_VOCATIONAL_TEST_UI
ARG NEXT_PUBLIC_ENABLE_VIDEO_EXPORT
ARG NEXT_PUBLIC_VIDEO_EXPORT_CTA_DESTINATION
ARG NEXT_PUBLIC_ENABLE_PPTX_IMPORT
ARG NEXT_PUBLIC_PRO_WORKBENCH_ENABLED
ENV ALLOWED_FRAME_ANCESTORS=$ALLOWED_FRAME_ANCESTORS
ENV NEXT_PUBLIC_MAIC_EDITOR_ENABLED=$NEXT_PUBLIC_MAIC_EDITOR_ENABLED
ENV NEXT_PUBLIC_MAIC_EDITOR_RENDERER_ENABLED=$NEXT_PUBLIC_MAIC_EDITOR_RENDERER_ENABLED
ENV NEXT_PUBLIC_MAIC_PLAYBACK_RENDERER_ENABLED=$NEXT_PUBLIC_MAIC_PLAYBACK_RENDERER_ENABLED
ENV NEXT_PUBLIC_PI_CHAT_ENABLED=$NEXT_PUBLIC_PI_CHAT_ENABLED
ENV NEXT_PUBLIC_COURSEWARE_REFERENCE_ENABLED=$NEXT_PUBLIC_COURSEWARE_REFERENCE_ENABLED
ENV NEXT_PUBLIC_SHOW_VOCATIONAL_TEST_UI=$NEXT_PUBLIC_SHOW_VOCATIONAL_TEST_UI
ENV NEXT_PUBLIC_ENABLE_VIDEO_EXPORT=$NEXT_PUBLIC_ENABLE_VIDEO_EXPORT
ENV NEXT_PUBLIC_VIDEO_EXPORT_CTA_DESTINATION=$NEXT_PUBLIC_VIDEO_EXPORT_CTA_DESTINATION
ENV NEXT_PUBLIC_ENABLE_PPTX_IMPORT=$NEXT_PUBLIC_ENABLE_PPTX_IMPORT
ENV NEXT_PUBLIC_PRO_WORKBENCH_ENABLED=$NEXT_PUBLIC_PRO_WORKBENCH_ENABLED
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/packages ./packages
COPY . .
# Build the workspace packages (rollup + tsc) here, not inside `pnpm install`,
# so the deps stage only resolves and links dependencies. The importer's
# rollup + terser pass is the heaviest step (see #1526). This is the same chain
# the root `postinstall` runs locally, so local dev is unchanged.
# The explicit V8 old-space size makes the heap limit predictable instead of
# derived from the container's memory limit; with it, this step completes under
# a 1 GiB container limit. It bounds the JS heap only, not the step's total
# memory, so it does not by itself prevent a host- or VM-level OOM.
RUN NODE_OPTIONS=--max-old-space-size=1024 pnpm run build:packages
RUN pnpm build
# ---- Stage 4: Runner ----
FROM node:22-alpine AS runner
ARG ALPINE_MIRROR=""
WORKDIR /app
ENV NODE_ENV=production
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
RUN if [ -n "$ALPINE_MIRROR" ]; then \
cp /etc/apk/repositories /tmp/apk.repositories; \
sed -i "s|dl-cdn.alpinelinux.org|$ALPINE_MIRROR|g" /etc/apk/repositories; \
fi && \
apk add --no-cache libc6-compat cairo pango jpeg giflib librsvg && \
if [ -n "$ALPINE_MIRROR" ]; then \
mv /tmp/apk.repositories /etc/apk/repositories; \
fi
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# The app persists classrooms, classroom media, and usage records under
# ./data, which docker-compose.yml mounts as the openmaic-data named volume.
# Nothing above creates the directory, so on first run Docker materializes
# the mountpoint as root:root and every write from the unprivileged runtime
# user fails with EACCES — classroom persistence silently stores nothing
# (THU-MAIC/OpenMAIC#1438). Creating it here makes the empty-volume copy-up
# inherit the runtime user's ownership.
RUN mkdir -p /app/data && chown -R nextjs:nodejs /app/data
USER nextjs
EXPOSE 3000
CMD ["node", "server.js"]