feat(docker-watcher): phase 8 - REST API layer
All REST endpoints wired with chi router: projects, stages, instances, deploys, registries, settings, quick deploy, webhook. Full main.go wiring with graceful shutdown. Consistent JSON envelope responses. Sensitive fields stripped from API responses.
This commit is contained in:
@@ -30,7 +30,7 @@ A self-hosted tool that automates Docker container deployment with Nginx Proxy M
|
||||
- [x] Phase 5: Registry Client & Poller [domain: backend] → [subplan](./phase-5-registry-poller.md)
|
||||
- [x] Phase 6: Webhook Handler [domain: backend] → [subplan](./phase-6-webhook-handler.md)
|
||||
- [x] Phase 7: Deployer & Health Checker [domain: backend] → [subplan](./phase-7-deployer.md)
|
||||
- [ ] Phase 8: REST API Layer [domain: backend] → [subplan](./phase-8-api-layer.md)
|
||||
- [x] Phase 8: REST API Layer [domain: backend] → [subplan](./phase-8-api-layer.md)
|
||||
- [ ] Phase 9: SvelteKit Dashboard & Project Views [domain: frontend] → [subplan](./phase-9-dashboard.md)
|
||||
- [ ] Phase 10: Quick Deploy & Settings Pages [domain: frontend] → [subplan](./phase-10-settings-deploy.md)
|
||||
- [ ] Phase 11: Frontend Embed & Real-Time Updates [domain: fullstack] → [subplan](./phase-11-embed-sse.md)
|
||||
@@ -53,7 +53,7 @@ A self-hosted tool that automates Docker container deployment with Nginx Proxy M
|
||||
| Phase 5: Registry & Poller | backend | ✅ Complete | ✅ Pass w/ fixes | ⏭️ Skip (Big Bang) | ✅ |
|
||||
| Phase 6: Webhook Handler | backend | ✅ Complete | ✅ Pass w/ fixes | ⏭️ Skip (Big Bang) | ✅ |
|
||||
| Phase 7: Deployer & Health | backend | ✅ Complete | ✅ Pass w/ fixes | ⏭️ Skip (Big Bang) | ✅ |
|
||||
| Phase 8: API Layer | backend | ⬜ Not Started | ⬜ | ⏭️ Skip (Big Bang) | ⬜ |
|
||||
| Phase 8: API Layer | backend | ✅ Complete | ⬜ Pending | ⏭️ Skip (Big Bang) | ⬜ |
|
||||
| Phase 9: Dashboard | frontend | ⬜ Not Started | ⬜ | ⏭️ Skip (Big Bang) | ⬜ |
|
||||
| Phase 10: Settings & Deploy | frontend | ⬜ Not Started | ⬜ | ⏭️ Skip (Big Bang) | ⬜ |
|
||||
| Phase 11: Embed & SSE | fullstack | ⬜ Not Started | ⬜ | ⏭️ Skip (Big Bang) | ⬜ |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Phase 8: REST API Layer
|
||||
|
||||
**Status:** ⬜ Not Started
|
||||
**Status:** ✅ Complete
|
||||
**Parent plan:** [PLAN.md](./PLAN.md)
|
||||
**Domain:** backend
|
||||
|
||||
@@ -9,18 +9,18 @@ Wire up all REST API endpoints using chi router, connecting the store, deployer,
|
||||
|
||||
## Tasks
|
||||
|
||||
- [ ] Task 1: Set up chi router with middleware (logging, recovery, CORS, JSON content-type)
|
||||
- [ ] Task 2: Implement project endpoints — GET/POST /api/projects, GET/PUT/DELETE /api/projects/:id
|
||||
- [ ] Task 3: Implement stage endpoints — POST /api/projects/:id/stages, PUT/DELETE /api/projects/:id/stages/:stage
|
||||
- [ ] Task 4: Implement instance endpoints — GET /api/projects/:id/stages/:stage/instances, POST (deploy), DELETE (remove)
|
||||
- [ ] Task 5: Implement instance control endpoints — POST .../instances/:iid/stop, start, restart
|
||||
- [ ] Task 6: Implement quick deploy endpoints — POST /api/deploy/inspect, POST /api/deploy/quick
|
||||
- [ ] Task 7: Implement registry endpoints — GET/POST /api/registries, PUT/DELETE /api/registries/:id, POST .../test
|
||||
- [ ] Task 8: Implement settings endpoints — GET/PUT /api/settings, GET /api/settings/webhook-url, POST .../regenerate
|
||||
- [ ] Task 9: Implement deploy history endpoints — GET /api/deploys, GET /api/deploys/:id/logs (SSE stub)
|
||||
- [ ] Task 10: Implement registry tags endpoint — GET /api/registries/:id/tags/:image
|
||||
- [ ] Task 11: Wire webhook handler into router — POST /api/webhook/:secret-uuid
|
||||
- [ ] Task 12: Wire everything in main.go — initialize all services, start HTTP server
|
||||
- [x] Task 1: Set up chi router with middleware (logging, recovery, CORS, JSON content-type)
|
||||
- [x] Task 2: Implement project endpoints — GET/POST /api/projects, GET/PUT/DELETE /api/projects/:id
|
||||
- [x] Task 3: Implement stage endpoints — POST /api/projects/:id/stages, PUT/DELETE /api/projects/:id/stages/:stage
|
||||
- [x] Task 4: Implement instance endpoints — GET /api/projects/:id/stages/:stage/instances, POST (deploy), DELETE (remove)
|
||||
- [x] Task 5: Implement instance control endpoints — POST .../instances/:iid/stop, start, restart
|
||||
- [x] Task 6: Implement quick deploy endpoints — POST /api/deploy/inspect, POST /api/deploy/quick
|
||||
- [x] Task 7: Implement registry endpoints — GET/POST /api/registries, PUT/DELETE /api/registries/:id, POST .../test
|
||||
- [x] Task 8: Implement settings endpoints — GET/PUT /api/settings, GET /api/settings/webhook-url, POST .../regenerate
|
||||
- [x] Task 9: Implement deploy history endpoints — GET /api/deploys, GET /api/deploys/:id/logs (SSE stub)
|
||||
- [x] Task 10: Implement registry tags endpoint — GET /api/registries/:id/tags/:image
|
||||
- [x] Task 11: Wire webhook handler into router — POST /api/webhook/:secret-uuid
|
||||
- [x] Task 12: Wire everything in main.go — initialize all services, start HTTP server
|
||||
|
||||
## Files to Modify/Create
|
||||
- `internal/api/router.go` — chi router setup, middleware
|
||||
@@ -49,11 +49,64 @@ Wire up all REST API endpoints using chi router, connecting the store, deployer,
|
||||
- All handlers should validate input and return 400 for bad requests
|
||||
|
||||
## Review Checklist
|
||||
- [ ] All tasks completed
|
||||
- [ ] All API endpoints from PLAN.md are covered
|
||||
- [ ] Consistent response format across all endpoints
|
||||
- [ ] Input validation on all POST/PUT handlers
|
||||
- [ ] No business logic in handlers (delegates to services)
|
||||
- [x] All tasks completed
|
||||
- [x] All API endpoints from PLAN.md are covered
|
||||
- [x] Consistent response format across all endpoints
|
||||
- [x] Input validation on all POST/PUT handlers
|
||||
- [x] No business logic in handlers (delegates to services)
|
||||
|
||||
## Handoff to Next Phase
|
||||
<!-- Filled in by the implementation agent after completing this phase. -->
|
||||
|
||||
### API Surface
|
||||
- `api.NewServer(store, docker, deployer, webhookHandler, encKey)` creates the server
|
||||
- `server.Router()` returns a `chi.Router` with all routes mounted under `/api`
|
||||
- Response envelope: `{"success": bool, "data": ..., "error": "..."}`
|
||||
|
||||
### Endpoints Implemented
|
||||
| Method | Path | Handler |
|
||||
|--------|------|---------|
|
||||
| GET | /api/projects | listProjects |
|
||||
| POST | /api/projects | createProject |
|
||||
| GET | /api/projects/{id} | getProject (includes stages) |
|
||||
| PUT | /api/projects/{id} | updateProject |
|
||||
| DELETE | /api/projects/{id} | deleteProject |
|
||||
| POST | /api/projects/{id}/stages | createStage |
|
||||
| PUT | /api/projects/{id}/stages/{stage} | updateStage |
|
||||
| DELETE | /api/projects/{id}/stages/{stage} | deleteStage |
|
||||
| GET | /api/projects/{id}/stages/{stage}/instances | listInstances |
|
||||
| POST | /api/projects/{id}/stages/{stage}/instances | deployInstance |
|
||||
| DELETE | /api/projects/{id}/stages/{stage}/instances/{iid} | removeInstance |
|
||||
| POST | .../instances/{iid}/stop | stopInstance |
|
||||
| POST | .../instances/{iid}/start | startInstance |
|
||||
| POST | .../instances/{iid}/restart | restartInstance |
|
||||
| GET | /api/deploys | listDeploys |
|
||||
| GET | /api/deploys/{id}/logs | getDeployLogs (JSON stub) |
|
||||
| POST | /api/deploy/inspect | inspectImage |
|
||||
| POST | /api/deploy/quick | quickDeploy |
|
||||
| GET | /api/registries | listRegistries |
|
||||
| POST | /api/registries | createRegistry |
|
||||
| PUT | /api/registries/{id} | updateRegistry |
|
||||
| DELETE | /api/registries/{id} | deleteRegistry |
|
||||
| POST | /api/registries/{id}/test | testRegistry |
|
||||
| GET | /api/registries/{id}/tags/* | listRegistryTags |
|
||||
| GET | /api/settings | getSettings |
|
||||
| PUT | /api/settings | updateSettings |
|
||||
| GET | /api/settings/webhook-url | getWebhookURL |
|
||||
| POST | /api/settings/regenerate | regenerateWebhookSecret |
|
||||
| POST | /api/webhook/{secret} | webhook handler (mounted from webhook package) |
|
||||
|
||||
### main.go Wiring
|
||||
- All services initialized: store, docker, npm, deployer, health, notifier, webhook, poller
|
||||
- HTTP server with graceful shutdown on SIGTERM/SIGINT
|
||||
- Environment variables: `DATA_DIR`, `SEED_FILE`, `ENCRYPTION_KEY`, `NPM_URL`, `POLLING_INTERVAL`, `LISTEN_ADDR`
|
||||
- Default listen address: `:8080`
|
||||
|
||||
### SSE Stub
|
||||
- `GET /api/deploys/{id}/logs` returns logs as JSON array (not SSE yet)
|
||||
- Real SSE streaming deferred to Phase 11
|
||||
|
||||
### Security Notes
|
||||
- Registry tokens are encrypted before storage, decrypted on read for API calls
|
||||
- Settings response strips `npm_password` and `webhook_secret`, returns `has_npm_password` boolean
|
||||
- Registry list response strips tokens, returns `has_token` boolean
|
||||
- CORS allows all origins (dev mode) -- restrict in Phase 12
|
||||
|
||||
Reference in New Issue
Block a user