-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (39 loc) · 1.7 KB
/
Copy pathDockerfile
File metadata and controls
54 lines (39 loc) · 1.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
# ── Stage 1: Build ────────────────────────────────────────────────────────────
FROM node:20-alpine AS builder
WORKDIR /app
# Install backend dependencies
COPY package.json package-lock.json ./
RUN npm ci
# Install and build frontend
COPY src/web/package.json src/web/package-lock.json* ./src/web/
RUN npm ci --prefix src/web
COPY src/web ./src/web
RUN npm run build --prefix src/web
# Build TypeScript backend
COPY tsconfig.json knexfile.ts ./
COPY src ./src
RUN npm run build
# ── Stage 2: Production ───────────────────────────────────────────────────────
FROM node:20-alpine AS production
WORKDIR /app
# Install production dependencies only
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
# Copy compiled backend
COPY --from=builder /app/dist ./dist
# Copy migrations, seeds, and knexfile (needed at runtime via tsx)
COPY --from=builder /app/src/db ./src/db
COPY --from=builder /app/knexfile.ts ./knexfile.ts
COPY --from=builder /app/tsconfig.json ./tsconfig.json
# Copy built frontend assets
COPY --from=builder /app/src/web/dist ./src/web/dist
# Install tsx for running migrations at runtime
RUN npm install tsx typescript --save-dev
# Create data directories
RUN mkdir -p /data/chains /data/documents /app/logs
EXPOSE 3000
# Healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD wget -qO- http://localhost:3000/health || exit 1
# Run migrations (idempotent), then start
CMD ["sh", "-c", "npm run migrate && node dist/server.js"]