Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions .github/scripts/gke/README.md
Original file line number Diff line number Diff line change
@@ -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://<app>.pr-<number>.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 <project>` |
| URLs | `https://<service>.pr-<number>.platform.cogstack.dev` for `hapi`, `opensearch`, `nifi` |
| Login | user `admin`; password: `gcloud secrets versions access latest --secret preview-basic-auth-password --project <project>` |
| Auth to Google Cloud | GitHub OIDC (Workload Identity Federation). No keys are stored anywhere. |

## How it works
Expand All @@ -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-<n>.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

Expand Down Expand Up @@ -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.
33 changes: 14 additions & 19 deletions .github/scripts/gke/deploy.sh
Original file line number Diff line number Diff line change
@@ -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 <pr-number> (run cluster-up.sh first)
set -euo pipefail
cd "$(dirname "$0")"
Expand Down Expand Up @@ -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
12 changes: 8 additions & 4 deletions .github/scripts/gke/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ 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"
export CERT_MANAGER_CHART_VERSION="v1.21.3"

# Apps exposed per PR as <name>.pr-<number>.<BASE_DOMAIN>, 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 <number>: derive the per-PR names.
set_pr() {
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/gke/platform.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 3 additions & 6 deletions .github/scripts/gke/pr-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/gke/setup-gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions .github/scripts/gke/teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 0 additions & 69 deletions .github/scripts/gke/values.tmpl.yaml

This file was deleted.

15 changes: 8 additions & 7 deletions .github/workflows/gke_deploy_test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Deploy the PR's cogstack-ce-helm chart to its own GKE cluster and leave it
# running at https://<app>.pr-<number>.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://<service>.pr-<number>.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_*
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion deployment/charts/hapi-fhir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deployment/charts/hapi-fhir/templates/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 40 additions & 1 deletion deployment/scripts/minimum_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.<domain>, opensearch.<domain> and nifi.<domain>:
#
# INGRESS_DOMAIN=example.org bash deployment/scripts/minimum_deployment.sh
#
# Requirements: kubectl, helm, openssl, htpasswd.
set -euo pipefail

Expand Down Expand Up @@ -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 <host prefix> <service> <port>
cat <<EOF
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: $1
spec:
rules:
- host: $1.$INGRESS_DOMAIN
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: $2
port:
number: $3
EOF
}
if [[ -n "${INGRESS_DOMAIN:-}" ]]; then
{
ingress hapi hapi-fhir 8080
ingress opensearch opensearch-cluster-master 9200
ingress nifi cogstack-nifi 8080
} > rendered/ingress.yaml
kubectl -n "$ns" apply -f rendered/ingress.yaml
fi

# --- 4. Status -----------------------------------------------------------------
kubectl -n "$ns" get pods
cat <<EOF

Expand Down
Loading