infra: docker compose dev + production Dockerfiles
- docker-compose.dev.yml: hot-reload dev stack (rete-watch + server :7357 + web :5173) - docker-compose.yml: production stack - packages/chess/Dockerfile + nginx.conf: chess web image - packages/server/Dockerfile: server image - Dockerfile.dev: shared dev base image (Bun + workspace deps preinstalled) - .dockerignore: build context exclusions Used by Playwright e2e tests (run via .sisyphus/scripts/run-pw.sh which connects to the running dev stack instead of spawning its own server).
This commit is contained in:
parent
f1aa831546
commit
9d408b5996
7 changed files with 286 additions and 0 deletions
36
packages/chess/Dockerfile
Normal file
36
packages/chess/Dockerfile
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# syntax=docker/dockerfile:1.7
|
||||
# Vite-built React SPA for @paratype/chess, served by nginx.
|
||||
# Build context: monorepo root.
|
||||
|
||||
FROM oven/bun:1.3 AS deps
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json bun.lock ./
|
||||
COPY tsconfig.base.json tsconfig.json ./
|
||||
COPY packages/rete/package.json packages/rete/
|
||||
COPY packages/chess/package.json packages/chess/
|
||||
COPY packages/server/package.json packages/server/
|
||||
|
||||
RUN bun install --frozen-lockfile
|
||||
|
||||
# ---- builder
|
||||
FROM deps AS builder
|
||||
# rete must be built first — chess imports it via the "import" export
|
||||
# which points at dist/index.js.
|
||||
COPY packages/rete packages/rete
|
||||
RUN bun run --filter @paratype/rete build
|
||||
|
||||
COPY packages/chess packages/chess
|
||||
|
||||
# Bake the WebSocket URL into the bundle. Override at build time with
|
||||
# --build-arg VITE_WS_URL=wss://your-host/ws
|
||||
ARG VITE_WS_URL=ws://localhost:7357/ws
|
||||
ENV VITE_WS_URL=$VITE_WS_URL
|
||||
|
||||
RUN bun run --filter @paratype/chess build
|
||||
|
||||
# ---- runtime
|
||||
FROM nginx:1.27-alpine AS runtime
|
||||
COPY --from=builder /app/packages/chess/dist /usr/share/nginx/html
|
||||
COPY packages/chess/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 80
|
||||
18
packages/chess/nginx.conf
Normal file
18
packages/chess/nginx.conf
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# SPA history fallback — react-router uses client-side routes.
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# Cache hashed Vite assets aggressively.
|
||||
location /assets/ {
|
||||
access_log off;
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
try_files $uri =404;
|
||||
}
|
||||
}
|
||||
54
packages/server/Dockerfile
Normal file
54
packages/server/Dockerfile
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# syntax=docker/dockerfile:1.7
|
||||
# Authoritative Bun WebSocket server for @paratype/chess.
|
||||
# Build context: monorepo root (so workspace deps resolve).
|
||||
|
||||
FROM oven/bun:1.3 AS deps
|
||||
WORKDIR /app
|
||||
|
||||
# Manifests first for cacheable installs.
|
||||
COPY package.json bun.lock ./
|
||||
COPY tsconfig.base.json tsconfig.json ./
|
||||
COPY packages/rete/package.json packages/rete/
|
||||
COPY packages/chess/package.json packages/chess/
|
||||
COPY packages/server/package.json packages/server/
|
||||
|
||||
RUN bun install --frozen-lockfile
|
||||
|
||||
# ---- builder: compile @paratype/rete (server resolves its "import"
|
||||
# field to dist/index.js, so we MUST build it before runtime).
|
||||
FROM deps AS builder
|
||||
COPY packages/rete packages/rete
|
||||
RUN bun run --filter @paratype/rete build
|
||||
|
||||
# Bring in remaining sources needed at runtime.
|
||||
COPY packages/chess/src packages/chess/src
|
||||
COPY packages/chess/package.json packages/chess/
|
||||
COPY packages/server packages/server
|
||||
|
||||
# ---- runtime
|
||||
FROM oven/bun:1.3-slim AS runtime
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production \
|
||||
PORT=7357 \
|
||||
LOG_LEVEL=info
|
||||
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
|
||||
# rete: built dist + its symlinked node_modules
|
||||
COPY --from=builder /app/packages/rete/dist packages/rete/dist
|
||||
COPY --from=builder /app/packages/rete/package.json packages/rete/package.json
|
||||
COPY --from=builder /app/packages/rete/node_modules packages/rete/node_modules
|
||||
|
||||
# chess: source consumed by server.ts via "default" export, plus its
|
||||
# per-package node_modules so symlinked deps (zod, etc.) resolve.
|
||||
COPY --from=builder /app/packages/chess/src packages/chess/src
|
||||
COPY --from=builder /app/packages/chess/package.json packages/chess/package.json
|
||||
COPY --from=builder /app/packages/chess/node_modules packages/chess/node_modules
|
||||
|
||||
# server: full copy already includes its node_modules.
|
||||
COPY --from=builder /app/packages/server packages/server
|
||||
|
||||
EXPOSE 7357
|
||||
USER bun
|
||||
CMD ["bun", "run", "packages/server/src/index.ts"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue