Skip to content
Merged
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
163 changes: 163 additions & 0 deletions .github/workflows/smoke_nifi_services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
name: smoke-nifi-services

on:
push:
branches: ['**']
paths: &paths
- 'apps/nifi/**'
- 'apps/nginx/**'
- '.github/workflows/smoke_nifi_services.yml'
- '!**/*.md'
- '!**/README*'
pull_request:
paths: *paths
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

defaults:
run:
shell: bash
working-directory: apps/nifi/docker

jobs:
smoke:
name: Build and smoke-test NiFi services
runs-on: ubuntu-24.04
timeout-minutes: 45
env:
COMPOSE_FILE: docker-compose.base.yml:docker-compose.dev.yml
COMPOSE_PROJECT_NAME: nifi-smoke
CERT_DIR: ../../../deployment/security/certificates

steps:
- uses: actions/checkout@v7

- name: Set up Java
uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '21'

- name: Generate smoke fixtures
run: |
scratch_dir="$(mktemp -d)"
trap 'rm -rf "$scratch_dir"' EXIT
mkdir -p "$CERT_DIR"/{root,nifi,nginx} ../env
ca_cert="$CERT_DIR/root/root-ca.pem"
password="$(openssl rand -hex 16)"

openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj '/CN=NiFi smoke CA' \
-addext 'basicConstraints=critical,CA:TRUE' \
-addext 'keyUsage=critical,keyCertSign,cRLSign' \
-keyout "$scratch_dir/ca.key" -out "$ca_cert"

issue_cert() {
local subject="$1" san="$2" key="$3" cert="$4"
openssl req -new -newkey rsa:2048 -nodes -subj "/CN=$subject" \
-keyout "$key" -out "$scratch_dir/leaf.csr"
openssl x509 -req -days 1 -in "$scratch_dir/leaf.csr" \
-CA "$ca_cert" -CAkey "$scratch_dir/ca.key" \
-CAserial "$scratch_dir/ca.srl" -CAcreateserial \
-extfile <(printf 'subjectAltName=%s\nextendedKeyUsage=serverAuth\n' "$san") -out "$cert"
}
issue_cert nifi DNS:nifi "$scratch_dir/nifi.key" "$scratch_dir/nifi.pem"
issue_cert 127.0.0.1 IP:127.0.0.1 "$CERT_DIR/nginx/tls.key" "$CERT_DIR/nginx/tls.crt"

openssl pkcs12 -export -name nifi -inkey "$scratch_dir/nifi.key" \
-in "$scratch_dir/nifi.pem" -certfile "$ca_cert" \
-out "$scratch_dir/nifi.p12" -passout "pass:$password"
keytool -importkeystore -noprompt \
-srckeystore "$scratch_dir/nifi.p12" -srcstoretype PKCS12 -srcstorepass "$password" \
-destkeystore "$CERT_DIR/nifi/nifi-keystore.jks" -deststoretype JKS -deststorepass "$password"
keytool -importcert -noprompt -alias root-ca -file "$ca_cert" \
-keystore "$CERT_DIR/nifi/nifi-truststore.jks" -storetype JKS -storepass "$password"

touch ../env/general.env
cat > ../env/nifi.env <<EOF
NIFI_DOCKER_CPU_MIN=1
NIFI_DOCKER_CPU_MAX=2
NIFI_DOCKER_RAM=4g
NIFI_HEALTHCHECK_HOST=nifi
NIFI_WEB_PROXY_HOST=127.0.0.1:8443
SINGLE_USER_CREDENTIALS_USERNAME=smoke
SINGLE_USER_CREDENTIALS_PASSWORD=$password
NIFI_SENSITIVE_PROPS_KEY=$(openssl rand -hex 16)
KEYSTORE_PATH=/security/certificates/nifi/nifi-keystore.jks
KEYSTORE_TYPE=JKS
KEYSTORE_PASSWORD=$password
TRUSTSTORE_PATH=/security/certificates/nifi/nifi-truststore.jks
TRUSTSTORE_TYPE=JKS
TRUSTSTORE_PASSWORD=$password
EOF

- name: Validate published NGINX startup
run: |
source ./export_env_vars.sh
# The runner owns the temporary NGINX key.
docker compose -p nifi-smoke-published -f docker-compose.yml run --rm --no-deps \
--user "$(id -u):$(id -g)" nifi-nginx nginx -t

- name: Smoke tests
run: |
make start-nifi-dev-build
source ./export_env_vars.sh
url=https://127.0.0.1:8443
request=(curl --silent --show-error --noproxy '*' --cacert "$CERT_DIR/root/root-ca.pem" --connect-timeout 5 --max-time 20)

for route in / /nifi/; do
code="$("${request[@]}" --fail --retry 30 --retry-all-errors --retry-delay 10 --retry-max-time 600 \
--output /dev/null --write-out '%{http_code}' "$url$route")"
case "$code" in
200|301|302|303|307|308) echo "OK: $route returned HTTP $code" ;;
*) echo "Unexpected HTTP $code from $route" >&2; exit 1 ;;
esac
done

for service in nifi nifi-nginx; do
docker compose exec -T "$service" sh -ec 'test "$(id -u)" -ne 0'
done
docker compose exec -T nifi /opt/nifi/scripts/cogstack-healthcheck.sh live
docker compose exec -T nifi /opt/nifi/scripts/cogstack-healthcheck.sh ready
for probe in live ready; do
docker compose exec -T nifi-nginx curl -fsS --output /dev/null "http://127.0.0.1:8080/healthz/$probe"
done

response="$("${request[@]}" --data-urlencode "username=$SINGLE_USER_CREDENTIALS_USERNAME" \
--data-urlencode "password=$SINGLE_USER_CREDENTIALS_PASSWORD" \
--write-out $'\n%{http_code}' "$url/nifi-api/access/token")"
code="${response##*$'\n'}"
token="${response%$'\n'*}"
if [[ "$code" != 201 || -z "$token" ]]; then
echo "NiFi token request returned HTTP $code or an empty token" >&2
exit 1
fi

code="$("${request[@]}" --header "Authorization: Bearer $token" --output /dev/null \
--write-out '%{http_code}' "$url/nifi-api/flow/about")"
if [[ "$code" != 200 ]]; then
echo "Authenticated NiFi API returned HTTP $code" >&2
exit 1
fi
echo 'OK: authenticated NiFi API returned HTTP 200'

- name: Dump container logs
if: failure()
run: |
[[ -f ../env/nifi.env ]] || exit 0
source ./export_env_vars.sh
docker compose ps
docker compose logs --no-color nifi nifi-nginx

- name: Shutdown stack
if: always()
run: |
[[ -f ../env/nifi.env ]] || exit 0
source ./export_env_vars.sh
docker compose down -v
docker compose -p nifi-smoke-published -f docker-compose.yml down
5 changes: 3 additions & 2 deletions apps/cohorter/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# =========================
.env
.env.*
!.env.example
!/env/
/env/*
!/env/cohorter.env
*.key
*.pem
*.p12
Expand Down Expand Up @@ -50,7 +52,6 @@ __pycache__/
*$py.class
.venv/
venv/
env/
pip-wheel-metadata/
.pytest_cache/
.mypy_cache/
Expand Down
8 changes: 4 additions & 4 deletions apps/cohorter/NL2DSL/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This folder contains the **NL2DSL** service for the Cohorter application.

NL2DSL accepts a **natural-language cohort request** and uses an LLM (via **Ollama**) to translate it into a **JSON cohort DSL**. It can optionally call the **MedCAT** service for clinical concept annotation / normalization (depending on your server implementation).

This service is designed to run as part of the full stack (recommended) using the repo-root `docker-compose.yml`.
This service is designed to run as part of the full stack (recommended) using [`docker/docker-compose.yml`](../docker/docker-compose.yml).

---

Expand All @@ -19,10 +19,10 @@ This service is designed to run as part of the full stack (recommended) using th

## Run with Docker Compose (recommended)

From the **repo root**:
From `apps/cohorter/docker/`, using `env/cohorter.env`:

```bash
docker compose up --build nl2dsl
docker compose --env-file ../env/cohorter.env up --build nl2dsl
```

NL2DSL API will be available at:
Expand Down Expand Up @@ -110,7 +110,7 @@ node server.js
### Ollama not reachable
- If using Docker Compose with included Ollama: confirm `ollama` container is up
```bash
docker compose ps
docker compose --env-file ../env/cohorter.env ps
```
- Check Ollama is responding:
```bash
Expand Down
28 changes: 16 additions & 12 deletions apps/cohorter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ A lightweight cohort discovery application that combines:
- `WebAPP/`
Full application (frontend + backend) providing the UI and orchestration of the workflow.

- `docker/`: Docker Compose configuration for the full stack.

---

## Quick start (Docker Compose)
Expand All @@ -27,16 +29,18 @@ A lightweight cohort discovery application that combines:
- (Optional) GPU setup if you want Ollama GPU acceleration (depends on your host OS)

### 1) Build and start all services
From this directory:
From `apps/cohorter/`, configure [`env/cohorter.env`](env/cohorter.env), then run
Compose from `docker/`:

```bash
docker compose up --build
cd docker
docker compose --env-file ../env/cohorter.env up --build
```

Or run in background:

```bash
docker compose up --build -d
docker compose --env-file ../env/cohorter.env up --build -d
```

### 2) Access the app
Expand All @@ -49,7 +53,7 @@ docker compose up --build -d

## Configuration

### NL2DSL environment variables (via docker-compose.yml)
### NL2DSL environment variables (via docker/docker-compose.yml)

NL2DSL uses:
- `OLLAMA_URL` (default in compose: `http://ollama:11434/api/generate`)
Expand All @@ -62,13 +66,13 @@ WebAPP uses:
- `NL2DSL_URL` (default: `http://cohorter-nl2dsl:3002`)

### WebAPP random data generation (optional)
The `WebAPP/Dockerfile` supports a build arg `random` to generate random data:
Set the runtime `RANDOM_DATA` variable to generate random data:

```bash
WEBAPP_RANDOM=true docker compose up --build
RANDOM_DATA=true docker compose --env-file ../env/cohorter.env up --build
```

(If you don’t need random data generation, keep it `false`.)
Set `RANDOM_DATA=false` in `env/cohorter.env` to disable random data generation.

---

Expand All @@ -86,28 +90,28 @@ Each folder contains its own `Dockerfile` and scripts.
## Notes on models and licensing

- MedCAT model packs and any potentially sensitive data **must not** be committed to the repository.
- Ollama models are stored in a Docker named volume by default (`ollama:` in `docker-compose.yml`) so they persist across restarts.
- Ollama models are stored in a Docker named volume by default (`ollama:` in `docker/docker-compose.yml`) so they persist across restarts.

---

## Troubleshooting

### Rebuild everything cleanly
```bash
docker compose down
docker compose up --build
docker compose --env-file ../env/cohorter.env down
docker compose --env-file ../env/cohorter.env up --build
```

### Remove Ollama downloaded models (if needed)
This deletes the named volume that stores Ollama models:

```bash
docker compose down -v
docker compose --env-file ../env/cohorter.env down -v
```

### Check logs
```bash
docker compose logs -f
docker compose --env-file ../env/cohorter.env logs -f
```

---
Expand Down
8 changes: 4 additions & 4 deletions apps/cohorter/WebAPP/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This webapp is a cohort app for users to obtain the number of patients satifying

Other runtime dependencies include [ECharts](https://echarts.apache.org/en/index.html) for charts and [popper.js](https://popper.js.org/) for tooltips.

A GitHub Packages token with `read:packages` scope is required to install `@cogstack/frontend-common-react`. Set it in a `.env` file at the `apps/cohorter/` root (see `.env.example`) or export it in your shell:
A GitHub Packages token with `read:packages` scope is required to install `@cogstack/frontend-common-react`. Set it in [`env/cohorter.env`](../env/cohorter.env) for Compose or export it in your shell:

```bash
export NPM_TOKEN=ghp_your_token_here
Expand Down Expand Up @@ -44,7 +44,7 @@ There is a script `gen_random_data.js` in `server/data/` folder to generate the

Please make sure to have the six data files ready in the `server/data/` folder before starting the server. To start the server, in the app folder run `cd server && npm install && npm run start`.

The recommended way to run the full stack (webapp + NL2DSL + MedCAT + Ollama) is via `docker-compose` from the `apps/cohorter/` root — see the root-level README and `.env.example` for details. The `NPM_TOKEN` is passed as a BuildKit secret; set it in the `.env` file before building.
The recommended way to run the full stack (webapp + NL2DSL + MedCAT + Ollama) uses [`docker/docker-compose.yml`](../docker/docker-compose.yml) from `apps/cohorter/docker/` — see the app-root README and [`env/cohorter.env`](../env/cohorter.env) for details. The `NPM_TOKEN` is passed as a BuildKit secret.

### Environment variables

Expand Down Expand Up @@ -92,10 +92,10 @@ In Kubernetes these are set as env vars on the webapp container (via helm `cogst

### Run using Docker with random data

Set `RANDOM_DATA=true` in your `.env` file (or leave it unset — it defaults to `true`), then from the `apps/cohorter/` root:
Set `RANDOM_DATA=true` in `env/cohorter.env` (or leave it unset — it defaults to `true`), then from `apps/cohorter/docker/`:

```bash
docker compose up --build
docker compose --env-file ../env/cohorter.env up --build
```

The webapp will be available at `http://localhost:3000`.
Expand Down
8 changes: 2 additions & 6 deletions apps/cohorter/WebAPP/client-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ It keeps the existing Alpine-style template/data model behaviour, while using Re

## Requirements

- Node.js 18+
- Node.js 20.12+
- npm
- A GitHub Packages token with `read:packages` scope (to install `@cogstack/frontend-common-react`)
- Cohorter backend server running at `http://localhost:3000` (proxied automatically in dev)

## Environment variables

A single `.env` file at the **`apps/cohorter/` root** (one level up from `WebAPP/`) is shared between Vite and `docker-compose`. Copy `.env.example` there and fill in values:

```bash
cp ../../.env.example ../../.env
```
Configure [`apps/cohorter/env/cohorter.env`](../../env/cohorter.env), shared by Vite and Docker Compose.

| Variable | Required | Description |
|---|---|---|
Expand Down
11 changes: 6 additions & 5 deletions apps/cohorter/WebAPP/client-react/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { existsSync } from 'node:fs';
import { loadEnvFile } from 'node:process';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// Express server port (same origin in production; proxied in dev)
const API_ORIGIN = 'http://localhost:3000';

// Point Vite at the apps/cohorter/ root so that it reads the same .env
// as docker-compose, eliminating the need for a separate client-react/.env.
// Both `npm run dev` (Vite) and `docker-compose build` resolve vars from one file.
const ENV_DIR = '../../';
// Share the named environment file with Compose; image builds can omit it.
const ENV_FILE = new URL('../../env/cohorter.env', import.meta.url);
if (existsSync(ENV_FILE)) loadEnvFile(ENV_FILE);

export default defineConfig({
plugins: [react()],
envDir: ENV_DIR,
envDir: false,

build: {
outDir: 'dist',
Expand Down
Loading