diff --git a/.github/scripts/gke/README.md b/.github/scripts/gke/README.md index ab22b4db..782e77d2 100644 --- a/.github/scripts/gke/README.md +++ b/.github/scripts/gke/README.md @@ -1,13 +1,15 @@ # GKE deployment test -Every pull request that touches the Helm charts is deployed to its own small GKE -cluster and left running, so reviewers can open the apps in a browser. +Every pull request that touches the deployment is deployed to its own small GKE +cluster and left running, so reviewers can open the services in a browser. The +stack is HAPI FHIR, OpenSearch and NiFi, deployed by +`deployment/scripts/minimum_deployment.sh` and nothing else. | | | |---|---| | Workflows | `.github/workflows/gke_deploy_test.yml`, `.github/workflows/gke_teardown.yml` | -| URLs | `https://.pr-.platform.cogstack.dev` for `trainer`, `jupyter`, `dashboards`, `medcat`, `anoncat`, `ocr` | -| Login | user `cogstack`; password: `gcloud secrets versions access latest --secret preview-basic-auth-password --project ` | +| URLs | `https://.pr-.platform.cogstack.dev` for `hapi`, `opensearch`, `nifi` | +| Login | user `admin`; password: `gcloud secrets versions access latest --secret preview-basic-auth-password --project ` | | Auth to Google Cloud | GitHub OIDC (Workload Identity Federation). No keys are stored anywhere. | ## How it works @@ -17,16 +19,18 @@ every script derives what it needs from the PR number. 1. `cluster-up.sh` creates the cluster, or reuses it if a previous push already did. 2. `deploy.sh` installs Traefik and cert-manager, points `*.pr-.platform.cogstack.dev` - at the load balancer, obtains a wildcard certificate, then installs or upgrades - `cogstack-ce-helm` (`deployment/charts/ce`) from the PR and runs `helm test`. -3. `smoke-test.sh` requests every app over public HTTPS. + at the load balancer, obtains a wildcard certificate, then runs + `minimum_deployment.sh` from the PR with `INGRESS_DOMAIN` set and waits for + the workloads. +3. `smoke-test.sh` requests every service over public HTTPS. 4. `pr-status.sh` writes a panel at the top of the PR description: a link and a green or red dot per app. It shows "deploying", "failed" and "removed" too, and the hourly job re-checks the dots for environments that are still up. 5. The check goes green and the cluster stays up. -Every route sits behind basic auth, because the charts ship demo passwords and -the URLs are public. +Every route sits behind basic auth, because HAPI FHIR and NiFi have no login +and the URLs are public. Traefik passes the login on, and the OpenSearch `admin` +user is given the same password, so one login opens all three. ## Teardown @@ -66,6 +70,6 @@ To move the test to another repository: ## Limits - Pull requests from forks and from Dependabot are skipped: they cannot obtain an OIDC token. -- Pull requests that change nothing under `deployment/charts/`, `.github/scripts/` or - `.github/workflows/gke_*` are not deployed; the check is skipped and counts as passing. +- Pull requests that change nothing under `deployment/charts/`, `deployment/scripts/`, + `deployment/env/`, `.github/scripts/` or `.github/workflows/gke_*` are not deployed; the check is skipped and counts as passing. - The charts deploy published images, so this tests the charts, not unreleased application code. diff --git a/.github/scripts/gke/deploy.sh b/.github/scripts/gke/deploy.sh index 37d08b83..ec8b53ba 100755 --- a/.github/scripts/gke/deploy.sh +++ b/.github/scripts/gke/deploy.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -# Deploy this checkout of cogstack-ce-helm to the PR's cluster, behind HTTPS. -# Safe to re-run: a later push to the PR upgrades the existing release. +# Deploy this checkout's minimum stack (HAPI FHIR, OpenSearch, NiFi) to the PR's +# cluster, behind HTTPS, with deployment/scripts/minimum_deployment.sh. +# Safe to re-run: a later push to the PR applies the manifests again. # Usage: deploy.sh (run cluster-up.sh first) set -euo pipefail cd "$(dirname "$0")" @@ -52,21 +53,15 @@ log "Requesting the wildcard certificate for *.${DOMAIN}" envsubst '${GCP_PROJECT_ID} ${DOMAIN}' < platform.tmpl.yaml | kubectl apply -f - kubectl -n traefik wait --for=condition=Ready certificate/wildcard --timeout=15m -log "Deploying cogstack-ce-helm" -envsubst '${DOMAIN}' < values.tmpl.yaml > "$WORK/values.yaml" -(cd "$REPO_ROOT/deployment/charts" && "$REPO_ROOT/.github/scripts/helm-recursive-dependency-update.py") +log "Deploying the minimum stack" +# The script takes its OpenSearch users from this file instead of the passwords +# committed in deployment/env/authentication.env. +printf 'OPENSEARCH_ADMIN_PASSWORD=%s\nOPENSEARCH_KIBANA_PASSWORD=%s\n' \ + "$password" "$(openssl rand -hex 16)" > "$WORK/authentication.env" +OPENSEARCH_AUTH_FILE="$WORK/authentication.env" INGRESS_DOMAIN="$DOMAIN" \ + bash "$REPO_ROOT/deployment/scripts/minimum_deployment.sh" -# A release left failed or half-applied by an earlier run blocks upgrades; start it clean. -release_status="$(helm status "$RELEASE_NAME" -n "$RELEASE_NAMESPACE" -o json 2>/dev/null | jq -r '.info.status' || true)" -if [[ -n "$release_status" && "$release_status" != "deployed" ]]; then - log "Release is '$release_status'; uninstalling before reinstall" - helm uninstall "$RELEASE_NAME" -n "$RELEASE_NAMESPACE" --wait --timeout 10m -fi - -helm upgrade --install "$RELEASE_NAME" "$REPO_ROOT/deployment/charts/ce" \ - --namespace "$RELEASE_NAMESPACE" --create-namespace \ - -f "$WORK/values.yaml" \ - --wait --timeout 30m - -log "Running helm tests" -helm test "$RELEASE_NAME" -n "$RELEASE_NAMESPACE" --logs --timeout 15m +log "Waiting for the workloads" +for workload in $(kubectl -n "$NAMESPACE" get deployment,statefulset -o name); do + kubectl -n "$NAMESPACE" rollout status "$workload" --timeout=20m +done diff --git a/.github/scripts/gke/lib.sh b/.github/scripts/gke/lib.sh index 2a76849b..9fdf6724 100755 --- a/.github/scripts/gke/lib.sh +++ b/.github/scripts/gke/lib.sh @@ -18,11 +18,15 @@ export NODE_SERVICE_ACCOUNT="gke-node@${GCP_PROJECT_ID}.iam.gserviceaccount.com" # Label carried by every cluster this test creates; the reaper selects on it. export CLUSTER_LABEL="purpose=pr-deploy-test" -export BASIC_AUTH_USER="cogstack" +# Traefik asks for this login on every route and passes it on, and deploy.sh +# gives the same password to the OpenSearch user of the same name. One login +# therefore opens all three services. +export BASIC_AUTH_USER="admin" export BASIC_AUTH_SECRET="preview-basic-auth-password" -export RELEASE_NAME="cogstack" -export RELEASE_NAMESPACE="cogstack" +# The namespace minimum_deployment.sh deploys to. +NAMESPACE="$(source ../../../deployment/env/general.env && echo "$KUBE_NAMESPACE")" +export NAMESPACE # Pinned so that an upstream chart release cannot break a required check. export TRAEFIK_CHART_VERSION="42.4.1" @@ -30,7 +34,7 @@ export CERT_MANAGER_CHART_VERSION="v1.21.3" # Apps exposed per PR as .pr-., with the path the # smoke test requests. -export APPS="trainer:/ jupyter:/ dashboards:/ medcat:/api/health/live anoncat:/api/health/live ocr:/api/health" +export APPS="hapi:/fhir/metadata opensearch:/ nifi:/nifi/" # set_pr : derive the per-PR names. set_pr() { diff --git a/.github/scripts/gke/platform.tmpl.yaml b/.github/scripts/gke/platform.tmpl.yaml index 56ffea16..1fa492ac 100644 --- a/.github/scripts/gke/platform.tmpl.yaml +++ b/.github/scripts/gke/platform.tmpl.yaml @@ -36,5 +36,5 @@ metadata: spec: basicAuth: secret: basic-auth-users - # Do not pass the browser's Basic credentials on to the apps. - removeHeader: true + # OpenSearch needs the credentials too; see BASIC_AUTH_USER in lib.sh. + removeHeader: false diff --git a/.github/scripts/gke/pr-status.sh b/.github/scripts/gke/pr-status.sh index 38acc2f2..ee1d1b3b 100755 --- a/.github/scripts/gke/pr-status.sh +++ b/.github/scripts/gke/pr-status.sh @@ -27,12 +27,9 @@ now="$(date -u '+%Y-%m-%d %H:%M UTC')" app_title() { case "$1" in - trainer) echo "MedCAT Trainer" ;; - jupyter) echo "JupyterHub" ;; - dashboards) echo "OpenSearch Dashboards" ;; - medcat) echo "MedCAT Service (API)" ;; - anoncat) echo "AnonCAT Service (API)" ;; - ocr) echo "OCR Service (API)" ;; + hapi) echo "HAPI FHIR (API)" ;; + opensearch) echo "OpenSearch (API)" ;; + nifi) echo "NiFi" ;; *) echo "$1" ;; esac } diff --git a/.github/scripts/gke/setup-gcp.sh b/.github/scripts/gke/setup-gcp.sh index 18a820f0..edc8adad 100755 --- a/.github/scripts/gke/setup-gcp.sh +++ b/.github/scripts/gke/setup-gcp.sh @@ -132,6 +132,6 @@ $(for repo in "$@"; do echo " gh variable set GCP_SERVICE_ACCOUNT -R ${repo} -b ${CI_SA}" done) -3. Password for the PR environments (user "cogstack"): +3. Password for the PR environments (user "admin"): gcloud secrets versions access latest --secret ${SECRET} --project ${PROJECT_ID} EOF diff --git a/.github/scripts/gke/teardown.sh b/.github/scripts/gke/teardown.sh index 04cd1e65..d1c79f6c 100755 --- a/.github/scripts/gke/teardown.sh +++ b/.github/scripts/gke/teardown.sh @@ -13,8 +13,7 @@ if [[ -n "$status" ]]; then # cluster alone leaves the load balancer and the volume disks behind, billing. if [[ "$status" == "RUNNING" || "$status" == "RECONCILING" ]] && get_credentials; then log "Removing workloads, volumes and the load balancer" - helm uninstall "$RELEASE_NAME" -n "$RELEASE_NAMESPACE" --wait --timeout 10m || true - kubectl delete namespace "$RELEASE_NAMESPACE" --ignore-not-found --timeout=10m || true + kubectl delete namespace "$NAMESPACE" --ignore-not-found --timeout=10m || true helm uninstall traefik -n traefik --wait --timeout 10m || true kubectl -n traefik delete svc --all --ignore-not-found --timeout=10m || true else diff --git a/.github/scripts/gke/values.tmpl.yaml b/.github/scripts/gke/values.tmpl.yaml deleted file mode 100644 index f6300624..00000000 --- a/.github/scripts/gke/values.tmpl.yaml +++ /dev/null @@ -1,69 +0,0 @@ -# Values for cogstack-ce-helm in a PR environment: the chart defaults plus an -# ingress per app. Rendered with envsubst; ${DOMAIN} is pr-.. -opensearch: - replicas: 1 - # GKE nodes ship vm.max_map_count=65530; OpenSearch refuses to start below 262144. - sysctlInit: - enabled: true - -opensearch-dashboards: - ingress: - enabled: true - ingressClassName: traefik - hosts: - - host: dashboards.${DOMAIN} - paths: - - path: / - backend: - serviceName: "" - servicePort: "" - -medcat-service: - ingress: - enabled: true - className: traefik - hosts: - - host: medcat.${DOMAIN} - paths: - - path: / - pathType: Prefix - -anoncat-service: - ingress: - enabled: true - className: traefik - hosts: - - host: anoncat.${DOMAIN} - paths: - - path: / - pathType: Prefix - -ocr-service: - ingress: - enabled: true - className: traefik - hosts: - - host: ocr.${DOMAIN} - paths: - - path: / - pathType: Prefix - -medcat-trainer: - env: - CSRF_TRUSTED_ORIGINS: "https://trainer.${DOMAIN}" - ingress: - enabled: true - className: traefik - hosts: - - host: trainer.${DOMAIN} - paths: - - path: / - pathType: Prefix - -cogstack-jupyterhub: - jupyterhub: - ingress: - enabled: true - ingressClassName: traefik - hosts: - - jupyter.${DOMAIN} diff --git a/.github/workflows/gke_deploy_test.yml b/.github/workflows/gke_deploy_test.yml index db7712e1..4dafe6ac 100644 --- a/.github/workflows/gke_deploy_test.yml +++ b/.github/workflows/gke_deploy_test.yml @@ -1,8 +1,9 @@ -# Deploy the PR's cogstack-ce-helm chart to its own GKE cluster and leave it -# running at https://.pr-.platform.cogstack.dev for review. The -# links and a status dot per app are kept at the top of the PR description. +# Deploy the PR's minimum stack (HAPI FHIR, OpenSearch, NiFi) to its own GKE +# cluster with deployment/scripts/minimum_deployment.sh and leave it running at +# https://.pr-.platform.cogstack.dev for review. The links and +# a status dot per service are kept at the top of the PR description. # -# - The first run for a PR creates the cluster; later pushes upgrade the release. +# - The first run for a PR creates the cluster; later pushes apply the manifests again. # - The cluster is removed by gke_teardown.yml (PR closed, manual, or too old). # - Authentication to Google Cloud is GitHub OIDC; there are no stored keys. # - Nothing here names a repository. The test runs wherever the three GCP_* @@ -46,7 +47,7 @@ jobs: PR_NUMBER: ${{ github.event.pull_request.number }} run: | if gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files" --paginate --jq '.[].filename' | - grep -qE '^(deployment/charts/|\.github/scripts/|\.github/workflows/gke_)'; then + grep -qE '^(deployment/(charts|scripts|env)/|\.github/scripts/|\.github/workflows/gke_)'; then echo "deploy=true" >> "$GITHUB_OUTPUT" else echo "deploy=false" >> "$GITHUB_OUTPUT" @@ -90,8 +91,8 @@ jobs: with: version: v3.17.0 - - name: Install Python deps for chart scripts - run: pip install pyyaml + - name: Install htpasswd + run: command -v htpasswd || { sudo apt-get update && sudo apt-get install -y apache2-utils; } - name: Create or reuse the cluster run: .github/scripts/gke/cluster-up.sh "$PR_NUMBER" diff --git a/deployment/charts/hapi-fhir/README.md b/deployment/charts/hapi-fhir/README.md index e7bc729a..b06ec775 100644 --- a/deployment/charts/hapi-fhir/README.md +++ b/deployment/charts/hapi-fhir/README.md @@ -8,7 +8,7 @@ PostgreSQL, so a search straight after a write still sees it. | Workload | Image | Service | Storage | | --- | --- | --- | --- | | `hapi-fhir` | `hapiproject/hapi:v8.12.0-2` | `hapi-fhir:8080` | none | -| `hapi-fhir-db` | `postgres:16-alpine` | `hapi-fhir-db:5432` | 10Gi PVC | +| `hapi-fhir-db` | `postgres:18.6-trixie` | `hapi-fhir-db:5432` | 10Gi PVC | | `hapi-fhir-opensearch` | `opensearchproject/opensearch:3.9.0` | `hapi-fhir-opensearch:9200` | 10Gi PVC | ## No templating diff --git a/deployment/charts/hapi-fhir/templates/postgres.yaml b/deployment/charts/hapi-fhir/templates/postgres.yaml index bbfcd245..b0e0aefb 100644 --- a/deployment/charts/hapi-fhir/templates/postgres.yaml +++ b/deployment/charts/hapi-fhir/templates/postgres.yaml @@ -29,7 +29,7 @@ spec: spec: containers: - name: postgres - image: postgres:16-alpine + image: postgres:18.6-trixie # Modest tuning for a single small node. args: - -c diff --git a/deployment/scripts/minimum_deployment.sh b/deployment/scripts/minimum_deployment.sh index 7441d4fc..298bec6f 100755 --- a/deployment/scripts/minimum_deployment.sh +++ b/deployment/scripts/minimum_deployment.sh @@ -12,6 +12,11 @@ # that are missing. OpenSearch users and their passwords come from # deployment/env/authentication.env. # +# Set INGRESS_DOMAIN to publish the three services through the cluster's default +# ingress controller, at hapi., opensearch. and nifi.: +# +# INGRESS_DOMAIN=example.org bash deployment/scripts/minimum_deployment.sh +# # Requirements: kubectl, helm, openssl, htpasswd. set -euo pipefail @@ -71,7 +76,41 @@ kubectl -n "$ns" apply -f rendered/opensearch.yaml helm template cogstack-nifi charts/nifi > rendered/nifi.yaml kubectl -n "$ns" apply -f rendered/nifi.yaml -# --- 3. Status ----------------------------------------------------------------- +# --- 3. Ingress ---------------------------------------------------------------- +# HAPI FHIR and NiFi have no login of their own, so the ingress controller must +# add one if the address is public. Where NetworkPolicy is enforced, NiFi's +# policy admits only NGINX pods and the nifi host will not answer. +ingress() { # ingress + cat < rendered/ingress.yaml + kubectl -n "$ns" apply -f rendered/ingress.yaml +fi + +# --- 4. Status ----------------------------------------------------------------- kubectl -n "$ns" get pods cat <