Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (50 loc) · 2.09 KB
/
Copy pathDockerfile
File metadata and controls
64 lines (50 loc) · 2.09 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
# Base image with Bun
FROM oven/bun:1 AS base
WORKDIR /app
# Install dependencies
# `--ignore-scripts` skips the `fumadocs-mdx` postinstall (declared in
# package.json by PR #131). That hook needs `source.config.ts` and
# `content/docs/`, which aren't present in this hermetic deps stage --
# only `package.json` + the lockfile are. We regenerate fumadocs sources
# explicitly in the builder stage below, where the full tree is available.
FROM base AS deps
COPY package.json pnpm-lock.yaml ./
RUN bun install --frozen-lockfile --ignore-scripts
# Build Next.js
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
# Compile MDX docs into `src/.source/` before `next build` -- this is what
# the postinstall hook would have done on a non-Docker install.
RUN bunx fumadocs-mdx source.config.ts src/.source
RUN bun run build
# Bundle idempotent migration script with all dependencies
RUN bun build src/db/migrate-idempotent.ts --target=bun --outfile=migrate-idempotent.js
# Bundle one-shot encryption backfill script. Self-host operators run it once
# after upgrading to v0.4.x via:
# docker compose exec app bun encrypt-backfill.js [--dry-run]
RUN bun build scripts/encrypt-backfill.ts --target=bun --outfile=encrypt-backfill.js
# Final runtime image
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Copy Next.js standalone output + public files
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Copy bundled idempotent migration script (no node_modules needed!)
COPY --from=builder /app/migrate-idempotent.js ./migrate-idempotent.js
# Copy bundled encryption backfill script
COPY --from=builder /app/encrypt-backfill.js ./encrypt-backfill.js
# Copy migrations folder
COPY --from=builder /app/src/db/migrations ./src/db/migrations
# Copy entrypoint
COPY docker-entrypoint.sh ./docker-entrypoint.sh
RUN chmod +x docker-entrypoint.sh
EXPOSE 3000
ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["bun", "server.js"]