omni-pca-docs/Dockerfile
Ryan Malloy 17cd57f1bf Compose convention: dev/prod target switch, HMR-friendly Caddy labels
Aligns with the warehack-ing host convention (matches birdcage-docs):

Dockerfile — multi-stage with named targets:
  base   shared npm ci + COPY
  dev    npx astro dev --host 0.0.0.0 --port 4321  (HMR enabled)
  build  npx astro build (produces /app/dist)
  prod   caddy:2-alpine serves /srv with /health probe + HEALTHCHECK

docker-compose.yml — picks the target via APP_ENV in .env:
  build.target = ${APP_ENV:-dev}
  caddy.reverse_proxy upstream port = ${APP_PORT:-4321}
  Adds the streaming/HMR caddy labels CLAUDE.md requires for Vite-over-
  Caddy: flush_interval=-1, transport.read/write_timeout=0, keepalive,
  stream_timeout=24h, stream_close_delay=5s
  Volume mounts ./src, ./public, astro.config.mjs (live in dev, harmless
  in prod since the prod stage doesn't reference /app)

astro.config.mjs — vite.server.hmr block now picks up VITE_HMR_HOST
env var and configures host/protocol/clientPort for wss-on-443 HMR
through Caddy. Falls back to undefined when unset so plain
'npm run dev' still works.

Caddyfile — adds /health endpoint for the Dockerfile HEALTHCHECK,
SPA-style try_files fallback chain (path -> path/index.html -> /index.html).

Makefile — adds 'make dev' / 'make prod' that rewrite APP_ENV+APP_PORT
in .env then rebuild. Tail-logs after up/restart so you see startup
diagnostics without a separate 'make logs'.

.env.example — five vars (COMPOSE_PROJECT_NAME, APP_ENV, APP_PORT,
PUBLIC_DOMAIN, VITE_HMR_HOST), defaulting to prod mode against the
public hai-omni-pro-ii.warehack.ing domain. .env stays gitignored so
each environment (local, remote) can override.

Local container rebuilt + recreated, healthy, /health returns 200,
PUBLIC_DOMAIN locally still set to .l.warehack.ing in the host .env.
2026-05-10 18:05:54 -06:00

35 lines
1.4 KiB
Docker

# syntax=docker/dockerfile:1.7
#
# Multi-stage Dockerfile matching the warehack-ing services convention:
# * dev — Astro dev server with HMR, source-mounted via compose volumes
# * build — runs `astro build`, produces /app/dist
# * prod — Caddy serves the static dist on port 80, plus a /health probe
#
# Pick the stage at compose-build time via APP_ENV={dev,prod} in .env.
# ── base: shared dependency install ──────────────────────────────
FROM node:lts-slim AS base
WORKDIR /app
ENV ASTRO_TELEMETRY_DISABLED=1
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
# ── dev: Astro dev server with HMR ──────────────────────────────
FROM base AS dev
ENV HOST=0.0.0.0
EXPOSE 4321
CMD ["npx", "astro", "dev", "--host", "0.0.0.0", "--port", "4321"]
# ── build: static site generation ───────────────────────────────
FROM base AS build
RUN npx astro build
# ── prod: Caddy serving static files ────────────────────────────
FROM caddy:2-alpine AS prod
COPY Caddyfile /etc/caddy/Caddyfile
COPY --from=build /app/dist /srv
EXPOSE 80
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget -qO- http://127.0.0.1:80/health || exit 1