-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
96 lines (73 loc) · 3.36 KB
/
Copy pathDockerfile
File metadata and controls
96 lines (73 loc) · 3.36 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
# =============================================================================
# BibleLM — Production Dockerfile
# Multi-stage build: deps → builder → runner
#
# Final image is based on Alpine Linux and only contains the minimal set of
# files output by Next.js "standalone" mode — no node_modules, no source.
#
# Build:
# docker build --build-arg GROQ_API_KEY=<key> -t biblelm .
#
# Run:
# docker run -p 3000:3000 --env-file .env.local biblelm
# =============================================================================
# -----------------------------------------------------------------------------
# Stage 1: deps — install production dependencies only
# -----------------------------------------------------------------------------
FROM node:22-alpine AS deps
# libc6-compat is required for certain native Node addons on Alpine
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Copy manifests first so Docker layer-caching skips npm install when unchanged
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
# -----------------------------------------------------------------------------
# Stage 2: builder — compile TypeScript, run data scripts, produce Next build
# -----------------------------------------------------------------------------
FROM node:22-alpine AS builder
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Copy ALL dependencies (including devDependencies) needed to build
COPY package.json package-lock.json ./
RUN npm ci
# Copy the rest of the source
COPY . .
# Pre-process data bundles (morphology, translations, opengnt, etc.)
# These produce the JSON files under data/ that are bundled into the build.
# If data/ is already populated (e.g. checked into git) you can comment these out.
RUN npm run build:morphhb
RUN npm run build:openhebrewbible
RUN npm run build:translations
RUN npm run build:opengnt
# Build the Next.js app in standalone mode
# NEXT_TELEMETRY_DISABLED silences the anonymous telemetry prompt
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build
# Pre-compute the BM25 search-engine state so cold starts are <10ms at runtime
RUN npx ts-node --project tsconfig.scripts.json scripts/build-retrieval-index.ts
# -----------------------------------------------------------------------------
# Stage 3: runner — minimal production image
# -----------------------------------------------------------------------------
FROM node:22-alpine AS runner
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Security: run as non-root
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Bind to all interfaces inside the container; the host port is mapped via -p
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Copy the self-contained server bundle produced by Next.js standalone output.
# This includes the minimal node_modules required to run — nothing more.
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/public ./public
# Copy the pre-built data bundles (BM25 state, Bible index, morphology, etc.)
# These are read at runtime by the retrieval engine.
COPY --from=builder --chown=nextjs:nodejs /app/data ./data
USER nextjs
EXPOSE 3000
# Start the standalone Next.js server (no next start needed)
CMD ["node", "server.js"]