-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.api
More file actions
54 lines (47 loc) · 2.2 KB
/
Dockerfile.api
File metadata and controls
54 lines (47 loc) · 2.2 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
# RexAlgo Next.js API — build from monorepo ROOT (Railway default clone).
# Docker Compose still uses backend/Dockerfile with context ./backend.
# @see railway.toml at repo root
FROM node:20-bookworm-slim AS base
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates openssl python3 make g++ \
&& rm -rf /var/lib/apt/lists/*
FROM base AS deps
COPY backend/package.json ./
RUN npm install
FROM base AS builder
COPY --from=deps /app/node_modules ./node_modules
COPY backend/ .
ENV NEXT_TELEMETRY_DISABLED=1
# `next build` loads server modules (e.g. `lib/db.ts`). No Postgres exists in the
# image build — supply a throwaway URL and skip migrate/seed until runtime
# (Railway injects the real `DATABASE_URL` on the runner).
ENV REXALGO_SKIP_DB_BOOT=1
ENV PGSSLMODE=disable
ENV DATABASE_URL=postgres://build:build@127.0.0.1:5432/rexalgo_build?sslmode=disable
# Next evaluates server route modules during `next build` ("Collecting page data").
# Railway (and most CI) does not inject service env vars into the *image build*
# step — only into the running container. Without these, `requireSecretEnv` in
# `lib/auth.ts` / `middleware.ts` throws and the build fails. These values exist
# only in the builder stage; the `runner` image below is `FROM base` and does
# not inherit them, so production still requires real secrets at runtime.
ENV JWT_SECRET=0000000000000000000000000000000000000000000000000000000000000000
ENV ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000000
ENV FINGERPRINT_SECRET=0000000000000000000000000000000000000000000000000000000000000000
RUN npm run build
FROM base AS runner
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
RUN apt-get update && apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
# Same flat standalone layout as backend/Dockerfile (see comment there).
WORKDIR /app
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
# Drizzle migrations run on first DB use (see backend/src/lib/db.ts).
COPY --from=builder /app/drizzle ./drizzle
EXPOSE 3000
CMD ["node", "server.js"]