feat: Create Dockerfile.app (node→nginx multi-stage), nginx.conf (SPA +…

- "docker/Dockerfile.app"
- "docker/nginx.conf"
- "docker-compose.yml"

GSD-Task: S02/T01
This commit is contained in:
jlightner 2026-03-26 06:43:59 +00:00
parent 8ef0d4bf01
commit 80ca11409c
7 changed files with 4409 additions and 0 deletions

37
docker-compose.yml Normal file
View file

@ -0,0 +1,37 @@
# Kerf — full-stack Docker Compose
# Runs the vectorization engine + web app behind nginx reverse-proxy.
#
# Usage:
# docker compose up -d # start all services
# docker compose ps # check health
# docker compose down # tear down
services:
kerf-engine:
build:
context: .
dockerfile: docker/Dockerfile.engine
ports:
- "8000:8000"
healthcheck:
test: ["CMD", "curl", "-sf", "http://localhost:8000/engine/health"]
interval: 15s
timeout: 5s
start_period: 10s
retries: 3
kerf-app:
build:
context: .
dockerfile: docker/Dockerfile.app
ports:
- "3000:80"
depends_on:
kerf-engine:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:80/"]
interval: 15s
timeout: 5s
start_period: 5s
retries: 3

39
docker/Dockerfile.app Normal file
View file

@ -0,0 +1,39 @@
# ── Kerf App — multi-stage Docker build ──
# Stage 1: Build the Vite/React app
# Stage 2: Serve via nginx with reverse-proxy to engine
# ── Stage 1: Build ──
FROM node:22-alpine AS builder
WORKDIR /build
# Copy root workspace config first (npm ci needs it for workspace resolution)
COPY package.json package-lock.json ./
# Copy the app workspace
COPY app/ ./app/
# Install dependencies from the workspace root
RUN npm ci --workspace=app
# Build the app (tsc -b && vite build)
RUN npm run build --workspace=app
# ── Stage 2: Runtime — nginx serving static files ──
FROM nginx:1.27-alpine AS runtime
# Remove default nginx site
RUN rm /etc/nginx/conf.d/default.conf
# Copy custom nginx config
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
# Copy built assets from builder
COPY --from=builder /build/app/dist /usr/share/nginx/html
EXPOSE 80
HEALTHCHECK --interval=15s --timeout=5s --start-period=5s --retries=3 \
CMD wget -qO- http://127.0.0.1:80/ || exit 1
CMD ["nginx", "-g", "daemon off;"]

43
docker/nginx.conf Normal file
View file

@ -0,0 +1,43 @@
# Kerf App nginx reverse-proxy + SPA static server
# Serves the Vite-built app and proxies /engine/* to the kerf-engine container.
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# ── Gzip ──
gzip on;
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
gzip_min_length 256;
# ── Proxy /engine/* to the engine container ──
location /engine/ {
proxy_pass http://kerf-engine:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Engine trace/simplify can take a while on large images
proxy_read_timeout 120s;
proxy_send_timeout 120s;
# Allow large image uploads (engine accepts multipart)
client_max_body_size 50m;
}
# ── SPA fallback serve index.html for client-side routes ──
location / {
try_files $uri $uri/ /index.html;
}
# ── Static asset caching ──
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|otf|eot)$ {
expires 7d;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
}

4271
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

6
package.json Normal file
View file

@ -0,0 +1,6 @@
{
"name": "kerf-engine-root",
"private": true,
"version": "0.0.0",
"workspaces": ["app"]
}

6
tsconfig.json Normal file
View file

@ -0,0 +1,6 @@
{
"files": [],
"references": [
{ "path": "./app" }
]
}

7
vitest.config.ts Normal file
View file

@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
projects: ['app/vite.config.ts'],
},
})