Align CI/CD with shared infra/ci-workflows and drop compose-based CI.
CI / changes (push) Successful in 1m4s
CI / backend (push) Failing after 0s
CI / frontend (push) Failing after 0s

Replace hand-rolled jobs with @v1 callers, capped bake/migrate CD, and remove the docker-compose.ci.yml bridge workaround.
This commit is contained in:
2026-10-06 19:10:58 +08:00
parent 1124c1f079
commit 5a175e3fba
12 changed files with 397 additions and 197 deletions
+3 -2
View File
@@ -18,13 +18,14 @@ DASHBOARD_ORIGIN=https://vigilcare-records.vectur45.com
# Docker network already created by VigilCareClinical's own compose project; that
# stack MUST be up before the first `docker compose -f docker-compose.prod.yml up`.
# Runtime (DML-only) connection used by the API container.
PG_CONNECTION="Host=postgres;Port=5432;Database=vigilcare_records;Username=vigilcare_records_app;Password=CHANGE_ME;SSL Mode=Disable"
# Npgsql key=value form only — never a URI, and do not wrap in quotes (quotes break readiness).
PG_CONNECTION=Host=postgres;Port=5432;Database=vigilcare_records;Username=vigilcare_records_app;Password=CHANGE_ME;SSL Mode=Disable
# DDL-privileged connection used ONLY by the EF migration bundle (CD migrate job).
# CD copies migrate-api to the deploy host and runs it in a one-shot container on
# shared-services, so use the same Docker DNS name as PG_CONNECTION (Host=postgres),
# not an external hostname. Store this as Gitea secret PG_CONNECTION_DDL.
# Never put this credential in the API container environment.
PG_CONNECTION_DDL="Host=postgres;Port=5432;Database=vigilcare_records;Username=vigilcare_records_migrator;Password=CHANGE_ME;SSL Mode=Disable"
PG_CONNECTION_DDL=Host=postgres;Port=5432;Database=vigilcare_records;Username=vigilcare_records_migrator;Password=CHANGE_ME;SSL Mode=Disable
# ---- Redis (shared-services network) ----
# "redis" = the service name on the shared Redis compose project.
+121 -52
View File
@@ -1,9 +1,13 @@
# Build images, migrate, deploy on version tags.
# Requires act_runner with docker, curl, ssh, scp, bash and label ubuntu-latest.
# Build images (capped bake), migrate, deploy on version tags.
# Copy of docs/CICD/templates/workflows/cd.yml adapted for this repo's paths.
#
# ubuntu-latest is a registered runner label, not a GitHub-hosted VM.
# Requires Docker-mode runner (host docker socket), curl, ssh, scp, bash.
# GITEA_TOKEN cannot push images — REGISTRY_TOKEN must be a PAT.
#
# Secrets: REGISTRY_USERNAME, REGISTRY_TOKEN, PG_CONNECTION_DDL,
# DEPLOY_HOST, DEPLOY_USER, DEPLOY_SSH_KEY
# Variables: REGISTRY (optional; defaults below)
# Variables: REGISTRY (optional), MIGRATE_DOCKER_NETWORK (default shared-services)
name: CD
on:
@@ -47,47 +51,53 @@ jobs:
| docker login "${REGISTRY%%/*}" \
-u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
- name: Build and push vigilcare-records-api
- name: Bake and push images
env:
TAG: ${{ steps.meta.outputs.tag }}
run: |
docker build -f VigilCareRecordsAPI/Dockerfile \
-t "${REGISTRY}/vigilcare-records-api:${{ steps.meta.outputs.tag }}" \
-t "${REGISTRY}/vigilcare-records-api:latest" .
docker push "${REGISTRY}/vigilcare-records-api:${{ steps.meta.outputs.tag }}"
docker push "${REGISTRY}/vigilcare-records-api:latest"
# Cap buildkitd cgroup, then bake one target at a time —
# BUILDKIT_STEP_MAX_PARALLELISM=1 alone does not leave Gitea a core.
bash scripts/cap-buildx-builder.sh vigilcare-records-builder
bake_one() {
local target="$1"
shift
echo "=== bake ${target} ==="
BUILDX_NO_DEFAULT_ATTESTATIONS=1 docker buildx bake \
--progress=plain \
"$target" \
"$@" \
-f docker-bake.hcl
}
bake_one api --push --set api.output=type=image,push=true
sleep 8
bake_one ui --push --set ui.output=type=image,push=true
sleep 8
bake_one migrate --set migrate.output=type=docker
# scratch migrate-bundle needs an explicit command (or image CMD).
cid=$(docker create vigilcare-records-migrate-bundle:local /out/migrate-api)
docker cp "$cid:/out/migrate-api" ./migrate-api
docker rm "$cid"
chmod +x ./migrate-api
- name: Build and push vigilcare-records-dashboard
# Context is vigilcare-records-web/ — package.json and nginx.conf live there.
run: |
docker build -f vigilcare-records-web/Dockerfile \
-t "${REGISTRY}/vigilcare-records-dashboard:${{ steps.meta.outputs.tag }}" \
-t "${REGISTRY}/vigilcare-records-dashboard:latest" vigilcare-records-web
docker push "${REGISTRY}/vigilcare-records-dashboard:${{ steps.meta.outputs.tag }}"
docker push "${REGISTRY}/vigilcare-records-dashboard:latest"
- name: Upload migration bundle
uses: actions/upload-artifact@v4
with:
name: migrate-api
path: migrate-api
if-no-files-found: error
migrate:
needs: build-and-push
runs-on: ubuntu-latest
# Checkout must run on the job host. Build the EF bundle via Dockerfile
# --target migrate (context upload), not docker run -v — under act_runner
# bind mounts resolve on the Docker host, not the job workspace.
# Postgres lives on the deploy host's shared-services network and is not
# reachable from act_runner, so the bundle is copied there and executed in
# a one-shot container joined to that network (Host=postgres resolves).
# NOTE: AppBootstrapHostedService also runs db.Database.MigrateAsync() after
# Kestrel listens, so this job is a defense-in-depth pre-deploy step using a
# DDL-privileged credential the API container never sees, not the only
# migration path.
# Bundle is an artefact from build-and-push — never docker build here.
# Bind mounts resolve on the Docker host, not the job workspace.
# Postgres is on the deploy host; copy the binary there.
steps:
- uses: actions/checkout@v4
- name: Build migration bundle
run: |
docker build -f VigilCareRecordsAPI/Dockerfile --target migrate \
-t vigilcare-records-migrate-bundle:local .
cid=$(docker create vigilcare-records-migrate-bundle:local)
docker cp "$cid:/out/migrate-api" ./migrate-api
docker rm "$cid"
chmod +x ./migrate-api
- name: Download migration bundle
uses: actions/download-artifact@v4
with:
name: migrate-api
path: .
- name: Configure SSH
run: |
@@ -95,34 +105,52 @@ jobs:
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H "${{ secrets.DEPLOY_HOST }}" >> ~/.ssh/known_hosts
chmod +x ./migrate-api
# Runs while the previous release is still serving traffic, so every
# migration must be backwards-compatible with the outgoing image
# (expand-then-contract). Connection strings contain `;` / spaces
# ("SSL Mode=...") — never pass them as a bare ssh remote argv; the
# remote shell splits on `;` and drops the variable (set -u → unbound).
# Expand-then-contract: migrate while the previous release still serves.
# PG_CONNECTION_DDL must be Npgsql key=value form, not a URI. No wrapping quotes.
- name: Apply migrations
env:
PG_CONNECTION_DDL: ${{ secrets.PG_CONNECTION_DDL }}
MIGRATE_DOCKER_NETWORK: ${{ vars.MIGRATE_DOCKER_NETWORK }}
run: |
REMOTE="${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}"
NETWORK="${MIGRATE_DOCKER_NETWORK:-shared-services}"
scp -i ~/.ssh/id_ed25519 ./migrate-api \
"$REMOTE:/tmp/vigilcare-records-migrate-api"
umask 077
printf '%s\n' "$PG_CONNECTION_DDL" > /tmp/vigilcare-records-pg-ddl
printf '%s' "$PG_CONNECTION_DDL" > /tmp/vigilcare-records-pg-ddl
scp -i ~/.ssh/id_ed25519 /tmp/vigilcare-records-pg-ddl \
"$REMOTE:/tmp/vigilcare-records-pg-ddl"
rm -f /tmp/vigilcare-records-pg-ddl
ssh -i ~/.ssh/id_ed25519 "$REMOTE" bash -euo pipefail <<'EOF'
ssh -i ~/.ssh/id_ed25519 "$REMOTE" \
NETWORK="$NETWORK" \
bash -euo pipefail <<'EOF'
chmod +x /tmp/vigilcare-records-migrate-api
chmod 600 /tmp/vigilcare-records-pg-ddl
PG_CONNECTION_DDL="$(cat /tmp/vigilcare-records-pg-ddl)"
PG_CONNECTION_DDL="$(tr -d '\r\n' < /tmp/vigilcare-records-pg-ddl)"
PG_CONNECTION_DDL="${PG_CONNECTION_DDL#\"}"
PG_CONNECTION_DDL="${PG_CONNECTION_DDL%\"}"
PG_CONNECTION_DDL="${PG_CONNECTION_DDL#\'}"
PG_CONNECTION_DDL="${PG_CONNECTION_DDL%\'}"
if [[ "$PG_CONNECTION_DDL" == postgresql://* || "$PG_CONNECTION_DDL" == postgres://* ]]; then
echo "PG_CONNECTION_DDL must be Npgsql key=value form, not a URI." >&2
exit 1
fi
if [[ "$PG_CONNECTION_DDL" != Host=* && "$PG_CONNECTION_DDL" != host=* ]]; then
PG_CONNECTION_DDL="Host=${PG_CONNECTION_DDL}"
fi
printf '%s' "$PG_CONNECTION_DDL" > /tmp/vigilcare-records-pg-ddl
docker run --rm \
--network shared-services \
--network "${NETWORK}" \
-v /tmp/vigilcare-records-migrate-api:/migrate-api:ro \
--entrypoint /migrate-api \
-v /tmp/vigilcare-records-pg-ddl:/run/pg-ddl:ro \
--entrypoint sh \
mcr.microsoft.com/dotnet/runtime-deps:8.0 \
--connection "$PG_CONNECTION_DDL"
-c 'exec /migrate-api --connection "$(tr -d "\r\n" < /run/pg-ddl)"'
rm -f /tmp/vigilcare-records-migrate-api /tmp/vigilcare-records-pg-ddl
EOF
@@ -147,12 +175,43 @@ jobs:
- name: Deploy
env:
IMAGE_TAG: ${{ needs.build-and-push.outputs.tag }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
run: |
if [ -n "${{ vars.REGISTRY }}" ]; then
REGISTRY="${{ vars.REGISTRY }}"
else
REGISTRY="git.vectur45.com/trent/vigilcare-records"
fi
REGISTRY_HOST="${REGISTRY%%/*}"
ssh -i ~/.ssh/id_ed25519 \
"${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
IMAGE_TAG="$IMAGE_TAG" bash -euo pipefail <<'EOF'
IMAGE_TAG="$IMAGE_TAG" \
REGISTRY_HOST="$REGISTRY_HOST" \
REGISTRY_USERNAME="$REGISTRY_USERNAME" \
REGISTRY_TOKEN="$REGISTRY_TOKEN" \
bash -euo pipefail <<'EOF'
cd /opt/vigilcare-records
echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY_HOST}" \
-u "${REGISTRY_USERNAME}" --password-stdin
env_val() { sed -n "s/^${1}=//p" .env | tail -n1 | tr -d '\r'; }
strip_quotes() {
local v="$1"
v="${v#\"}"; v="${v%\"}"; v="${v#\'}"; v="${v%\'}"
printf '%s' "$v"
}
PG_CONNECTION="$(strip_quotes "$(env_val PG_CONNECTION)")"
if [[ -z "$PG_CONNECTION" ]]; then
echo "PG_CONNECTION is empty in /opt/vigilcare-records/.env" >&2
exit 1
fi
if [[ "$PG_CONNECTION" != Host=* && "$PG_CONNECTION" != host=* ]]; then
echo "PG_CONNECTION must start with Host= (Npgsql key=value form)." >&2
exit 1
fi
# Record the currently deployed tag so a rollback has a target.
grep '^IMAGE_TAG=' .env > .env.previous || true
@@ -171,6 +230,7 @@ jobs:
exit 1
fi
docker image prune -f
docker compose -f docker-compose.prod.yml --env-file .env ps -a
EOF
- name: Smoke test
@@ -185,15 +245,24 @@ jobs:
DASHBOARD_PORT="$(env_val DASHBOARD_PORT)"; DASHBOARD_PORT="${DASHBOARD_PORT:-8089}"
for i in $(seq 1 30); do
if curl -fsS "http://localhost:${API_PORT}/health/ready" >/dev/null; then
echo "Ready check passed."
set +e
http_code=$(curl -s -o /dev/null -w '%{http_code}' --connect-timeout 2 \
"http://localhost:${API_PORT}/health/ready" 2>/dev/null)
curl_exit=$?
set -e
if [ "$curl_exit" -ne 0 ] || [ -z "$http_code" ]; then
http_code="000"
fi
if [ "$http_code" = "200" ]; then
echo "Ready check passed (attempt ${i})."
curl -fsS "http://localhost:${DASHBOARD_PORT}/" >/dev/null && echo "Dashboard serving."
exit 0
fi
echo "Attempt ${i}/30: HTTP ${http_code}"
sleep 5
done
echo "Ready check never passed — dumping API logs:"
docker compose -f docker-compose.prod.yml --env-file .env logs --tail 100 api
docker compose -f docker-compose.prod.yml --env-file .env logs --tail 150 api || true
exit 1
EOF
+83 -102
View File
@@ -1,118 +1,99 @@
# Build and test on every push/PR. Fixtures read ConnectionStrings__* /
# Redis__* directly from environment (see VigilCareRecordsAPI.Tests/Fixtures/
# ApiFixture.cs) against the ports published by docker-compose.yml; object
# storage is pgsty/silo (MinIO-compatible) from docker-compose.yml defaults
# (localhost:9012, minioadmin/minioadmin; bucket auto-created on first upload
# by DocumentStorageService).
# Thin caller — pipelines live in infra/ci-workflows@v1.
# Pin @v1 (never a branch). Path filter + changes job stay local (repo-specific).
#
# Prerequisite: infra/ci-workflows Settings → Actions → collaborative owners
# must list this repo's owner.
name: CI
on:
push:
branches: [master]
branches: [main, master]
paths:
- "VigilCareRecordsAPI/**"
- "VigilCareRecordsAPI.Tests/**"
- "vigilcare-records-web/**"
- "VigilCareRecords.sln"
- ".gitea/workflows/**"
pull_request:
branches: [master]
branches: [main, master]
paths:
- "VigilCareRecordsAPI/**"
- "VigilCareRecordsAPI.Tests/**"
- "vigilcare-records-web/**"
- "VigilCareRecords.sln"
- ".gitea/workflows/**"
workflow_dispatch:
jobs:
backend:
# Stays local: repo-specific path map; needs fetch-depth: 0.
# Keep actions/checkout@v4 here until builtin:checkout is proven with fetch-depth: 0.
changes:
runs-on: ubuntu-latest
# Isolated compose project + CI override (docker-compose.ci.yml) so jobs do
# not steal Docker address-pool subnets from each other / from prod.
env:
COMPOSE_PROJECT_NAME: vigilcare-ci
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml
# act_runner's docker executor runs steps inside their own job container — a
# sibling of the "docker compose" containers below — so "localhost" from inside
# the job container is NOT the Docker host and can't reach the published
# Postgres/Redis ports (this is what "Connection refused" on 127.0.0.1:5437
# in the Test step means). The Test step below points at host.docker.internal
# instead; that hostname must resolve inside the job container, which on Linux
# requires the runner itself (not this workflow) to add
# `--add-host=host.docker.internal:host-gateway` — set
# `container: { options: "--add-host=host.docker.internal:host-gateway" }` in the
# act_runner's config.yaml. Docker Desktop runners already resolve this hostname
# out of the box. See docs/25-gitea-cicd-docker-deploy.md ("Runner requirement
# for Compose-based tests").
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v4
- name: Start dependency stack
run: |
docker network prune -f || true
docker compose down --remove-orphans -v || true
docker compose up -d --remove-orphans postgres redis minio
- name: Wait for Postgres
run: |
for i in $(seq 1 60); do
docker compose exec -T postgres pg_isready -U postgres && break
sleep 2
done
docker compose exec -T postgres pg_isready -U postgres
- name: Wait for Redis / MinIO
run: |
for i in $(seq 1 60); do
docker compose exec -T redis redis-cli ping 2>/dev/null | grep -q PONG \
&& docker compose exec -T minio curl -sf http://localhost:9000/minio/health/live >/dev/null \
&& echo "Redis and MinIO are ready" && exit 0
echo "waiting for dependencies ($i)..."
sleep 2
done
echo "Dependencies failed to become ready" >&2
docker compose ps
docker compose logs --tail=50 redis minio
exit 1
- name: Create test database
run: |
docker compose exec -T postgres psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname='vigilcare_records_test'" \
| grep -q 1 \
|| docker compose exec -T postgres psql -U postgres -c "CREATE DATABASE vigilcare_records_test"
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
fetch-depth: 0
- name: Restore
run: dotnet restore VigilCareRecords.sln
- name: Build
run: dotnet build VigilCareRecords.sln -c Release --no-restore
- name: Test
env:
ASPNETCORE_ENVIRONMENT: "Testing"
CONNECTIONSTRINGS__DEFAULTCONNECTION: "Host=host.docker.internal;Port=5437;Database=vigilcare_records_test;Username=postgres;Password=password"
REDIS__CONNECTIONSTRING: "host.docker.internal:6383,defaultDatabase=1,allowAdmin=true"
- id: filter
name: Detect stack changes
run: |
dotnet test VigilCareRecords.sln -c Release --no-build \
--logger "trx;LogFileName=test-results.trx" \
--results-directory ./TestResults
set -euo pipefail
backend=false
frontend=false
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
backend=true
frontend=true
else
if [ "${{ github.event_name }}" = "pull_request" ]; then
base="${{ github.event.pull_request.base.sha }}"
else
base="${{ github.event.before }}"
fi
if [ -z "${base:-}" ] || [ "$base" = "0000000000000000000000000000000000000000" ]; then
backend=true
frontend=true
else
files="$(git diff --name-only "$base" "${{ github.sha }}")"
printf '%s\n' "$files"
if printf '%s\n' "$files" | grep -qE '^(VigilCareRecordsAPI/|VigilCareRecordsAPI\.Tests/|VigilCareRecords\.sln|\.gitea/workflows/)'; then
backend=true
fi
if printf '%s\n' "$files" | grep -qE '^(vigilcare-records-web/|\.gitea/workflows/)'; then
frontend=true
fi
fi
fi
echo "backend=${backend}" >> "$GITHUB_OUTPUT"
echo "frontend=${frontend}" >> "$GITHUB_OUTPUT"
- name: Publish test results
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: ./TestResults
- name: Tear down stack
if: always()
run: docker compose down --remove-orphans -v
backend:
needs: changes
if: needs.changes.outputs.backend == 'true'
uses: infra/ci-workflows/.gitea/workflows/dotnet8-ci.yml@v1
with:
working_directory: .
solution: VigilCareRecords.sln
postgres_db: vigilcare_records_test
# Single test project (service-backed). No isolated/InMemory split today.
test_projects: |
VigilCareRecordsAPI.Tests/VigilCareRecordsAPI.Tests.csproj
# ApiFixture reads CONNECTIONSTRINGS__DEFAULTCONNECTION / REDIS__CONNECTIONSTRING
# (not the shared workflow's ConnectionStrings__Postgres / ConnectionStrings__Redis).
test_env: |
CONNECTIONSTRINGS__DEFAULTCONNECTION=Host=postgres;Port=5432;Database=vigilcare_records_test;Username=postgres;Password=postgres;SSL Mode=Disable
REDIS__CONNECTIONSTRING=redis:6379,defaultDatabase=1,allowAdmin=true
frontend:
runs-on: ubuntu-latest
container:
image: node:22-alpine
steps:
- uses: actions/checkout@v4
- name: Install
working-directory: vigilcare-records-web
run: npm ci
- name: Test
working-directory: vigilcare-records-web
run: npm run test:run
- name: Build
working-directory: vigilcare-records-web
run: npm run build
needs: changes
if: needs.changes.outputs.frontend == 'true'
uses: infra/ci-workflows/.gitea/workflows/node-ci.yml@v1
with:
working_directory: vigilcare-records-web
node_version: "22"
# Typecheck once here; build must not re-run vue-tsc.
lint_command: npm run typecheck
extra_check_command: npm run test:run
build_command: npx vite build
@@ -10,12 +10,10 @@ public class ApiFixture : WebApplicationFactory<Program>, IAsyncLifetime
// Override configuration to point at a test database — never run tests against
// the development database; a botched rollback could corrupt seed data.
//
// Defaults assume Postgres/Redis are reachable on the host's loopback address
// (e.g. `docker compose up -d postgres redis` on a dev machine). CI runners that
// execute the test step inside its own job container (act_runner's default docker
// executor) can't reach ports published on the Docker *host* via "localhost" —
// set CONNECTIONSTRINGS__DEFAULTCONNECTION / REDIS__CONNECTIONSTRING (e.g. to
// host.docker.internal) in that environment to override.
// Defaults assume Postgres/Redis on loopback (local `docker compose up -d
// postgres redis`). CI (infra/ci-workflows dotnet8-ci) sets
// CONNECTIONSTRINGS__DEFAULTCONNECTION / REDIS__CONNECTIONSTRING to the
// service-container DNS names (Host=postgres, redis:6379).
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.UseEnvironment("Testing");
+9 -5
View File
@@ -24,9 +24,8 @@ RUN sed -i \
-e 's/"SecretKey": "[^"]*"/"SecretKey": ""/' \
/app/publish/appsettings.json
# ---- optional target: EF migration bundle, built and extracted by the CD
# migrate job (docker build --target migrate + docker cp). Never shipped in the
# runtime image below. ----
# ---- optional target: EF migration bundle (SDK stage). CD bakes migrate-bundle
# (scratch) and extracts via docker create + docker cp — never ship this stage. ----
FROM build AS migrate
RUN dotnet tool install --global dotnet-ef --version 8.*
ENV PATH="$PATH:/root/.dotnet/tools"
@@ -35,8 +34,13 @@ RUN dotnet ef migrations bundle \
--self-contained -r linux-x64 \
--output /out/migrate-api
# ---- runtime ----
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
# scratch + CMD so bare `docker create IMAGE` works (FROM scratch has no default cmd).
FROM scratch AS migrate-bundle
COPY --from=migrate /out/migrate-api /out/migrate-api
CMD ["/out/migrate-api"]
# ---- runtime (bake target "final") ----
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
RUN apt-get update \
+42
View File
@@ -0,0 +1,42 @@
# Invoked from the repo root. cwd:// keeps contexts relative to that
# working directory, not this file.
#
# CD must cap the builder cgroup (scripts/cap-buildx-builder.sh)
# and bake one target at a time. The runner host also runs Gitea.
#
# API Dockerfile ends with `final` and exposes scratch `migrate-bundle`.
# Context for API is repo root (Dockerfile COPY paths assume that).
variable "REGISTRY" {}
variable "TAG" {}
group "default" {
targets = ["api", "ui", "migrate"]
}
target "api" {
context = "cwd://"
dockerfile = "VigilCareRecordsAPI/Dockerfile"
target = "final"
tags = ["${REGISTRY}/vigilcare-records-api:${TAG}", "${REGISTRY}/vigilcare-records-api:latest"]
cache-from = ["type=registry,ref=${REGISTRY}/vigilcare-records-api:buildcache"]
cache-to = ["type=registry,ref=${REGISTRY}/vigilcare-records-api:buildcache,mode=max"]
}
target "ui" {
context = "cwd://vigilcare-records-web"
dockerfile = "Dockerfile"
target = "final"
tags = ["${REGISTRY}/vigilcare-records-dashboard:${TAG}", "${REGISTRY}/vigilcare-records-dashboard:latest"]
cache-from = ["type=registry,ref=${REGISTRY}/vigilcare-records-dashboard:buildcache"]
cache-to = ["type=registry,ref=${REGISTRY}/vigilcare-records-dashboard:buildcache,mode=max"]
}
target "migrate" {
context = "cwd://"
dockerfile = "VigilCareRecordsAPI/Dockerfile"
target = "migrate-bundle"
tags = ["vigilcare-records-migrate-bundle:local"]
cache-from = ["type=registry,ref=${REGISTRY}/vigilcare-records-api:buildcache"]
# no cache-to — api already exports this Dockerfile at mode=max
}
-9
View File
@@ -1,9 +0,0 @@
# CI override: attach deps to the host's built-in bridge instead of creating a
# new user-defined network. Busy act_runners often hit
# "all predefined address pools have been fully subnetted" when every job
# allocates a fresh subnet. Tests reach Postgres/Redis/MinIO via published
# ports on host.docker.internal, so service-name DNS is not required.
networks:
vigilcare:
external: true
name: bridge
+12 -4
View File
@@ -2,12 +2,20 @@
How to wire a multi-service app for continuous integration and deployment on **Gitea Actions**, using VigilCare Clinical as a concrete example. The same layout works for any stack: keep local infra in one Compose file, ship only app images in production, put secrets on the host (not in git), and let workflows build, migrate, and deploy on version tags.
> **Platform source of truth:** [`docs/CICD/`](CICD/README.md) — especially
> [`onboarding-a-project.md`](CICD/onboarding-a-project.md) and
> [`platform/observed-state.md`](CICD/platform/observed-state.md).
> Prefer reusable callers (`infra/ci-workflows@v1`) over compose-based CI.
> For this repo’s current wiring, see [`docs/26-vigilcare-records-cicd.md`](26-vigilcare-records-cicd.md).
> Sections below that describe `host.docker.internal` / published DB ports are
> historical Clinical patterns; do not copy them into new projects.
Related docs in this repo:
- [`.gitea/workflows/ci.yml`](../../.gitea/workflows/ci.yml) / [`.gitea/workflows/cd.yml`](../../.gitea/workflows/cd.yml)
- [`docker-compose.yml`](../../docker-compose.yml) (local + CI dependencies)
- [`docker-compose.prod.yml`](../../docker-compose.prod.yml) (production app stack)
- [`.env.example`](../../.env.example)
- [`.gitea/workflows/ci.yml`](../.gitea/workflows/ci.yml) / [`.gitea/workflows/cd.yml`](../.gitea/workflows/cd.yml)
- [`docker-compose.yml`](../docker-compose.yml) (local dependencies)
- [`docker-compose.prod.yml`](../docker-compose.prod.yml) (production app stack)
- [`.env.example`](../.env.example)
- [`docs/ops/cd-deploy-ssh-setup.md`](../ops/cd-deploy-ssh-setup.md)
- [`docs/instructions-for-env.md`](../instructions-for-env.md)
+58 -11
View File
@@ -1,11 +1,15 @@
# Guide 26: VigilCareRecords CI/CD (Gitea Actions + Docker Compose)
How VigilCareRecords is built, tested, and deployed on the same Gitea Actions + `act_runner` + container registry setup already used by VigilCareClinical. See [`docs/25-gitea-cicd-docker-deploy.md`](25-gitea-cicd-docker-deploy.md) for the general pattern this guide instantiates; this doc only covers what is specific to this repo.
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-compose.yml`](../docker-compose.yml) (local + CI dependencies)
- [`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)
@@ -23,7 +27,32 @@ VigilCareRecords ships two images:
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. Shared production infrastructure
---
## 2. CI
CI is a **thin caller** of shared reusable workflows in `infra/ci-workflows@v1`.
Steps are not copied into this repo.
| Job | Workflow |
| --- | --- |
| `backend` | `dotnet8-ci.yml@v1` — Postgres/Redis as `services:`, reached by DNS (`Host=postgres`, `redis:6379`) |
| `frontend` | `node-ci.yml@v1` — 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`.
**Prerequisite:** `infra/ci-workflows` Settings → Actions → collaborative owners
must include this repo’s owner.
---
## 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:
@@ -33,7 +62,9 @@ Per the "Integrated Database Deployment" decision documented in [`vigilcare-reco
**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.
## 3. One-time host setup
---
## 4. One-time host setup
```bash
ssh deploy@YOUR_HOST "mkdir -p /opt/vigilcare-records"
@@ -43,6 +74,8 @@ 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
@@ -57,7 +90,9 @@ docker run --rm --network shared-services --entrypoint /bin/sh minio/mc \
EOF
```
## 4. Gitea secrets and variables
---
## 5. Gitea secrets and variables
Repo → **Settings** → **Actions**.
@@ -65,8 +100,8 @@ Repo → **Settings** → **Actions**.
| Secret | Used by |
|---|---|
| `REGISTRY_USERNAME` | `docker login` |
| `REGISTRY_TOKEN` | `docker login` (access token / PAT with package write) |
| `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 |
@@ -77,8 +112,11 @@ Repo → **Settings** → **Actions**.
| Variable | Used by |
|---|---|
| `REGISTRY` | Optional override of the default `git.vectur45.com/trent/vigilcare-records` |
| `MIGRATE_DOCKER_NETWORK` | Optional; defaults to `shared-services` |
## 5. Release flow
---
## 6. Release flow (CD)
```bash
# CI green on master, then:
@@ -86,11 +124,20 @@ git tag v1.0.0
git push origin v1.0.0
```
This triggers `.gitea/workflows/cd.yml`: build & push both images → SSH the EF migrations bundle onto the deploy host and run it on `shared-services` with `PG_CONNECTION_DDL` → SSH deploy (`scp` the prod compose file, patch `IMAGE_TAG`, `pull` + `up -d`) → smoke test (`/health/ready`, dashboard `/`) → automatic rollback to the previous `IMAGE_TAG` on failure (schema changes are not reverted; see the expand/contract note in `cd.yml`).
`.gitea/workflows/cd.yml`:
Manual redeploy of an existing tag: Gitea UI → Actions → CD → Run workflow, with `image_tag` input.
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)
## 6. Pre-production checklist (application-level, not part of this CI/CD change)
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).
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Cap a named docker-container buildx builder so it cannot take both vCPUs
# or swap-thrash Gitea on the e2-standard-2 (2 vCPU / 8 GB).
#
# ./CICD/scripts/cap-buildx-builder.sh growth-os-builder
#
# BUILDKIT_STEP_MAX_PARALLELISM=1 only serializes steps. A single
# `dotnet publish` / vite / gzip still uses every core unless the
# buildkitd container itself has a cgroup quota. This script:
# - reuses the builder when the driver is already docker-container
# (wiping it would drop the local BuildKit cache)
# - creates it with parallelism=1 and GOMAXPROCS=1 when missing
# - always `docker update --cpus=1 --memory=3g --memory-swap=3g`
#
# Override with BUILDX_HOST_CPUS / BUILDX_HOST_MEMORY.
# The CD job must still bake one target at a time.
set -euo pipefail
builder="${1:?builder name}"
cpus="${BUILDX_HOST_CPUS:-1.0}"
memory="${BUILDX_HOST_MEMORY:-3g}"
if docker buildx inspect "$builder" >/dev/null 2>&1; then
driver="$(docker buildx inspect "$builder" | awk '/^Driver:/{print $2; exit}')"
if [ "$driver" = "docker-container" ]; then
docker buildx use "$builder"
else
docker buildx rm -f "$builder"
docker buildx create --name "$builder" --driver docker-container \
--driver-opt env.BUILDKIT_STEP_MAX_PARALLELISM=1 \
--driver-opt env.GOMAXPROCS=1 \
--use
fi
else
docker buildx create --name "$builder" --driver docker-container \
--driver-opt env.BUILDKIT_STEP_MAX_PARALLELISM=1 \
--driver-opt env.GOMAXPROCS=1 \
--use
fi
docker buildx inspect --bootstrap
ids="$(docker ps --filter "name=buildx_buildkit_${builder}" --format '{{.ID}}')"
cid="$(printf '%s\n' "$ids" | awk 'NR==1')"
if [ -z "$cid" ]; then
echo "cap-buildx-builder: no running container matching buildx_buildkit_${builder}" >&2
docker ps --filter "name=buildx_buildkit" >&2 || true
exit 1
fi
docker update \
--cpus="$cpus" \
--memory="$memory" \
--memory-swap="$memory" \
--cpu-shares=512 \
"$cid"
echo "cap-buildx-builder: ${builder} -> ${cid} cpus=${cpus} memory=${memory} (swap capped)"
+6 -5
View File
@@ -8,12 +8,13 @@ COPY package.json package-lock.json ./
RUN npm ci
COPY . .
# No VITE_API_URL build-arg needed: src/api/client.ts and src/api/fhirClient.ts
# use relative base URLs ("/api/v1", "/fhir") and rely on the nginx reverse proxy
# below to reach the api container at runtime — same origin in every environment.
RUN npm run build
# Typecheck runs in CI (npm run typecheck). Image build is vite only.
# No VITE_API_URL build-arg: src/api/client.ts and src/api/fhirClient.ts use
# relative base URLs ("/api/v1", "/fhir"); nginx reverse-proxies to the api
# container — same origin in every environment.
RUN npx vite build
FROM nginx:1.27-alpine AS runtime
FROM nginx:1.27-alpine AS final
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html
+2 -1
View File
@@ -5,7 +5,8 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"typecheck": "vue-tsc -b",
"build": "vite build",
"preview": "vite preview",
"test": "vitest",
"test:run": "vitest run",