Remote uses: @v1 never scheduled jobs; keep thin callers against local workflow_call copies until collaborative owners include Trent.
146 lines
7.5 KiB
Markdown
146 lines
7.5 KiB
Markdown
# Guide 26: VigilCareRecords CI/CD (Gitea Actions + Docker Compose)
|
||
|
||
How VigilCareRecords is built, tested, and deployed on the shared Gitea Actions
|
||
platform. Platform rules and onboarding live in [`docs/CICD/`](CICD/README.md) —
|
||
especially [`onboarding-a-project.md`](CICD/onboarding-a-project.md). This guide
|
||
only covers what is specific to this repo.
|
||
|
||
Related files:
|
||
|
||
- [`.gitea/workflows/ci.yml`](../.gitea/workflows/ci.yml) / [`.gitea/workflows/cd.yml`](../.gitea/workflows/cd.yml)
|
||
- [`docker-bake.hcl`](../docker-bake.hcl) / [`scripts/cap-buildx-builder.sh`](../scripts/cap-buildx-builder.sh)
|
||
- [`docker-compose.yml`](../docker-compose.yml) (local dependencies only)
|
||
- [`docker-compose.prod.yml`](../docker-compose.prod.yml) (production app stack)
|
||
- [`.env.example`](../.env.example)
|
||
- [`VigilCareRecordsAPI/Dockerfile`](../VigilCareRecordsAPI/Dockerfile) / [`vigilcare-records-web/Dockerfile`](../vigilcare-records-web/Dockerfile)
|
||
|
||
---
|
||
|
||
## 1. Topology
|
||
|
||
VigilCareRecords ships two images:
|
||
|
||
| Image | Dockerfile | Build context |
|
||
|---|---|---|
|
||
| `vigilcare-records-api` | `VigilCareRecordsAPI/Dockerfile` | repo root |
|
||
| `vigilcare-records-dashboard` | `vigilcare-records-web/Dockerfile` | `vigilcare-records-web/` |
|
||
|
||
Unlike VigilCareClinical, there is no gateway service, and the frontend does not bake in an absolute API URL at build time — `src/api/client.ts` and `src/api/fhirClient.ts` use relative base URLs (`/api/v1`, `/fhir`). The dashboard's `nginx.conf` reverse-proxies those paths to the `api` container, so the same image works behind any hostname without a build-arg.
|
||
|
||
---
|
||
|
||
## 2. CI
|
||
|
||
CI is a **thin caller** of local reusable workflows
|
||
(`.gitea/workflows/dotnet8-ci.yml`, `.gitea/workflows/node-ci.yml`). Those files
|
||
are vendored from the shared `infra/ci-workflows` kit because this repo’s owner
|
||
is not yet listed under that repo’s Actions **collaborative owners** — remote
|
||
`uses: infra/ci-workflows/...@v1` fails in 0s with no runner/steps. Switch the
|
||
caller back to `@v1` once access is granted.
|
||
|
||
| Job | Workflow |
|
||
| --- | --- |
|
||
| `backend` | `dotnet8-ci.yml` — Postgres/Redis as `services:`, reached by DNS (`Host=postgres`, `redis:6379`) |
|
||
| `frontend` | `node-ci.yml` — typecheck → unit tests → `vite build` |
|
||
|
||
A local `changes` job path-filters so a frontend-only push does not start Postgres.
|
||
`workflow_dispatch` forces both stacks.
|
||
|
||
`ApiFixture` reads `CONNECTIONSTRINGS__DEFAULTCONNECTION` / `REDIS__CONNECTIONSTRING`;
|
||
the caller maps those in `test_env` to the service containers. MinIO is not started
|
||
in CI (tests do not drive object storage). Local deps still come from
|
||
`docker compose up -d postgres redis minio`.
|
||
|
||
---
|
||
|
||
## 3. Shared production infrastructure
|
||
|
||
Per the "Integrated Database Deployment" decision documented in [`vigilcare-records-clinical-overview.md`](vigilcare-records-clinical-overview.md), VigilCareRecords does **not** run its own Postgres/Redis/MinIO/Seq in production. It joins the external `shared-services` Docker network already created by VigilCareClinical's own compose project and connects to those same containers, using:
|
||
|
||
- Its own logical Postgres database (`vigilcare_records`, separate schema/tables from VigilCareClinical's `patients`/`encounters`/`observations` — see the promotion service for how the two connect at the application layer, not the infrastructure layer)
|
||
- A dedicated Redis logical database (`defaultDatabase=2` in `.env.example`) so batch-assignment locks never collide with VigilCareClinical's keys
|
||
- A dedicated MinIO bucket (`vigilcare-records-scans`) separate from any clinical document buckets
|
||
|
||
**Before the first deploy**, confirm the VigilCareClinical infra stack (or whatever compose project owns `shared-services`) is already running on the deploy host — `docker network ls | grep shared-services` should show it. `docker compose -f docker-compose.prod.yml up` will fail to find the network otherwise.
|
||
|
||
---
|
||
|
||
## 4. One-time host setup
|
||
|
||
```bash
|
||
ssh deploy@YOUR_HOST "mkdir -p /opt/vigilcare-records"
|
||
scp .env deploy@YOUR_HOST:/opt/vigilcare-records/.env
|
||
ssh deploy@YOUR_HOST "chmod 600 /opt/vigilcare-records/.env"
|
||
```
|
||
|
||
Fill in `.env` from [`.env.example`](../.env.example) first — generate `JWT_SECRET` with `openssl rand -base64 48`, and get real credentials for the shared Postgres/Redis/MinIO/Seq services from whoever manages that stack. CD never uploads or overwrites `.env`; only the `IMAGE_TAG` line is patched automatically on each release.
|
||
|
||
`PG_CONNECTION` / `PG_CONNECTION_DDL` must be Npgsql `key=value` form (not a URI) and must **not** be wrapped in quotes.
|
||
|
||
Create the Records MinIO bucket once (the API also creates it on startup if missing):
|
||
|
||
```bash
|
||
ssh deploy@YOUR_HOST bash -euo pipefail <<'EOF'
|
||
cd /opt/vigilcare-records
|
||
env_val() { sed -n "s/^${1}=//p" .env | tail -n1 | tr -d '\r'; }
|
||
ACCESS="$(env_val MINIO_ACCESS_KEY)"
|
||
SECRET="$(env_val MINIO_SECRET_KEY)"
|
||
BUCKET="$(env_val MINIO_BUCKET_NAME)"; BUCKET="${BUCKET:-vigilcare-records-scans}"
|
||
docker run --rm --network shared-services --entrypoint /bin/sh minio/mc \
|
||
-c "mc alias set local http://minio:9000 '${ACCESS}' '${SECRET}' && mc mb --ignore-existing local/${BUCKET}"
|
||
EOF
|
||
```
|
||
|
||
---
|
||
|
||
## 5. Gitea secrets and variables
|
||
|
||
Repo → **Settings** → **Actions**.
|
||
|
||
### Secrets
|
||
|
||
| Secret | Used by |
|
||
|---|---|
|
||
| `REGISTRY_USERNAME` | `docker login` (runner + deploy host) |
|
||
| `REGISTRY_TOKEN` | `docker login` (PAT with package write — not `GITEA_TOKEN`) |
|
||
| `PG_CONNECTION_DDL` | migrate job only — DDL-privileged connection (`Host=postgres` on `shared-services`), never given to the API container |
|
||
| `DEPLOY_HOST` | SSH / SCP |
|
||
| `DEPLOY_USER` | SSH / SCP |
|
||
| `DEPLOY_SSH_KEY` | Private key PEM / OpenSSH private key body |
|
||
|
||
### Variables
|
||
|
||
| Variable | Used by |
|
||
|---|---|
|
||
| `REGISTRY` | Optional override of the default `git.vectur45.com/trent/vigilcare-records` |
|
||
| `MIGRATE_DOCKER_NETWORK` | Optional; defaults to `shared-services` |
|
||
|
||
---
|
||
|
||
## 6. Release flow (CD)
|
||
|
||
```bash
|
||
# CI green on master, then:
|
||
git tag v1.0.0
|
||
git push origin v1.0.0
|
||
```
|
||
|
||
`.gitea/workflows/cd.yml`:
|
||
|
||
1. Cap BuildKit (`scripts/cap-buildx-builder.sh`) and bake **one target at a time** (`api` → `ui` → `migrate`) via `docker-bake.hcl`
|
||
2. Upload the scratch `migrate-bundle` binary as an artifact (`@v4`)
|
||
3. Migrate job downloads the artifact, SCPs it to the deploy host, runs it on `shared-services` with `PG_CONNECTION_DDL`
|
||
4. Deploy: `docker login` on the host, `scp` compose, patch `IMAGE_TAG`, `pull` + `up -d`
|
||
5. Smoke: `/health/ready` and dashboard `/`
|
||
6. On failure: restore previous `IMAGE_TAG` (schema is **not** reverted — expand-then-contract migrations only)
|
||
|
||
Manual redeploy: Gitea UI → Actions → CD → Run workflow, with `image_tag` input.
|
||
|
||
---
|
||
|
||
## 7. Pre-production checklist (application-level, not part of this CI/CD change)
|
||
|
||
- **Demo data seeding runs unconditionally on startup.** `Program.cs` calls `DataSeeder.SeedAsync(db)` whenever `ASPNETCORE_ENVIRONMENT` is not `Testing` — including `Production`. Unlike the VigilCareClinical example (`Seeding__EnableDemoData=false`), this app has no seeding toggle. Before a real clinical deploy, either add a guard around `DataSeeder.SeedAsync` for `Production`, or confirm the twelve seeded demo accounts (all password `password`) are acceptable/rotated before go-live.
|
||
- Confirm `Cors:AllowedOrigins` / `DASHBOARD_ORIGIN` matches the real public dashboard origin if the dashboard is ever served from a different origin than the API (not the default same-origin nginx-proxy setup described above).
|
||
- Rotate `JWT_SECRET` from any value used during testing before the first real deploy.
|