Repository navigation
Expand file tree
/
Copy pathDockerfile.server
More file actions
59 lines (53 loc) · 2.51 KB
/
Copy pathDockerfile.server
File metadata and controls
59 lines (53 loc) · 2.51 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
# ── Stage 1: full install (build tools needed for sqlite3 native addon) ───────
FROM node:20-alpine AS all-deps
WORKDIR /build
RUN apk add --no-cache python3 make g++
COPY package.json package-lock.json ./
COPY client/package.json ./client/
COPY server/package.json ./server/
RUN npm ci
# ── Stage 2: production-only deps (same build tools, smaller node_modules) ────
FROM node:20-alpine AS prod-deps
WORKDIR /build
RUN apk add --no-cache python3 make g++
COPY package.json package-lock.json ./
COPY client/package.json ./client/
COPY server/package.json ./server/
RUN npm ci --omit=dev
# ── Stage 3: build the React client ───────────────────────────────────────────
FROM node:20-alpine AS client-build
WORKDIR /build
COPY --from=all-deps /build/node_modules ./node_modules
COPY package.json ./
COPY server/package.json ./server/package.json
COPY client/ ./client/
RUN npm run build -w client
# ── Stage 4: compile the Hono server (TypeScript → JavaScript) ────────────────
FROM node:20-alpine AS server-build
WORKDIR /build
COPY --from=all-deps /build/node_modules ./node_modules
COPY package.json ./
COPY client/package.json ./client/package.json
COPY server/ ./server/
RUN npm run build -w server
# tsc does not copy non-TS assets; bring schema.sql and prompts into dist so the runtime can find them
RUN cp server/src/db/schema.sql server/dist/db/schema.sql
RUN cp -r server/src/prompts server/dist/prompts
# ── Stage 5: production image ──────────────────────────────────────────────────
FROM node:20-alpine
WORKDIR /app
# Pre-compiled node_modules (includes the sqlite3 native binary)
COPY --from=prod-deps /build/node_modules ./node_modules
# Compiled server and built client
COPY --from=server-build /build/server/dist ./server/dist/
COPY --from=client-build /build/client/dist ./client/dist/
# Run as the unprivileged node user. /data holds the SQLite DB + uploads volume;
# chown here covers fresh volumes — volumes created by an older (root) image need
# a one-time `docker exec -u root <container> chown -R node:node /data`.
RUN mkdir -p /data && chown -R node:node /data /app
USER node
EXPOSE 3000
ENV NODE_ENV=production
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget -qO- http://localhost:3000/health || exit 1
CMD ["node", "server/dist/index.js"]