2.5 KiB
2.5 KiB
Step 07: Server Mode and HTTP API
Prerequisites: steps 04, 05, 06.
Read README.md and 00-legacy-analysis.md first.
Goal
Implement the server subcommand: a persistent web server exposing build state as JSON and serving artifacts.
Design
Bootstrapping:
CLAUDE.mdnotes the context starts with web typenone; theserversubcommand must run a web context. Preferred approach:ServerCommandlaunches a secondSpringApplicationwithWebApplicationType.SERVLETand aserverprofile, then blocks until shutdown. Document the chosen mechanism in the code and, if it deviates, in an ADR.- Add
spring-boot-starter-webdependency. - The watcher (step 06) is active only in the
serverprofile. - New config keys
server.portandserver.bindAddress(defaults 18080 / 0.0.0.0, as legacy).
JSON API (package de.hoennig.gittally.server), replacing the legacy /control/* endpoints:
GET /api/builds/latest— latest build per branch.GET /api/builds/history— all builds, newest first.GET /api/builds/current— the list of running builds (there can be several, one per branch, up tobuilds.maxConcurrent), each with live status and log tail (?offset=for incremental log fetch, addressed by artifact key).GET /api/status/{commit}— effective status including Gitea lookup (replaces/control/status); must return an explicit error state on Gitea failure, never hang.POST /api/builds/{branch}/restart,POST /api/builds/{artifactKey}/cancel(cancel takes the artifact key because multiple builds can run concurrently),DELETE /api/builds/{artifactKey}— guarded by a simple token like the legacy cancel token; wire into executor/watcher/repository.GET /api/watcher— watcher health (last poll, last error).- Artifact serving:
GET /artifacts/{artifactKey}/**streaming from the artifact store, with no-cache headers for html/json/log.
Out of Scope
- HTML pages (step 08); JSON plus artifact files only.
- TLS/reverse proxy (documented in step 12).
Tests
@WebMvcTestslices with@MockkBeanper controller (seeCLAUDE.mdconventions).- Contract tests: JSON shapes, error states (Gitea down → explicit
unknownstatus, HTTP 200), cancel token rejection. - One
@SpringBootTeston the server profile proving the context boots with watcher and web enabled.
Acceptance Criteria
./gradlew ktlintFormatthen./gradlew buildis green.java -jar ... serverstarts,GET /api/builds/latestanswers, Ctrl-C shuts down cleanly (manual smoke test; document result in this file).