Operations

Deployment and Runtime

Deploy AMCDR services, apply database migrations, configure dependencies, and check runtime health.

Runtime service requirements

Each deployment profile must run the AMCDR application, governed clinical repository, search index, runtime cache, and configured identity provider where authentication is enabled. Database migrations must be applied and verified before clinical traffic is served.

Production posture

National-scale deployment profiles

AMCDR supports Docker single-tenant, Docker multi-tenant, replicated Kubernetes single-tenant, and replicated Kubernetes multi-tenant deployments. AMCDR_INFRASTRUCTURE_MODE selects the infrastructure profile independently from the existing AMCDR_DEPLOYMENT_MODE product-module preset.

Full-EHR profile with AmyTerm

The recommended full-EHR profile deploys AmyTerm as a separately operated companion service and registers it in AMCDR as amyterm-main. Each service keeps its own database, secrets, migrations and recovery process. AMCDR calls AmyTerm's FHIR terminology API over verified TLS with OAuth2 client credentials; AmyTerm owns codes, ValueSets and mappings, while AMCDR owns patient records, facility defaults, workflows, prices and invoices.

AMCDR caches terminology results and supplies small standards-based country, language and currency fallbacks. Registration, discharge and emergency care therefore do not depend on a fresh network call. A core-CDR deployment may omit AmyTerm only when another governed FHIR terminology authority is configured.

ProfileRequired settingsOperating model
Docker single tenantdocker-single-tenant, singleDefault tenant with signed or membership-resolved request context.
Docker multi-tenantdocker-multi-tenant, multiMandatory verified tenant context, PostgreSQL RLS and tenant-isolated search/cache.
Kubernetes single tenantkubernetes-single-tenant, singleReplicated stateless APIs and dedicated replica-safe workers.
Kubernetes multi-tenantkubernetes-multi-tenant, multiNational shared platform with tenant isolation enforced at every runtime layer.

Verified tenant context

Every authenticated clinical request resolves one immutable tenant context from a signed OIDC/bearer claim, a verified API credential, or the configured single-tenant default. Governance headers such as X-AmCDR-Tenant-ID constrain scope but never grant it. Tenant switching requires a newly signed token. Multi-tenant API-key calls include the tenant header, and AMCDR proceeds only when the API-key hash and stored credential tenant both match.

AMCDR_TENANCY_MODE=multi
AMCDR_TENANT_CONTEXT_REQUIRED=true
AMCDR_TENANT_DATABASE_RLS_ENABLED=true
AMCDR_TENANT_OPENSEARCH_ISOLATION=index

The supplied Keycloak realm maps the admin-managed tenant_id user attribute into ID, access, and user-info tokens. Assign every workforce identity an active AMCDR tenant UUID before enabling multi-tenant clinical traffic. Users working across organizations obtain a separately signed session for the selected tenant; request headers cannot change that identity scope.

Defence-in-depth isolation

The API database credential must use a dedicated NOSUPERUSER NOBYPASSRLS role. Alembic uses a separate migration-owner URL. The readiness check reports action_required if the runtime role is a superuser or can bypass RLS, because PostgreSQL intentionally exempts those roles even when policies are forced.

Kubernetes production topology

The production manifests provide a one-shot migration Job, separate API/frontend/worker Deployments, non-root containers, read-only root filesystems, explicit resources, startup/readiness/liveness probes, topology spreading, disruption budgets, horizontal autoscaling, dedicated service accounts, TLS ingress and ingress network controls. PostgreSQL, Redis and OpenSearch are externalized in production so a national operator can attach approved high-availability services, backup policy, point-in-time recovery and regional disaster recovery.

Use Kubernetes Production Deployment for the complete operator runbook, including prerequisites, immutable images, secrets, database roles, signed tenant context, network egress, migration sequencing, FHIR validator packages, probes, scaling, monitoring, backup restoration, disaster recovery, upgrades, incident controls, and production acceptance gates.

Complete and approve Data Residency and Subprocessor Controls for every production provider, region, replica, backup, recovery path, support location and external recipient before admitting clinical traffic.

kubectl kustomize k8s/overlays/prod-single > rendered-single-tenant.yaml
kubectl kustomize k8s/overlays/prod > rendered-multi-tenant.yaml

Create the referenced amcdr-secrets Secret through the approved secret manager or CSI/External Secrets integration. Never deploy the example placeholder secret. Run GET /admin/tenant-isolation/readiness, or open Platform configuration → Readiness & Audit, before promoting clinical traffic. A shared multi-tenant release must report production_multi_tenant_ready=true.

Health checks

After every deployment, check application health, schema state, search availability, frontend reachability, sign-in behavior, and terminology connectivity.

Deployment sequence

Use the same sequence across local, staging, and production deployments so migrations, caches, indexes, and optional modules come up predictably.

docker compose \
  -f docker-compose.yml \
  -f docker-compose.dependencies.yml \
  run --rm --no-deps -T backend alembic upgrade head

curl -i http://127.0.0.1:8009/health
curl -I https://amcdr.example.org/
StepWhy it matters
Run migrations before trafficKeeps backend schema revision aligned with the expected Alembic head and avoids runtime 503 readiness failures.
Restart backend/frontendLoads new code, authenticated documentation, OpenAPI schema, and module registry changes.
Warm Redis cachesPreloads template, form, AQL, terminology, saved-query, and selected operational projections.
Reindex OpenSearchRefreshes patient, composition, template, and rebuildable search projections after imports or schema/index changes.
Check optional servicesVerify MediServe, Clinical Safety Sidecar, AMy-Term, OpenSearch, Redis, and CQL services only when enabled for the deployment.

GitHub, Harbor and GitOps publishing

Releases start from the main branch. A GitHub-hosted runner checks dependencies, lint, Alembic migrations and PostgreSQL enterprise workflows, then builds the frontend and documentation. All of these checks must pass before publishing begins.

The trusted self-hosted BuildKit job publishes backend and frontend images to registry.hygeoniq.com with immutable tags containing the UTC date, time and commit. It commits those image references to the platform-infrastructure GitOps repository. Argo CD applies the Kubernetes changes, and the workflow verifies the backend, worker and frontend rollouts. Development Docker then receives the same image tag, followed by the VPS build from the accepted Git revision.

The publisher treats HTTP 200 or the registry's expected unauthenticated 401 response from https://registry.hygeoniq.com/v2/ as ready. It waits for Harbor/Traefik readiness before building and retries an interrupted image publish with the same immutable tag. Do not bypass TLS verification and do not substitute the Harbor user-interface hostname for the canonical registry hostname.

Privileged publishing runs only on repository-scoped self-hosted runners after trusted-main acceptance succeeds. Harbor and infrastructure credentials stay in owner-readable runner files; development and VPS SSH credentials plus pinned host keys stay in GitHub Actions secrets. Pull-request jobs never receive those credentials or the Docker socket.

FailureCheckRecovery
connect: connection refused on port 443Traefik entry point, Harbor ingress/route, Harbor core and registry pods/services, node address and local DNS/hosts mapping.Restore the ingress or registry service, verify /v2/ returns 200/401, then rerun the failed workflow. The immutable tag makes the retry safe.
TLS name or certificate errorCertificate SAN includes registry.hygeoniq.com; full chain is served; runner trusts the issuing CA.Correct the certificate/route. Never use an insecure-registry flag as a workaround.
401 after Docker configurationHarbor robot/user credentials and amcdr project push permission.Rotate/update the protected runner credential and rerun without printing the secret.
GitOps update skippedBoth images exist under the exact AMCDR_IMAGE_TAG; infrastructure deploy key and protected branch access are valid.Repair access, retain the existing image tag, and rerun the workflow.

Immutable GitHub-source VPS releases

The main-branch workflow deploys the AMCDR VPS by pulling and building the accepted GitHub revision. The deployer fetches origin/main, verifies the full revision and creates a detached worktree below /opt/amcdr/releases/. It links the protected .env and applies /opt/amcdr/config/docker-compose.vps.local.yml, keeping the approved connector configuration mounted read-only.

From that immutable worktree, the deployer builds the application and runs docker compose run --rm --no-deps -T backend alembic upgrade head once. It then recreates the stateless backend, frontend and documentation containers. After checking public TLS, service health and the device-integration documentation page, it records the full revision in /opt/amcdr/current-git-revision. The --no-deps option prevents Compose from reconciling or recreating PostgreSQL, Redis or OpenSearch during migration.

The deployment lock serializes VPS releases and prior stateless image IDs are retained for health-failure rollback. Schema downgrade is never automatic; migrations delivered continuously must remain backward compatible with the preceding application revision.

Rollback boundary. Do not reset, clean or release from the VPS's divergent mutable checkout. Roll application containers back to a prior immutable release only when its schema is compatible. If new schema has received data, database downgrade requires an approved maintenance window, backup and data-disposition plan.

Preserve the cryptographic installation-identity volume during every recreation. Replacing that volume registers a different installation with the control plane and invalidates the relationship to its existing license.

Documentation loading and cache

The selected documentation page loads first. Once the browser is idle, AMCDR fetches the authenticated documentation bundle and search index, then caches all pages for subsequent in-app navigation. The backend also supplies ETag, Last-Modified and private cache headers. A release-specific cache version invalidates old pages after deployment. Documentation navigation replaces only the document content and must not reload the clinical application shell.

CQL runtime services

CQL translation and evaluation run as separate services. The translator converts CQL to ELM and should be available when importing or compiling CQL libraries. The evaluator executes compiled libraries against governed patient facts and should be available when Clinical Assistant guardrails or CDS workflows depend on CQL.

docker compose \
  -f docker-compose.yml \
  -f docker-compose.dependencies.yml \
  -f docker-compose.cql.yml \
  up -d cql-translator cql-evaluator
ServiceExpected configurationVerification
CQL translatorAMCDR_CQL_COMPILER_URL=http://cql-translator:8080Compile a known CQL library and confirm ELM is stored under runtime/cql/elm/<library>/<version>/.
CQL evaluatorAMCDR_CQL_EVALUATOR_URL=http://cql-evaluator:8081Run the evaluator health endpoint and execute a low-risk library that does not require live FHIR facts.
Backend API keyEvaluator service calls should use the configured AMCDR API key or internal service credential.Confirm CQL evaluation does not fail with HTTP 401 during background guardrail checks.

Search indexing and cache warmup

OpenSearch indexes can be rebuilt from the authoritative clinical data. After migrations, search projection changes, or large imports, run an authenticated reindex for the affected scope or a full reindex for all projections.

Performance readinessGET /performance/readiness reports schema state, Redis availability, OpenSearch projection health, cache warmup ownership, and measured probe latency.
StatusGET /search/status confirms OpenSearch configuration, aliases, shards, and cluster health.
Compositions onlyPOST /search/reindex?scope=compositions rebuilds composition search documents.
Full reindexPOST /search/reindex?scope=all rebuilds patient, composition, template, and supported projection indexes.

Redis cache warmup keeps template node pickers, AQL builder metadata, form designer metadata, and saved-query export paths responsive. Run a full warmup after template-heavy imports or deployments that change template projection logic.

docker compose exec -T backend python - <<'PY'
from app.core.warmup import run_warmup_once
run_warmup_once(label="manual", full=True)
PY

For an operator-controlled full search rebuild, run the same backend-side function used by the API when bearer/API-key access is not convenient on the host.

docker compose exec -T backend python - <<'PY'
from app.db.session import SessionLocal
from app.services.search_service import create_reindex_job, search_status

db = SessionLocal()
try:
    print(search_status())
    print(create_reindex_job(db, index_scope="all"))
finally:
    db.close()
PY

Expected cache families include amcdr:tmpl:*, amcdr:scope:tmpl:*, and laboratory operational keys such as amcdr:lab:* when Laboratory is enabled. Cache is rebuildable; PostgreSQL remains authoritative.

curl -s -H "Authorization: Bearer ${TOKEN}" http://127.0.0.1:8009/performance/readiness

For normal operation, aim for status=ok. status=degraded means the clinical API may remain available, but an accelerator such as Redis, OpenSearch, or cache warmup requires attention. status=not_ready means schema or database readiness must be corrected before clinical traffic.

Production monitoring

AMCDR exposes Prometheus-compatible metrics at GET /metrics. Keep this endpoint protected by backend authentication and restrict it at the reverse proxy to the internal scrape network.

HTTP trafficRequest totals, in-flight requests, and route duration histograms by route template and status code.
ReadinessPerformance readiness state, schema/database/Redis/OpenSearch/cache-warmup gauges, and dependency probe latency.
openEHR EHR recordsAuthoritative database count of EHR containers through amcdr_ehr_records.
OpenSearchProjection alias presence, health state, and document counts for patient, composition, and template search scopes.
Cache warmupWarmup owner, background loop state, and configured rewarm interval.

Use Prometheus and Grafana to retain metrics, build dashboards, send alerts and follow trends. Redis handles caching and distributed locks. For complete infrastructure visibility, pair AMCDR /metrics with Redis, PostgreSQL, OpenSearch, node, and container exporters.

For VPS monitoring, start Prometheus and Grafana through docker-compose.monitoring.yml; they are not created by the core VPS compose command unless the monitoring file is included.

docker compose \
  -f docker-compose.yml \
  -f docker-compose.dependencies.yml \
  -f docker-compose.monitoring.yml \
  up -d prometheus grafana

The monitoring services use restart: unless-stopped. After they are created once, Docker restarts them after host or daemon reboot. Keep Prometheus and Grafana bound to 127.0.0.1 unless access is protected by VPN, SSO, or a private reverse proxy.

For the shared sandbox monitoring portal, put these values in the deployment environment file and recreate Grafana: AMCDR_GRAFANA_HOST_BIND=127.0.0.1, GF_SERVER_DOMAIN=grafana.sandbox.hygeoniq.com, GF_SERVER_ROOT_URL=https://grafana.sandbox.hygeoniq.com/, and GF_SECURITY_COOKIE_SECURE=true.

Prometheus must use a dedicated metrics token. Set AMCDR_METRICS_BEARER_TOKEN on the backend and put the same value in the Prometheus bearer token file. Do not use an expiring user session token for Prometheus scrapes.

For the complete monitoring runbook, dashboard guidance, scrape configuration, and recommended alert rules, use Platform Monitoring.