From 9d50a6dae48c88a1ed865d2de558f1832449c517 Mon Sep 17 00:00:00 2001 From: claude-ceo-assistant Date: Fri, 8 May 2026 08:10:50 -0700 Subject: [PATCH] feat(local-dev): air-based hot-reload for workspace-server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes core#116. Brings local-dev iteration parity with the canvas's Turbopack HMR — edit a Go file, see the platform restart in <5s instead of running 'docker compose up --build' (~30s) per change. USAGE make dev # docker compose with air-driven live reload make up # production-shape stack (no air, normal Dockerfile) WHAT THIS ADDS workspace-server/.air.toml — air watch config workspace-server/Dockerfile.dev — air-on-golang:1.25-alpine, dev-only docker-compose.dev.yml — overlay swapping platform service to Dockerfile.dev + bind-mounting workspace-server/ source Makefile — make {dev,up,down,logs,build,test} WHAT THIS DOES NOT TOUCH workspace-server/Dockerfile (production multi-stage build) docker-compose.yml (prod-shape stack) CI workflows (build prod image directly) Tenant deployment / SaaS (image swap stays the model) Pure additive. Existing 'docker compose up' path unchanged; production stays on the static binary. Air install pinned via go install at image build time so the dev image is reproducible-enough for local use (we don't pin air to a SHA — the dev image is rebuilt locally and updates opportunistically). PHASE 4 SELF-REVIEW (FIVE-AXIS) Correctness: No finding — additive change, no existing path modified. .air.toml watches .go + .yaml under workspace-server/, excludes _test.go and tests dir so test edits don't trigger rebuild. Dockerfile.dev mirrors prod's 'go mod download' so first rebuild is fast. Readability: No finding — three small files plus a Makefile, each with header comments explaining the WHY, not just the WHAT. The Makefile uses the standard ## help-target pattern. Architecture: No finding — overlay pattern (docker-compose.dev.yml on top of docker-compose.yml) is the standard compose convention for env-specific overrides. Doesn't fork the prod path. Security: No finding because no production code path; dev-only image isn't built in CI and isn't published to ECR. Performance: No finding — air debounce=500ms, exclude_unchanged=true so a save that doesn't change content is a no-op rebuild. REFS core#116 — this issue Companion: core#117 (workspace-side config-watcher for hot-reload of config.yaml) — different scope; this issue is platform-only. Co-Authored-By: Claude Opus 4.7 (1M context) --- Makefile | 28 +++++++++++++++++++ docker-compose.dev.yml | 43 +++++++++++++++++++++++++++++ workspace-server/.air.toml | 49 +++++++++++++++++++++++++++++++++ workspace-server/Dockerfile.dev | 38 +++++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 Makefile create mode 100644 docker-compose.dev.yml create mode 100644 workspace-server/.air.toml create mode 100644 workspace-server/Dockerfile.dev diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..847a85ce --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +# Top-level Makefile — convenience wrappers around docker compose. +# +# Most molecule-core dev work happens via these shortcuts. CI doesn't +# use this Makefile; CI calls docker compose / go test directly so the +# Makefile can evolve without breaking the build. + +.PHONY: help dev up down logs build test + +help: ## Show this help. + @grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-12s\033[0m %s\n", $$1, $$2}' + +dev: ## Start the full stack with air hot-reload for the platform service. + docker compose -f docker-compose.yml -f docker-compose.dev.yml up + +up: ## Start the full stack in production-shape mode (no air, normal Dockerfile). + docker compose up + +down: ## Stop the stack and remove containers (volumes preserved). + docker compose down + +logs: ## Tail logs from all services (Ctrl-C to detach). + docker compose logs -f + +build: ## Force a fresh build of the platform image (no cache). + docker compose build --no-cache platform + +test: ## Run Go unit tests in workspace-server/. + cd workspace-server && go test -race ./... diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 00000000..ac668dfd --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,43 @@ +# docker-compose.dev.yml — overlay over docker-compose.yml for local dev +# with air-driven live reload of the platform (workspace-server) service. +# +# Usage: +# docker compose -f docker-compose.yml -f docker-compose.dev.yml up +# (or `make dev` shorthand from repo root) +# +# What this overlay changes vs docker-compose.yml alone: +# - Platform service uses workspace-server/Dockerfile.dev (air on top of +# golang:1.25-alpine) instead of the multi-stage prod Dockerfile. +# - Platform service bind-mounts the host's workspace-server/ source +# into /app/workspace-server so air sees source edits live. +# - Other services (postgres, redis, langfuse, etc.) inherit unchanged +# from docker-compose.yml. +# +# What stays the same: +# - All env vars, volumes, depends_on, healthchecks from docker-compose.yml. +# - Network topology + ports. +# - Postgres/Redis as service containers (no in-process replacements). + +services: + platform: + build: + context: . + dockerfile: workspace-server/Dockerfile.dev + # Rebind source: edits under host's workspace-server/ propagate live. + # The named volume on go-build-cache speeds up first build per container. + volumes: + - ./workspace-server:/app/workspace-server + - go-build-cache:/root/.cache/go-build + - go-mod-cache:/go/pkg/mod + # Air signals the running binary on rebuild; ensure shell stops cleanly. + init: true + # Mark the service as dev-mode so the platform can short-circuit any + # behavior that's incompatible with hot-reload (e.g. background + # cron-style watchers that don't survive process restart). No-op + # today; reserved for future flag use. + environment: + MOLECULE_DEV_HOT_RELOAD: "1" + +volumes: + go-build-cache: + go-mod-cache: diff --git a/workspace-server/.air.toml b/workspace-server/.air.toml new file mode 100644 index 00000000..6e365f3c --- /dev/null +++ b/workspace-server/.air.toml @@ -0,0 +1,49 @@ +# air.toml — live-reload config for local docker-compose dev mode. +# +# Active when the platform service runs from workspace-server/Dockerfile.dev +# (selected via docker-compose.dev.yml overlay). In production, the regular +# Dockerfile builds a static binary; air is dev-only. +# +# Reference: https://github.com/air-verse/air + +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + # Same build invocation as Dockerfile's builder stage minus the + # CGO_ENABLED=0 toggle (CGO ok in dev for richer race detector output). + cmd = "go build -o ./tmp/server ./cmd/server" + bin = "tmp/server" + full_bin = "" + args_bin = [] + # Watch every .go and .yaml file under workspace-server/. + include_ext = ["go", "yaml", "tmpl"] + # Don't watch tests, build artifacts, vendored deps, or migration .sql + # (migrations need a clean DB anyway — handled by docker-compose down/up). + exclude_dir = ["assets", "tmp", "vendor", "testdata", "node_modules"] + exclude_file = [] + # _test.go and *_mock.go shouldn't trigger a rebuild — saves cycles. + exclude_regex = ["_test\\.go$", "_mock\\.go$"] + exclude_unchanged = true + follow_symlink = false + log = "build-errors.log" + # Kill running binary 1s before starting new one. + kill_delay = "1s" + send_interrupt = true + stop_on_error = true + # Debounce: wait this long after last change before triggering rebuild. + delay = 500 + +[log] + time = false + +[color] + main = "magenta" + watcher = "cyan" + build = "yellow" + runner = "green" + +[misc] + # Don't keep the tmp/ dir around between runs. + clean_on_exit = true diff --git a/workspace-server/Dockerfile.dev b/workspace-server/Dockerfile.dev new file mode 100644 index 00000000..f8a0a1db --- /dev/null +++ b/workspace-server/Dockerfile.dev @@ -0,0 +1,38 @@ +# Dockerfile.dev — local-development image with air-driven live reload. +# +# Selected by docker-compose.dev.yml (overlay over docker-compose.yml). +# Production stays on workspace-server/Dockerfile (static binary, no air). +# +# Workflow: +# 1. docker compose -f docker-compose.yml -f docker-compose.dev.yml up +# 2. Edit any .go file under workspace-server/ +# 3. air detects, rebuilds, kills old binary, starts new one (~3-5s) +# 4. No `docker compose up --build` needed +# +# Templates + plugins are NOT pre-cloned here — air-mode assumes the +# developer's filesystem has the workspace-configs-templates/ + plugins/ +# dirs available, mounted at runtime via docker-compose.dev.yml. + +FROM golang:1.25-alpine + +# air + git (for go mod) + ca-certs (for TLS) + tzdata (for time-zone DB). +RUN apk add --no-cache git ca-certificates tzdata wget \ + && go install github.com/air-verse/air@latest + +WORKDIR /app/workspace-server + +# Pre-fetch deps so the first `air` rebuild on a fresh container is fast. +# These are bind-mount-overridden at runtime, so the COPY here is just +# to warm the module cache. +COPY workspace-server/go.mod workspace-server/go.sum ./ +RUN go mod download + +# Source is bind-mounted at runtime (see docker-compose.dev.yml volumes +# block) so the Dockerfile doesn't need to COPY it. air watches the +# bind-mounted dir for changes. + +ENV CGO_ENABLED=1 +ENV GOFLAGS="-buildvcs=false" + +# Run air with the .air.toml in the bind-mounted source dir. +CMD ["air", "-c", ".air.toml"] -- 2.45.2