-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathDockerfile
More file actions
67 lines (56 loc) · 2 KB
/
Dockerfile
File metadata and controls
67 lines (56 loc) · 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
55
56
57
58
59
60
61
62
63
64
65
# Multi-stage Dockerfile for Next.js + Prisma (SQLite)
ARG NODE_VERSION=20
FROM node:${NODE_VERSION}-bookworm-slim AS base
WORKDIR /app
ENV NODE_ENV=production
RUN corepack enable
RUN apt-get update -y && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*
FROM base AS deps
# Install dependencies (use lockfile if present)
COPY package.json pnpm-lock.yaml* ./
RUN pnpm install --frozen-lockfile
COPY prisma ./prisma
# Generate Prisma Client early so it is cached with node_modules
ENV DB=sqlite
ENV SQLITE_URL=file:/app/data/openchat.db
RUN pnpm exec prisma generate --schema prisma/schema.sqlite.prisma
FROM base AS builder
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Set build-time env vars so Next.js static generation doesn't fail
ENV DB=sqlite
ENV SQLITE_URL=file:/app/data/openchat.db
ENV AUTH_SECRET=build-time-secret-will-be-overridden
ENV AUTH_URL=http://localhost:3000
# Build Next.js
RUN pnpm run build
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
ENV DB=sqlite
ENV SQLITE_URL=file:/app/data/openchat.db
ENV AUTH_TRUST_HOST=true
ENV AUTH_URL=http://localhost:3000
ENV AUTH=true
# Copy runtime assets
COPY --from=builder /app/public ./public
COPY --from=builder /app/prisma ./prisma
COPY --from=deps /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/.next ./.next
# Install OpenSSL (required by Prisma and for generating secrets)
RUN apt-get update -y && apt-get install -y openssl && rm -rf /var/lib/apt/lists/* \
&& pnpm run prisma:gen
EXPOSE 3000
# Generate AUTH_SECRET if not provided, run migrations, and start the app
CMD sh -c '\
if [ -z "$AUTH_SECRET" ]; then \
export AUTH_SECRET="$(openssl rand -base64 32)"; \
echo "⚠️ AUTH_SECRET was not provided - generated temporary secret"; \
echo "⚠️ Set AUTH_SECRET env var for persistence across restarts"; \
fi; \
echo "Starting OpenChat..."; \
pnpm run migrate:deploy || pnpm run db:push; \
pnpm start'