diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ae17d9d3..f118f222 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -27,7 +27,7 @@ updates: # Keep Dockerfile base images up to date - package-ecosystem: "docker" - directory: "/apps/cogstack-jupyter-hub" + directory: "/apps/jupyter-hub" schedule: interval: "monthly" registries: @@ -41,7 +41,7 @@ updates: # Keep uv.lock Python dependencies up to date - package-ecosystem: "uv" - directory: "/apps/cogstack-jupyter-hub" + directory: "/apps/jupyter-hub" schedule: interval: "monthly" commit-message: diff --git a/.github/workflows/build_helm_charts.yml b/.github/workflows/build_helm_charts.yml index 7a23d39a..282ecd4b 100644 --- a/.github/workflows/build_helm_charts.yml +++ b/.github/workflows/build_helm_charts.yml @@ -153,15 +153,22 @@ jobs: - name: Discover charts id: charts run: | - if [[ "${{ steps.version.outputs.single_chart }}" == "true" ]]; then - echo "charts=${{ steps.version.outputs.chart }}" >> "$GITHUB_OUTPUT" - else - CHARTS=() - while IFS= read -r chartfile; do - CHARTS+=("$(basename "$(dirname "$chartfile")")") - done < <(find . -maxdepth 2 -mindepth 2 -type f -name Chart.yaml | sort) - echo "charts=${CHARTS[*]}" >> "$GITHUB_OUTPUT" + CHARTS=() + while IFS= read -r chartfile; do + CHART_DIR="$(dirname "$chartfile")" + if [[ "${{ steps.version.outputs.single_chart }}" == "true" ]]; then + CHART_NAME="$(helm show chart "$CHART_DIR" | awk '/^name:/ {print $2; exit}')" + if [[ "$CHART_NAME" != "${{ steps.version.outputs.chart }}" ]]; then + continue + fi + fi + CHARTS+=("$(basename "$CHART_DIR")") + done < <(find . -maxdepth 2 -mindepth 2 -type f -name Chart.yaml | sort) + if [[ "${{ steps.version.outputs.single_chart }}" == "true" && "${#CHARTS[@]}" != 1 ]]; then + echo "Expected exactly one chart named ${{ steps.version.outputs.chart }}; found ${#CHARTS[@]}." >&2 + exit 1 fi + echo "charts=${CHARTS[*]}" >> "$GITHUB_OUTPUT" - name: Recursive dependency update (all charts, including nested) # Waiting on helm recursive feature https://github.com/helm/helm/pull/30855 @@ -182,7 +189,8 @@ jobs: run: | VERSION="${{ steps.version.outputs.chart_version }}" for CHART in ${{ steps.charts.outputs.charts }}; do - helm push "./$CHART-$VERSION.tgz" oci://registry-1.docker.io/cogstacksystems + CHART_NAME="$(helm show chart "./$CHART" | awk '/^name:/ {print $2; exit}')" + helm push "./$CHART_NAME-$VERSION.tgz" oci://registry-1.docker.io/cogstacksystems done - name: Attach chart to GitHub Release @@ -190,4 +198,4 @@ jobs: if: github.ref_type == 'tag' with: tag_name: ${{ github.ref_name }} - files: deployment/charts/${{ steps.charts.outputs.chart }}-${{ steps.version.outputs.chart_version }}.tgz + files: deployment/charts/${{ steps.version.outputs.chart }}-${{ steps.version.outputs.chart_version }}.tgz diff --git a/.github/workflows/docker_build_cohorter.yml b/.github/workflows/docker_build_cohorter.yml index 2a9f524e..0f9c756e 100644 --- a/.github/workflows/docker_build_cohorter.yml +++ b/.github/workflows/docker_build_cohorter.yml @@ -6,11 +6,11 @@ on: tags: - "cohorter-v*.*.*" # e.g., cohorter-v1.2.3 paths: - - "apps/cogstack-cohorter/**" + - "apps/cohorter/**" - ".github/workflows/docker_build_cohorter.yml" pull_request: paths: - - "apps/cogstack-cohorter/**" + - "apps/cohorter/**" - ".github/workflows/docker_build_cohorter.yml" jobs: @@ -24,13 +24,13 @@ jobs: matrix: include: - name: nl2dsl - context: apps/cogstack-cohorter/NL2DSL - dockerfile: apps/cogstack-cohorter/NL2DSL/Dockerfile + context: apps/cohorter/NL2DSL + dockerfile: apps/cohorter/NL2DSL/Dockerfile image: cogstacksystems/cogstack-cohorter-nl2dsl - name: webapp - context: apps/cogstack-cohorter/WebAPP - dockerfile: apps/cogstack-cohorter/WebAPP/Dockerfile + context: apps/cohorter/WebAPP + dockerfile: apps/cohorter/WebAPP/Dockerfile image: cogstacksystems/cogstack-cohorter-webapp steps: diff --git a/.github/workflows/docker_build_jupyterhub.yml b/.github/workflows/docker_build_jupyterhub.yml index de3fa06a..210efca4 100644 --- a/.github/workflows/docker_build_jupyterhub.yml +++ b/.github/workflows/docker_build_jupyterhub.yml @@ -8,11 +8,11 @@ on: branches: [main] tags: ['cogstack-jupyter-hub-v*.*.*'] paths: - - "apps/cogstack-jupyter-hub/**" + - "apps/jupyter-hub/**" - ".github/workflows/docker_build_jupyterhub.yml" pull_request: paths: - - "apps/cogstack-jupyter-hub/**" + - "apps/jupyter-hub/**" - ".github/workflows/docker_build_jupyterhub.yml" workflow_dispatch: @@ -72,8 +72,8 @@ jobs: id: hub uses: docker/build-push-action@v7 with: - context: apps/cogstack-jupyter-hub - file: apps/cogstack-jupyter-hub/Dockerfile_hub + context: apps/jupyter-hub + file: apps/jupyter-hub/Dockerfile_hub platforms: linux/amd64 build-args: | CPU_ARCHITECTURE=amd64 @@ -90,8 +90,8 @@ jobs: id: su uses: docker/build-push-action@v7 with: - context: apps/cogstack-jupyter-hub - file: apps/cogstack-jupyter-hub/Dockerfile_singleuser + context: apps/jupyter-hub + file: apps/jupyter-hub/Dockerfile_singleuser platforms: linux/amd64 build-args: | CPU_ARCHITECTURE=amd64 @@ -156,8 +156,8 @@ jobs: id: hub uses: docker/build-push-action@v7 with: - context: apps/cogstack-jupyter-hub - file: apps/cogstack-jupyter-hub/Dockerfile_hub + context: apps/jupyter-hub + file: apps/jupyter-hub/Dockerfile_hub platforms: linux/arm64 build-args: | CPU_ARCHITECTURE=arm64 @@ -173,8 +173,8 @@ jobs: id: su uses: docker/build-push-action@v7 with: - context: apps/cogstack-jupyter-hub - file: apps/cogstack-jupyter-hub/Dockerfile_singleuser + context: apps/jupyter-hub + file: apps/jupyter-hub/Dockerfile_singleuser platforms: linux/arm64 build-args: | CPU_ARCHITECTURE=arm64 @@ -224,8 +224,8 @@ jobs: - name: Build & push singleuser GPU (amd64) uses: docker/build-push-action@v7 with: - context: apps/cogstack-jupyter-hub - file: apps/cogstack-jupyter-hub/Dockerfile_singleuser + context: apps/jupyter-hub + file: apps/jupyter-hub/Dockerfile_singleuser platforms: linux/amd64 build-args: | CPU_ARCHITECTURE=amd64 diff --git a/.github/workflows/docker_smoke_jupyterhub.yml b/.github/workflows/docker_smoke_jupyterhub.yml index 7c63a9ed..76fcfe55 100644 --- a/.github/workflows/docker_smoke_jupyterhub.yml +++ b/.github/workflows/docker_smoke_jupyterhub.yml @@ -8,11 +8,11 @@ on: branches: [main] tags: ['cogstack-jupyter-hub-v*.*.*'] paths: - - "apps/cogstack-jupyter-hub/**" + - "apps/jupyter-hub/**" - ".github/workflows/docker_smoke_jupyterhub.yml" pull_request: paths: - - "apps/cogstack-jupyter-hub/**" + - "apps/jupyter-hub/**" - ".github/workflows/docker_smoke_jupyterhub.yml" workflow_dispatch: @@ -22,7 +22,7 @@ concurrency: defaults: run: - working-directory: apps/cogstack-jupyter-hub + working-directory: apps/jupyter-hub jobs: smoke: diff --git a/.gitignore b/.gitignore index e88da896..9a5b035e 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,9 @@ __pycache__/ *.py[cod] *$py.class +# Python type stubs +*.pyi + # C extensions *.so diff --git a/.release-please-manifest.json b/.release-please-manifest.json index aa38ec7a..3931c6dc 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,12 +1,14 @@ { - "deployment/charts/medcat-service-helm": "0.6.0", - "deployment/charts/medcat-trainer-helm": "0.5.2", - "deployment/charts/cogstack-ce-helm": "0.7.1", - "deployment/charts/cogstack-cohorter-helm": "0.5.0", - "deployment/charts/cogstack-observability-helm": "0.4.1", - "deployment/charts/cogstack-jupyterhub-helm": "0.5.0", - "deployment/charts/ocr-service-helm": "0.1.0", + "deployment/charts/medcat-service": "0.6.0", + "deployment/charts/medcat-trainer": "0.5.2", + "deployment/charts/ce": "0.7.1", + "deployment/charts/cohorter": "0.5.0", + "deployment/charts/observability": "0.4.1", + "deployment/charts/jupyterhub": "0.5.0", + "deployment/charts/ocr-service": "0.1.0", + "deployment/charts/nifi": "0.0.0", + "deployment/charts/nginx": "0.0.0", "deployment/terraform/openstack-kubernetes-k3s": "0.1.2", "apps/ocr-service": "1.1.4", - "apps/cogstack-jupyter-hub": "2.3.10" + "apps/jupyter-hub": "2.3.10" } diff --git a/README.md b/README.md index 5b1c7c4d..c50293fc 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ See the latest documentation on [Readthedocs](https://docs.cogstack.org/en/lates Document and image text extraction built on Tesseract OCR - + CogStack Jupyter Hub
CogStack Jupyter Hub
@@ -51,7 +51,7 @@ See the latest documentation on [Readthedocs](https://docs.cogstack.org/en/lates - + CogStack Cohorter
CogStack Cohorter
@@ -59,7 +59,7 @@ See the latest documentation on [Readthedocs](https://docs.cogstack.org/en/lates Cohort definition tooling with NL2DSL and web UI - + CogStack Dashboards Demo
CogStack Dashboards Demo
@@ -69,6 +69,9 @@ See the latest documentation on [Readthedocs](https://docs.cogstack.org/en/lates +See [CogStack NiFi](apps/nifi/README.md) for the ingestion image, Python +processors, JDBC drivers and flow templates. + ### Tools - Source for the official cogstack documentation. This git repo stores the top level documetation that hosts on https://docs.cogstack.org - CogStack deployment instructions and examples diff --git a/apps/cogstack-cohorter/.env.example b/apps/cohorter/.env.example similarity index 100% rename from apps/cogstack-cohorter/.env.example rename to apps/cohorter/.env.example diff --git a/apps/cogstack-cohorter/.gitignore b/apps/cohorter/.gitignore similarity index 100% rename from apps/cogstack-cohorter/.gitignore rename to apps/cohorter/.gitignore diff --git a/apps/cogstack-cohorter/NL2DSL/.dockerignore b/apps/cohorter/NL2DSL/.dockerignore similarity index 100% rename from apps/cogstack-cohorter/NL2DSL/.dockerignore rename to apps/cohorter/NL2DSL/.dockerignore diff --git a/apps/cogstack-cohorter/NL2DSL/.gitignore b/apps/cohorter/NL2DSL/.gitignore similarity index 100% rename from apps/cogstack-cohorter/NL2DSL/.gitignore rename to apps/cohorter/NL2DSL/.gitignore diff --git a/apps/cogstack-cohorter/NL2DSL/Dockerfile b/apps/cohorter/NL2DSL/Dockerfile similarity index 100% rename from apps/cogstack-cohorter/NL2DSL/Dockerfile rename to apps/cohorter/NL2DSL/Dockerfile diff --git a/apps/cogstack-cohorter/NL2DSL/README.md b/apps/cohorter/NL2DSL/README.md similarity index 100% rename from apps/cogstack-cohorter/NL2DSL/README.md rename to apps/cohorter/NL2DSL/README.md diff --git a/apps/cogstack-cohorter/NL2DSL/docker_build.sh b/apps/cohorter/NL2DSL/docker_build.sh similarity index 100% rename from apps/cogstack-cohorter/NL2DSL/docker_build.sh rename to apps/cohorter/NL2DSL/docker_build.sh diff --git a/apps/cogstack-cohorter/NL2DSL/docker_run.sh b/apps/cohorter/NL2DSL/docker_run.sh similarity index 100% rename from apps/cogstack-cohorter/NL2DSL/docker_run.sh rename to apps/cohorter/NL2DSL/docker_run.sh diff --git a/apps/cogstack-cohorter/NL2DSL/package-lock.json b/apps/cohorter/NL2DSL/package-lock.json similarity index 100% rename from apps/cogstack-cohorter/NL2DSL/package-lock.json rename to apps/cohorter/NL2DSL/package-lock.json diff --git a/apps/cogstack-cohorter/NL2DSL/package.json b/apps/cohorter/NL2DSL/package.json similarity index 100% rename from apps/cogstack-cohorter/NL2DSL/package.json rename to apps/cohorter/NL2DSL/package.json diff --git a/apps/cogstack-cohorter/NL2DSL/public/index.html b/apps/cohorter/NL2DSL/public/index.html similarity index 100% rename from apps/cogstack-cohorter/NL2DSL/public/index.html rename to apps/cohorter/NL2DSL/public/index.html diff --git a/apps/cogstack-cohorter/NL2DSL/server.js b/apps/cohorter/NL2DSL/server.js similarity index 100% rename from apps/cogstack-cohorter/NL2DSL/server.js rename to apps/cohorter/NL2DSL/server.js diff --git a/apps/cogstack-cohorter/README.md b/apps/cohorter/README.md similarity index 100% rename from apps/cogstack-cohorter/README.md rename to apps/cohorter/README.md diff --git a/apps/cogstack-cohorter/WebAPP/.dockerignore b/apps/cohorter/WebAPP/.dockerignore similarity index 100% rename from apps/cogstack-cohorter/WebAPP/.dockerignore rename to apps/cohorter/WebAPP/.dockerignore diff --git a/apps/cogstack-cohorter/WebAPP/.gitignore b/apps/cohorter/WebAPP/.gitignore similarity index 100% rename from apps/cogstack-cohorter/WebAPP/.gitignore rename to apps/cohorter/WebAPP/.gitignore diff --git a/apps/cogstack-cohorter/WebAPP/Dockerfile b/apps/cohorter/WebAPP/Dockerfile similarity index 100% rename from apps/cogstack-cohorter/WebAPP/Dockerfile rename to apps/cohorter/WebAPP/Dockerfile diff --git a/apps/cogstack-cohorter/WebAPP/LICENSE b/apps/cohorter/WebAPP/LICENSE similarity index 100% rename from apps/cogstack-cohorter/WebAPP/LICENSE rename to apps/cohorter/WebAPP/LICENSE diff --git a/apps/cogstack-cohorter/WebAPP/README.md b/apps/cohorter/WebAPP/README.md similarity index 96% rename from apps/cogstack-cohorter/WebAPP/README.md rename to apps/cohorter/WebAPP/README.md index 17a4c2c5..9b9e9153 100644 --- a/apps/cogstack-cohorter/WebAPP/README.md +++ b/apps/cohorter/WebAPP/README.md @@ -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/cogstack-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 a `.env` file at the `apps/cohorter/` root (see `.env.example`) or export it in your shell: ```bash export NPM_TOKEN=ghp_your_token_here @@ -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/cogstack-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) 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. ### Environment variables @@ -92,7 +92,7 @@ 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/cogstack-cohorter/` root: +Set `RANDOM_DATA=true` in your `.env` file (or leave it unset — it defaults to `true`), then from the `apps/cohorter/` root: ```bash docker compose up --build diff --git a/apps/cogstack-cohorter/WebAPP/client-react/README.md b/apps/cohorter/WebAPP/client-react/README.md similarity index 96% rename from apps/cogstack-cohorter/WebAPP/client-react/README.md rename to apps/cohorter/WebAPP/client-react/README.md index bf412ae7..65c19739 100644 --- a/apps/cogstack-cohorter/WebAPP/client-react/README.md +++ b/apps/cohorter/WebAPP/client-react/README.md @@ -21,7 +21,7 @@ It keeps the existing Alpine-style template/data model behaviour, while using Re ## Environment variables -A single `.env` file at the **`apps/cogstack-cohorter/` root** (one level up from `WebAPP/`) is shared between Vite and `docker-compose`. Copy `.env.example` there and fill in values: +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 diff --git a/apps/cogstack-cohorter/WebAPP/client-react/index.html b/apps/cohorter/WebAPP/client-react/index.html similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/index.html rename to apps/cohorter/WebAPP/client-react/index.html diff --git a/apps/cogstack-cohorter/WebAPP/client-react/package-lock.json b/apps/cohorter/WebAPP/client-react/package-lock.json similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/package-lock.json rename to apps/cohorter/WebAPP/client-react/package-lock.json diff --git a/apps/cogstack-cohorter/WebAPP/client-react/package.json b/apps/cohorter/WebAPP/client-react/package.json similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/package.json rename to apps/cohorter/WebAPP/client-react/package.json diff --git a/apps/cogstack-cohorter/WebAPP/client-react/postcss.config.js b/apps/cohorter/WebAPP/client-react/postcss.config.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/postcss.config.js rename to apps/cohorter/WebAPP/client-react/postcss.config.js diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/app-template.html b/apps/cohorter/WebAPP/client-react/public/app-template.html similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/app-template.html rename to apps/cohorter/WebAPP/client-react/public/app-template.html diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/assets/Cogstack-Logo-Landcape-Dark.svg b/apps/cohorter/WebAPP/client-react/public/assets/Cogstack-Logo-Landcape-Dark.svg similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/assets/Cogstack-Logo-Landcape-Dark.svg rename to apps/cohorter/WebAPP/client-react/public/assets/Cogstack-Logo-Landcape-Dark.svg diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/assets/Cogstack-Logo.svg b/apps/cohorter/WebAPP/client-react/public/assets/Cogstack-Logo.svg similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/assets/Cogstack-Logo.svg rename to apps/cohorter/WebAPP/client-react/public/assets/Cogstack-Logo.svg diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/assets/css/google.fonts.css b/apps/cohorter/WebAPP/client-react/public/assets/css/google.fonts.css similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/assets/css/google.fonts.css rename to apps/cohorter/WebAPP/client-react/public/assets/css/google.fonts.css diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/assets/css/tailwind.css b/apps/cohorter/WebAPP/client-react/public/assets/css/tailwind.css similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/assets/css/tailwind.css rename to apps/cohorter/WebAPP/client-react/public/assets/css/tailwind.css diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/assets/css/tailwind.output.css b/apps/cohorter/WebAPP/client-react/public/assets/css/tailwind.output.css similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/assets/css/tailwind.output.css rename to apps/cohorter/WebAPP/client-react/public/assets/css/tailwind.output.css diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/assets/js/alpine.3.10.5.js b/apps/cohorter/WebAPP/client-react/public/assets/js/alpine.3.10.5.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/assets/js/alpine.3.10.5.js rename to apps/cohorter/WebAPP/client-react/public/assets/js/alpine.3.10.5.js diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/assets/js/echarts.min.js b/apps/cohorter/WebAPP/client-react/public/assets/js/echarts.min.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/assets/js/echarts.min.js rename to apps/cohorter/WebAPP/client-react/public/assets/js/echarts.min.js diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/assets/js/init-alpine.js b/apps/cohorter/WebAPP/client-react/public/assets/js/init-alpine.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/assets/js/init-alpine.js rename to apps/cohorter/WebAPP/client-react/public/assets/js/init-alpine.js diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/assets/js/popper.min.js b/apps/cohorter/WebAPP/client-react/public/assets/js/popper.min.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/assets/js/popper.min.js rename to apps/cohorter/WebAPP/client-react/public/assets/js/popper.min.js diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/assets/js/popper.min.js.map b/apps/cohorter/WebAPP/client-react/public/assets/js/popper.min.js.map similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/assets/js/popper.min.js.map rename to apps/cohorter/WebAPP/client-react/public/assets/js/popper.min.js.map diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/components/busy-pill.html b/apps/cohorter/WebAPP/client-react/public/components/busy-pill.html similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/components/busy-pill.html rename to apps/cohorter/WebAPP/client-react/public/components/busy-pill.html diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/components/query-nl.html b/apps/cohorter/WebAPP/client-react/public/components/query-nl.html similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/components/query-nl.html rename to apps/cohorter/WebAPP/client-react/public/components/query-nl.html diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/components/query-v1.html b/apps/cohorter/WebAPP/client-react/public/components/query-v1.html similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/components/query-v1.html rename to apps/cohorter/WebAPP/client-react/public/components/query-v1.html diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/components/results-main.html b/apps/cohorter/WebAPP/client-react/public/components/results-main.html similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/components/results-main.html rename to apps/cohorter/WebAPP/client-react/public/components/results-main.html diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/components/sidebar-desktop.html b/apps/cohorter/WebAPP/client-react/public/components/sidebar-desktop.html similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/components/sidebar-desktop.html rename to apps/cohorter/WebAPP/client-react/public/components/sidebar-desktop.html diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/components/sidebar-mobile.html b/apps/cohorter/WebAPP/client-react/public/components/sidebar-mobile.html similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/components/sidebar-mobile.html rename to apps/cohorter/WebAPP/client-react/public/components/sidebar-mobile.html diff --git a/apps/cogstack-cohorter/WebAPP/client-react/public/index.html b/apps/cohorter/WebAPP/client-react/public/index.html similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/public/index.html rename to apps/cohorter/WebAPP/client-react/public/index.html diff --git a/apps/cogstack-cohorter/WebAPP/client-react/src/AdminLoginDialog.jsx b/apps/cohorter/WebAPP/client-react/src/AdminLoginDialog.jsx similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/src/AdminLoginDialog.jsx rename to apps/cohorter/WebAPP/client-react/src/AdminLoginDialog.jsx diff --git a/apps/cogstack-cohorter/WebAPP/client-react/src/App.jsx b/apps/cohorter/WebAPP/client-react/src/App.jsx similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/src/App.jsx rename to apps/cohorter/WebAPP/client-react/src/App.jsx diff --git a/apps/cogstack-cohorter/WebAPP/client-react/src/FilterSidebar.jsx b/apps/cohorter/WebAPP/client-react/src/FilterSidebar.jsx similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/src/FilterSidebar.jsx rename to apps/cohorter/WebAPP/client-react/src/FilterSidebar.jsx diff --git a/apps/cogstack-cohorter/WebAPP/client-react/src/HeaderControls.jsx b/apps/cohorter/WebAPP/client-react/src/HeaderControls.jsx similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/src/HeaderControls.jsx rename to apps/cohorter/WebAPP/client-react/src/HeaderControls.jsx diff --git a/apps/cogstack-cohorter/WebAPP/client-react/src/LoadQueryDialog.jsx b/apps/cohorter/WebAPP/client-react/src/LoadQueryDialog.jsx similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/src/LoadQueryDialog.jsx rename to apps/cohorter/WebAPP/client-react/src/LoadQueryDialog.jsx diff --git a/apps/cogstack-cohorter/WebAPP/client-react/src/alpine-data.js b/apps/cohorter/WebAPP/client-react/src/alpine-data.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/src/alpine-data.js rename to apps/cohorter/WebAPP/client-react/src/alpine-data.js diff --git a/apps/cogstack-cohorter/WebAPP/client-react/src/alpine-runtime.js b/apps/cohorter/WebAPP/client-react/src/alpine-runtime.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/src/alpine-runtime.js rename to apps/cohorter/WebAPP/client-react/src/alpine-runtime.js diff --git a/apps/cogstack-cohorter/WebAPP/client-react/src/index.css b/apps/cohorter/WebAPP/client-react/src/index.css similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/src/index.css rename to apps/cohorter/WebAPP/client-react/src/index.css diff --git a/apps/cogstack-cohorter/WebAPP/client-react/src/main.jsx b/apps/cohorter/WebAPP/client-react/src/main.jsx similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/src/main.jsx rename to apps/cohorter/WebAPP/client-react/src/main.jsx diff --git a/apps/cogstack-cohorter/WebAPP/client-react/src/template-components.js b/apps/cohorter/WebAPP/client-react/src/template-components.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/src/template-components.js rename to apps/cohorter/WebAPP/client-react/src/template-components.js diff --git a/apps/cogstack-cohorter/WebAPP/client-react/tailwind.config.js b/apps/cohorter/WebAPP/client-react/tailwind.config.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/client-react/tailwind.config.js rename to apps/cohorter/WebAPP/client-react/tailwind.config.js diff --git a/apps/cogstack-cohorter/WebAPP/client-react/vite.config.js b/apps/cohorter/WebAPP/client-react/vite.config.js similarity index 94% rename from apps/cogstack-cohorter/WebAPP/client-react/vite.config.js rename to apps/cohorter/WebAPP/client-react/vite.config.js index b6fe8cc7..a2c57ea7 100644 --- a/apps/cogstack-cohorter/WebAPP/client-react/vite.config.js +++ b/apps/cohorter/WebAPP/client-react/vite.config.js @@ -4,7 +4,7 @@ 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/cogstack-cohorter/ root so that it reads the same .env +// 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 = '../../'; diff --git a/apps/cogstack-cohorter/WebAPP/docker_build.sh b/apps/cohorter/WebAPP/docker_build.sh similarity index 100% rename from apps/cogstack-cohorter/WebAPP/docker_build.sh rename to apps/cohorter/WebAPP/docker_build.sh diff --git a/apps/cogstack-cohorter/WebAPP/docker_run.sh b/apps/cohorter/WebAPP/docker_run.sh similarity index 100% rename from apps/cogstack-cohorter/WebAPP/docker_run.sh rename to apps/cohorter/WebAPP/docker_run.sh diff --git a/apps/cogstack-cohorter/WebAPP/entrypoint.sh b/apps/cohorter/WebAPP/entrypoint.sh similarity index 100% rename from apps/cogstack-cohorter/WebAPP/entrypoint.sh rename to apps/cohorter/WebAPP/entrypoint.sh diff --git a/apps/cogstack-cohorter/WebAPP/server/data-example/cui_pt2ch_example.json b/apps/cohorter/WebAPP/server/data-example/cui_pt2ch_example.json similarity index 100% rename from apps/cogstack-cohorter/WebAPP/server/data-example/cui_pt2ch_example.json rename to apps/cohorter/WebAPP/server/data-example/cui_pt2ch_example.json diff --git a/apps/cogstack-cohorter/WebAPP/server/data-example/snomed_example.json b/apps/cohorter/WebAPP/server/data-example/snomed_example.json similarity index 100% rename from apps/cogstack-cohorter/WebAPP/server/data-example/snomed_example.json rename to apps/cohorter/WebAPP/server/data-example/snomed_example.json diff --git a/apps/cogstack-cohorter/WebAPP/server/gen_random_data.js b/apps/cohorter/WebAPP/server/gen_random_data.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/server/gen_random_data.js rename to apps/cohorter/WebAPP/server/gen_random_data.js diff --git a/apps/cogstack-cohorter/WebAPP/server/package-lock.json b/apps/cohorter/WebAPP/server/package-lock.json similarity index 100% rename from apps/cogstack-cohorter/WebAPP/server/package-lock.json rename to apps/cohorter/WebAPP/server/package-lock.json diff --git a/apps/cogstack-cohorter/WebAPP/server/package.json b/apps/cohorter/WebAPP/server/package.json similarity index 100% rename from apps/cogstack-cohorter/WebAPP/server/package.json rename to apps/cohorter/WebAPP/server/package.json diff --git a/apps/cogstack-cohorter/WebAPP/server/server.js b/apps/cohorter/WebAPP/server/server.js similarity index 100% rename from apps/cogstack-cohorter/WebAPP/server/server.js rename to apps/cohorter/WebAPP/server/server.js diff --git a/apps/cogstack-cohorter/cohorter.gif b/apps/cohorter/cohorter.gif similarity index 100% rename from apps/cogstack-cohorter/cohorter.gif rename to apps/cohorter/cohorter.gif diff --git a/apps/cogstack-cohorter/docker-compose.yml b/apps/cohorter/docker-compose.yml similarity index 100% rename from apps/cogstack-cohorter/docker-compose.yml rename to apps/cohorter/docker-compose.yml diff --git a/apps/cogstack-dashboards-demo/.gitignore b/apps/dashboards-demo/.gitignore similarity index 100% rename from apps/cogstack-dashboards-demo/.gitignore rename to apps/dashboards-demo/.gitignore diff --git a/apps/cogstack-dashboards-demo/LICENSE b/apps/dashboards-demo/LICENSE similarity index 100% rename from apps/cogstack-dashboards-demo/LICENSE rename to apps/dashboards-demo/LICENSE diff --git a/apps/cogstack-dashboards-demo/README.md b/apps/dashboards-demo/README.md similarity index 100% rename from apps/cogstack-dashboards-demo/README.md rename to apps/dashboards-demo/README.md diff --git a/apps/cogstack-dashboards-demo/data/.gitkeep b/apps/dashboards-demo/data/.gitkeep similarity index 100% rename from apps/cogstack-dashboards-demo/data/.gitkeep rename to apps/dashboards-demo/data/.gitkeep diff --git a/apps/cogstack-dashboards-demo/figures/clusters.png b/apps/dashboards-demo/figures/clusters.png similarity index 100% rename from apps/cogstack-dashboards-demo/figures/clusters.png rename to apps/dashboards-demo/figures/clusters.png diff --git a/apps/cogstack-dashboards-demo/figures/disorder_per_age.png b/apps/dashboards-demo/figures/disorder_per_age.png similarity index 100% rename from apps/cogstack-dashboards-demo/figures/disorder_per_age.png rename to apps/dashboards-demo/figures/disorder_per_age.png diff --git a/apps/cogstack-dashboards-demo/figures/disorder_per_gender.png b/apps/dashboards-demo/figures/disorder_per_gender.png similarity index 100% rename from apps/cogstack-dashboards-demo/figures/disorder_per_gender.png rename to apps/dashboards-demo/figures/disorder_per_gender.png diff --git a/apps/cogstack-dashboards-demo/figures/handpicked_co_occurrences.png b/apps/dashboards-demo/figures/handpicked_co_occurrences.png similarity index 100% rename from apps/cogstack-dashboards-demo/figures/handpicked_co_occurrences.png rename to apps/dashboards-demo/figures/handpicked_co_occurrences.png diff --git a/apps/cogstack-dashboards-demo/figures/presence.png b/apps/dashboards-demo/figures/presence.png similarity index 100% rename from apps/cogstack-dashboards-demo/figures/presence.png rename to apps/dashboards-demo/figures/presence.png diff --git a/apps/cogstack-dashboards-demo/figures/subject.png b/apps/dashboards-demo/figures/subject.png similarity index 100% rename from apps/cogstack-dashboards-demo/figures/subject.png rename to apps/dashboards-demo/figures/subject.png diff --git a/apps/cogstack-dashboards-demo/figures/time.png b/apps/dashboards-demo/figures/time.png similarity index 100% rename from apps/cogstack-dashboards-demo/figures/time.png rename to apps/dashboards-demo/figures/time.png diff --git a/apps/cogstack-dashboards-demo/figures/top_level_concepts.png b/apps/dashboards-demo/figures/top_level_concepts.png similarity index 100% rename from apps/cogstack-dashboards-demo/figures/top_level_concepts.png rename to apps/dashboards-demo/figures/top_level_concepts.png diff --git a/apps/cogstack-dashboards-demo/requirements.txt b/apps/dashboards-demo/requirements.txt similarity index 100% rename from apps/cogstack-dashboards-demo/requirements.txt rename to apps/dashboards-demo/requirements.txt diff --git a/apps/cogstack-dashboards-demo/sample_access_scripts/python_os_access.py b/apps/dashboards-demo/sample_access_scripts/python_os_access.py similarity index 100% rename from apps/cogstack-dashboards-demo/sample_access_scripts/python_os_access.py rename to apps/dashboards-demo/sample_access_scripts/python_os_access.py diff --git a/apps/cogstack-dashboards-demo/sample_access_scripts/sample_curl_command.sh b/apps/dashboards-demo/sample_access_scripts/sample_curl_command.sh similarity index 100% rename from apps/cogstack-dashboards-demo/sample_access_scripts/sample_curl_command.sh rename to apps/dashboards-demo/sample_access_scripts/sample_curl_command.sh diff --git a/apps/cogstack-dashboards-demo/staging_scripts/co_occurence_generator.py b/apps/dashboards-demo/staging_scripts/co_occurence_generator.py similarity index 100% rename from apps/cogstack-dashboards-demo/staging_scripts/co_occurence_generator.py rename to apps/dashboards-demo/staging_scripts/co_occurence_generator.py diff --git a/apps/cogstack-dashboards-demo/staging_scripts/co_occurence_hand_selected.py b/apps/dashboards-demo/staging_scripts/co_occurence_hand_selected.py similarity index 100% rename from apps/cogstack-dashboards-demo/staging_scripts/co_occurence_hand_selected.py rename to apps/dashboards-demo/staging_scripts/co_occurence_hand_selected.py diff --git a/apps/cogstack-dashboards-demo/staging_scripts/disorder_codes.py b/apps/dashboards-demo/staging_scripts/disorder_codes.py similarity index 100% rename from apps/cogstack-dashboards-demo/staging_scripts/disorder_codes.py rename to apps/dashboards-demo/staging_scripts/disorder_codes.py diff --git a/apps/cogstack-dashboards-demo/staging_scripts/disorders_per_age.py b/apps/dashboards-demo/staging_scripts/disorders_per_age.py similarity index 100% rename from apps/cogstack-dashboards-demo/staging_scripts/disorders_per_age.py rename to apps/dashboards-demo/staging_scripts/disorders_per_age.py diff --git a/apps/cogstack-dashboards-demo/staging_scripts/disorders_per_sex.py b/apps/dashboards-demo/staging_scripts/disorders_per_sex.py similarity index 100% rename from apps/cogstack-dashboards-demo/staging_scripts/disorders_per_sex.py rename to apps/dashboards-demo/staging_scripts/disorders_per_sex.py diff --git a/apps/cogstack-dashboards-demo/staging_scripts/patients_per_disorder.py b/apps/dashboards-demo/staging_scripts/patients_per_disorder.py similarity index 100% rename from apps/cogstack-dashboards-demo/staging_scripts/patients_per_disorder.py rename to apps/dashboards-demo/staging_scripts/patients_per_disorder.py diff --git a/apps/cogstack-dashboards-demo/staging_scripts/top_level_codes.py b/apps/dashboards-demo/staging_scripts/top_level_codes.py similarity index 100% rename from apps/cogstack-dashboards-demo/staging_scripts/top_level_codes.py rename to apps/dashboards-demo/staging_scripts/top_level_codes.py diff --git a/apps/cogstack-dashboards-demo/visualisation_scripts/generate_meta_images.py b/apps/dashboards-demo/visualisation_scripts/generate_meta_images.py similarity index 100% rename from apps/cogstack-dashboards-demo/visualisation_scripts/generate_meta_images.py rename to apps/dashboards-demo/visualisation_scripts/generate_meta_images.py diff --git a/apps/cogstack-dashboards-demo/visualisation_scripts/pca_co_occurence.py b/apps/dashboards-demo/visualisation_scripts/pca_co_occurence.py similarity index 100% rename from apps/cogstack-dashboards-demo/visualisation_scripts/pca_co_occurence.py rename to apps/dashboards-demo/visualisation_scripts/pca_co_occurence.py diff --git a/apps/cogstack-dashboards-demo/visualisation_scripts/vis_disorder_per_age.py b/apps/dashboards-demo/visualisation_scripts/vis_disorder_per_age.py similarity index 100% rename from apps/cogstack-dashboards-demo/visualisation_scripts/vis_disorder_per_age.py rename to apps/dashboards-demo/visualisation_scripts/vis_disorder_per_age.py diff --git a/apps/cogstack-dashboards-demo/visualisation_scripts/vis_disorder_per_gender.py b/apps/dashboards-demo/visualisation_scripts/vis_disorder_per_gender.py similarity index 100% rename from apps/cogstack-dashboards-demo/visualisation_scripts/vis_disorder_per_gender.py rename to apps/dashboards-demo/visualisation_scripts/vis_disorder_per_gender.py diff --git a/apps/cogstack-dashboards-demo/visualisation_scripts/vis_top_codes.py b/apps/dashboards-demo/visualisation_scripts/vis_top_codes.py similarity index 100% rename from apps/cogstack-dashboards-demo/visualisation_scripts/vis_top_codes.py rename to apps/dashboards-demo/visualisation_scripts/vis_top_codes.py diff --git a/apps/cogstack-dashboards-demo/visualisation_scripts/visualise_co_occurence.py b/apps/dashboards-demo/visualisation_scripts/visualise_co_occurence.py similarity index 100% rename from apps/cogstack-dashboards-demo/visualisation_scripts/visualise_co_occurence.py rename to apps/dashboards-demo/visualisation_scripts/visualise_co_occurence.py diff --git a/apps/cogstack-jupyter-hub/.dockerignore b/apps/jupyter-hub/.dockerignore similarity index 100% rename from apps/cogstack-jupyter-hub/.dockerignore rename to apps/jupyter-hub/.dockerignore diff --git a/apps/cogstack-jupyter-hub/.gitattributes b/apps/jupyter-hub/.gitattributes similarity index 100% rename from apps/cogstack-jupyter-hub/.gitattributes rename to apps/jupyter-hub/.gitattributes diff --git a/apps/cogstack-jupyter-hub/.gitconfig b/apps/jupyter-hub/.gitconfig similarity index 100% rename from apps/cogstack-jupyter-hub/.gitconfig rename to apps/jupyter-hub/.gitconfig diff --git a/apps/cogstack-jupyter-hub/.github/workflows/helm-smoke-test.yml b/apps/jupyter-hub/.github/workflows/helm-smoke-test.yml similarity index 100% rename from apps/cogstack-jupyter-hub/.github/workflows/helm-smoke-test.yml rename to apps/jupyter-hub/.github/workflows/helm-smoke-test.yml diff --git a/apps/cogstack-jupyter-hub/.gitignore b/apps/jupyter-hub/.gitignore similarity index 100% rename from apps/cogstack-jupyter-hub/.gitignore rename to apps/jupyter-hub/.gitignore diff --git a/apps/cogstack-jupyter-hub/CHANGELOG.md b/apps/jupyter-hub/CHANGELOG.md similarity index 100% rename from apps/cogstack-jupyter-hub/CHANGELOG.md rename to apps/jupyter-hub/CHANGELOG.md diff --git a/apps/cogstack-jupyter-hub/Dockerfile_hub b/apps/jupyter-hub/Dockerfile_hub similarity index 100% rename from apps/cogstack-jupyter-hub/Dockerfile_hub rename to apps/jupyter-hub/Dockerfile_hub diff --git a/apps/cogstack-jupyter-hub/Dockerfile_singleuser b/apps/jupyter-hub/Dockerfile_singleuser similarity index 100% rename from apps/cogstack-jupyter-hub/Dockerfile_singleuser rename to apps/jupyter-hub/Dockerfile_singleuser diff --git a/apps/cogstack-jupyter-hub/LICENSE b/apps/jupyter-hub/LICENSE similarity index 100% rename from apps/cogstack-jupyter-hub/LICENSE rename to apps/jupyter-hub/LICENSE diff --git a/apps/cogstack-jupyter-hub/README.md b/apps/jupyter-hub/README.md similarity index 100% rename from apps/cogstack-jupyter-hub/README.md rename to apps/jupyter-hub/README.md diff --git a/apps/cogstack-jupyter-hub/config/jupyter_notebook_config.py b/apps/jupyter-hub/config/jupyter_notebook_config.py similarity index 100% rename from apps/cogstack-jupyter-hub/config/jupyter_notebook_config.py rename to apps/jupyter-hub/config/jupyter_notebook_config.py diff --git a/apps/cogstack-jupyter-hub/config/jupyterhub_config.py b/apps/jupyter-hub/config/jupyterhub_config.py similarity index 100% rename from apps/cogstack-jupyter-hub/config/jupyterhub_config.py rename to apps/jupyter-hub/config/jupyterhub_config.py diff --git a/apps/cogstack-jupyter-hub/config/jupyterhub_cookie_secret b/apps/jupyter-hub/config/jupyterhub_cookie_secret similarity index 100% rename from apps/cogstack-jupyter-hub/config/jupyterhub_cookie_secret rename to apps/jupyter-hub/config/jupyterhub_cookie_secret diff --git a/apps/cogstack-jupyter-hub/config/teamlist b/apps/jupyter-hub/config/teamlist similarity index 100% rename from apps/cogstack-jupyter-hub/config/teamlist rename to apps/jupyter-hub/config/teamlist diff --git a/apps/cogstack-jupyter-hub/config/userlist b/apps/jupyter-hub/config/userlist similarity index 100% rename from apps/cogstack-jupyter-hub/config/userlist rename to apps/jupyter-hub/config/userlist diff --git a/apps/cogstack-jupyter-hub/docker/Makefile b/apps/jupyter-hub/docker/Makefile similarity index 100% rename from apps/cogstack-jupyter-hub/docker/Makefile rename to apps/jupyter-hub/docker/Makefile diff --git a/apps/cogstack-jupyter-hub/docker/docker-compose.base.yml b/apps/jupyter-hub/docker/docker-compose.base.yml similarity index 100% rename from apps/cogstack-jupyter-hub/docker/docker-compose.base.yml rename to apps/jupyter-hub/docker/docker-compose.base.yml diff --git a/apps/cogstack-jupyter-hub/docker/docker-compose.dev.yml b/apps/jupyter-hub/docker/docker-compose.dev.yml similarity index 100% rename from apps/cogstack-jupyter-hub/docker/docker-compose.dev.yml rename to apps/jupyter-hub/docker/docker-compose.dev.yml diff --git a/apps/cogstack-jupyter-hub/docker/docker-compose.override.yml b/apps/jupyter-hub/docker/docker-compose.override.yml similarity index 100% rename from apps/cogstack-jupyter-hub/docker/docker-compose.override.yml rename to apps/jupyter-hub/docker/docker-compose.override.yml diff --git a/apps/cogstack-jupyter-hub/docker/docker-compose.prod.yml b/apps/jupyter-hub/docker/docker-compose.prod.yml similarity index 100% rename from apps/cogstack-jupyter-hub/docker/docker-compose.prod.yml rename to apps/jupyter-hub/docker/docker-compose.prod.yml diff --git a/apps/cogstack-jupyter-hub/docker/docker-compose.yml b/apps/jupyter-hub/docker/docker-compose.yml similarity index 100% rename from apps/cogstack-jupyter-hub/docker/docker-compose.yml rename to apps/jupyter-hub/docker/docker-compose.yml diff --git a/apps/cogstack-jupyter-hub/env/general.env b/apps/jupyter-hub/env/general.env similarity index 100% rename from apps/cogstack-jupyter-hub/env/general.env rename to apps/jupyter-hub/env/general.env diff --git a/apps/cogstack-jupyter-hub/env/jupyter.env b/apps/jupyter-hub/env/jupyter.env similarity index 100% rename from apps/cogstack-jupyter-hub/env/jupyter.env rename to apps/jupyter-hub/env/jupyter.env diff --git a/apps/cogstack-jupyter-hub/export_env_vars.sh b/apps/jupyter-hub/export_env_vars.sh similarity index 100% rename from apps/cogstack-jupyter-hub/export_env_vars.sh rename to apps/jupyter-hub/export_env_vars.sh diff --git a/apps/cogstack-jupyter-hub/notebooks/query_annotations_opensearch.ipynb b/apps/jupyter-hub/notebooks/query_annotations_opensearch.ipynb similarity index 100% rename from apps/cogstack-jupyter-hub/notebooks/query_annotations_opensearch.ipynb rename to apps/jupyter-hub/notebooks/query_annotations_opensearch.ipynb diff --git a/apps/cogstack-jupyter-hub/notebooks/query_pgsql.ipynb b/apps/jupyter-hub/notebooks/query_pgsql.ipynb similarity index 100% rename from apps/cogstack-jupyter-hub/notebooks/query_pgsql.ipynb rename to apps/jupyter-hub/notebooks/query_pgsql.ipynb diff --git a/apps/cogstack-jupyter-hub/pyproject.toml b/apps/jupyter-hub/pyproject.toml similarity index 100% rename from apps/cogstack-jupyter-hub/pyproject.toml rename to apps/jupyter-hub/pyproject.toml diff --git a/apps/cogstack-jupyter-hub/scripts/generate_cookie_secret.sh b/apps/jupyter-hub/scripts/generate_cookie_secret.sh similarity index 100% rename from apps/cogstack-jupyter-hub/scripts/generate_cookie_secret.sh rename to apps/jupyter-hub/scripts/generate_cookie_secret.sh diff --git a/apps/cogstack-jupyter-hub/scripts/helm_k8s_smoke_test.sh b/apps/jupyter-hub/scripts/helm_k8s_smoke_test.sh similarity index 100% rename from apps/cogstack-jupyter-hub/scripts/helm_k8s_smoke_test.sh rename to apps/jupyter-hub/scripts/helm_k8s_smoke_test.sh diff --git a/apps/cogstack-jupyter-hub/scripts/r_kernel_install.sh b/apps/jupyter-hub/scripts/r_kernel_install.sh similarity index 100% rename from apps/cogstack-jupyter-hub/scripts/r_kernel_install.sh rename to apps/jupyter-hub/scripts/r_kernel_install.sh diff --git a/apps/cogstack-jupyter-hub/scripts/update_env_cert_from_nifi_repo.sh b/apps/jupyter-hub/scripts/update_env_cert_from_nifi_repo.sh similarity index 100% rename from apps/cogstack-jupyter-hub/scripts/update_env_cert_from_nifi_repo.sh rename to apps/jupyter-hub/scripts/update_env_cert_from_nifi_repo.sh diff --git a/apps/cogstack-jupyter-hub/security/.gitignore b/apps/jupyter-hub/security/.gitignore similarity index 100% rename from apps/cogstack-jupyter-hub/security/.gitignore rename to apps/jupyter-hub/security/.gitignore diff --git a/apps/cogstack-jupyter-hub/security/nifi.key b/apps/jupyter-hub/security/nifi.key similarity index 100% rename from apps/cogstack-jupyter-hub/security/nifi.key rename to apps/jupyter-hub/security/nifi.key diff --git a/apps/cogstack-jupyter-hub/security/nifi.pem b/apps/jupyter-hub/security/nifi.pem similarity index 100% rename from apps/cogstack-jupyter-hub/security/nifi.pem rename to apps/jupyter-hub/security/nifi.pem diff --git a/apps/cogstack-jupyter-hub/security/root-ca.key b/apps/jupyter-hub/security/root-ca.key similarity index 100% rename from apps/cogstack-jupyter-hub/security/root-ca.key rename to apps/jupyter-hub/security/root-ca.key diff --git a/apps/cogstack-jupyter-hub/security/root-ca.pem b/apps/jupyter-hub/security/root-ca.pem similarity index 100% rename from apps/cogstack-jupyter-hub/security/root-ca.pem rename to apps/jupyter-hub/security/root-ca.pem diff --git a/apps/cogstack-jupyter-hub/uv.lock b/apps/jupyter-hub/uv.lock similarity index 100% rename from apps/cogstack-jupyter-hub/uv.lock rename to apps/jupyter-hub/uv.lock diff --git a/apps/nifi/.dockerignore b/apps/nifi/.dockerignore new file mode 100644 index 00000000..dfeb1ad5 --- /dev/null +++ b/apps/nifi/.dockerignore @@ -0,0 +1,32 @@ +# Build from apps/nifi; include only metadata and image resources. +** +!Dockerfile +!pyproject.toml +!uv.lock +!__init__.py +!user_scripts/ +!user_scripts/** +!user_python_extensions/ +!user_python_extensions/** +!drivers/ +!drivers/** +!user_schemas/ +!user_schemas/** +!user_templates/ +!user_templates/** +!docker/ +!docker/healthcheck.sh + +# Runtime state and local development artefacts never enter image layers. +user_scripts/logs/ +user_scripts/db/ +user_scripts/tmp/ +user_scripts/extensions/ +**/.venv/ +**/__pycache__/ +**/*.py[cod] +**/.DS_Store +**/.pytest_cache/ +**/.ruff_cache/ +**/.mypy_cache/ +**/*.egg-info/ diff --git a/apps/nifi/.gitignore b/apps/nifi/.gitignore new file mode 100644 index 00000000..c4f23203 --- /dev/null +++ b/apps/nifi/.gitignore @@ -0,0 +1,18 @@ +# NiFi and Py4J type stubs are maintained source files. +!typings/**/*.pyi + +# Mutable host configuration and processor state. +conf/flow.json.gz +conf/archive/ +user_scripts/db/* +!user_scripts/db/.gitignore +user_scripts/logs/* +!user_scripts/logs/.keep +!user_scripts/tmp/ +user_scripts/tmp/* +!user_scripts/tmp/.gitignore +**devel +devel +**flow +**login +user_scripts/extensions/* diff --git a/apps/nifi/Dockerfile b/apps/nifi/Dockerfile new file mode 100644 index 00000000..44c2fd67 --- /dev/null +++ b/apps/nifi/Dockerfile @@ -0,0 +1,215 @@ +# syntax=docker/dockerfile:1 +ARG NIFI_BASE_IMAGE=apache/nifi:2.12.0@sha256:6f7f2840dbf178c6dd3fa13435b9b358f3be3c6fb7417de467a35a267f4d28ad + +FROM ${NIFI_BASE_IMAGE} + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +ARG NIFI_VERSION=2.12.0 +ARG GROOVY_VERSION=5.1.0 + +ARG HTTP_PROXY="" +ARG HTTPS_PROXY="" +ARG no_proxy="" +ARG DEBIAN_FRONTEND=noninteractive + +ARG TZ="Europe/London" + +ENV TZ=${TZ} +ENV PYTHONPATH=${NIFI_HOME}/python/framework + +# python stuff +ENV PIP_PREFER_BINARY=1 +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 +ENV PIP_NO_CACHE_DIR=1 +# Turns off buffering for easier container logging +ENV PYTHONUNBUFFERED=1 + +USER root + +# Install system dependencies using the repositories provided by the base image. +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + apt-utils \ + build-essential \ + ca-certificates \ + cmake \ + curl \ + git \ + iputils-ping \ + jq \ + libsqlite3-dev \ + libssl-dev \ + make \ + openssl \ + postgresql-server-dev-all \ + python3.11 \ + python3.11-dev \ + python3-dev \ + python3-pip \ + python3-venv \ + software-properties-common \ + sqlite3 \ + ssl-cert \ + tzdata \ + unzip \ + zip; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* + +# install rust, medcat requirement, install UV +ENV HOME=/root +ENV PATH="/root/.cargo/bin:${PATH}" +ENV UV_INSTALL_DIR=/usr/local/bin + +RUN set -eux; \ + curl -sSf https://sh.rustup.rs -o /tmp/rustup-init.sh; \ + chmod +x /tmp/rustup-init.sh; \ + /tmp/rustup-init.sh -y; \ + rm /tmp/rustup-init.sh + +# Install the exact or minimum uv version required by the repository. +COPY pyproject.toml /tmp/cogstack_nifi/pyproject.toml +RUN set -eux; \ + UV_VERSION="$(sed -nE 's/^required-version = "(==|>=)([0-9]+\.[0-9]+\.[0-9]+)"$/\2/p' /tmp/cogstack_nifi/pyproject.toml)"; \ + test -n "${UV_VERSION}" || { echo 'Expected tool.uv.required-version to be ==X.Y.Z or >=X.Y.Z in pyproject.toml' >&2; exit 1; }; \ + curl -LsSf "https://astral.sh/uv/${UV_VERSION}/install.sh" -o /tmp/install_uv.sh; \ + bash /tmp/install_uv.sh; \ + rm /tmp/install_uv.sh + +######################################## Python / PIP SECTION ######################################## + +RUN uv pip install --no-cache-dir --break-system-packages --system --upgrade pip setuptools wheel + +# Install the locked runtime dependencies used by NiFi scripts and extensions. +COPY uv.lock /tmp/cogstack_nifi/uv.lock +RUN uv export \ + --project /tmp/cogstack_nifi \ + --frozen \ + --no-dev \ + --no-emit-project \ + --format requirements.txt \ + --output-file /tmp/cogstack_nifi/requirements.txt \ + && uv pip install \ + --no-cache-dir \ + --break-system-packages \ + --target=${NIFI_HOME}/python/framework \ + -r /tmp/cogstack_nifi/requirements.txt \ + --index-url https://pypi.org/simple + +####################################################################################################### + +# solve groovy grape proxy issues, grape ignores the current environment's proxy settings +ENV JAVA_OPTS="-Dhttp.proxyHost=${HTTP_PROXY} -Dhttps.proxyHost=${HTTPS_PROXY} -Dhttp.nonProxyHosts=${no_proxy}" + + +# Install Groovy +WORKDIR /opt/nifi/groovy + +RUN set -eux; \ + url1="https://archive.apache.org/dist/groovy/${GROOVY_VERSION}/distribution/apache-groovy-binary-${GROOVY_VERSION}.zip"; \ + url2="https://repo.maven.apache.org/maven2/org/apache/groovy/apache-groovy-binary/${GROOVY_VERSION}/apache-groovy-binary-${GROOVY_VERSION}.zip"; \ + curl -fsSL --retry 8 --retry-delay 3 --connect-timeout 20 -o groovy.zip "$url1" \ + || curl -fsSL --retry 8 --retry-delay 3 --connect-timeout 20 -o groovy.zip "$url2"; \ + unzip groovy.zip; rm groovy.zip + +ENV GROOVY_BIN=/opt/nifi/groovy/groovy-${GROOVY_VERSION}/bin +RUN $GROOVY_BIN/grape -V install org.apache.avro avro 1.12.0 + +####################################### NAR INSTALL SECTION ########################################## +# INSTALL NAR extensions +WORKDIR /opt/nifi/nifi-current/lib/ + +# Apache's base image already provides the standard NARs; add only missing extensions. +RUN set -eux; \ + base="https://repo.maven.apache.org/maven2/org/apache/nifi"; \ + nars=( \ + nifi-snowflake-processors-nar \ + nifi-snowflake-services-nar \ + nifi-snowflake-services-api-nar \ + nifi-sql-reporting-nar \ + nifi-parquet-nar \ + nifi-iotdb-nar \ + nifi-hadoop-libraries-nar \ + nifi-hadoop-nar \ + nifi-graph-nar \ + nifi-other-graph-services-nar \ + nifi-graph-client-service-api-nar \ + nifi-couchbase-nar \ + nifi-media-nar \ + nifi-neo4j-cypher-service-nar \ + nifi-nar-provider-service-api-nar \ + ); \ + for a in "${nars[@]}"; do \ + url="${base}/${a}/${NIFI_VERSION}/${a}-${NIFI_VERSION}.nar"; \ + echo "Downloading $a"; \ + curl -fsSL \ + --connect-timeout 20 \ + --retry 5 \ + --retry-connrefused \ + --retry-delay 3 \ + --retry-max-time 120 \ + -o "${a}-${NIFI_VERSION}.nar" \ + "$url"; \ + done + +######################################################################################################## + +# Baseline resources work without a repository checkout. Processor directories +# can still be overridden by writable, deployment-owned volumes. +COPY __init__.py /tmp/cogstack_nifi/__init__.py +COPY user_scripts /tmp/cogstack_nifi/user_scripts +COPY user_python_extensions /tmp/cogstack_nifi/user_python_extensions +RUN uv pip install --no-cache-dir --break-system-packages --no-deps \ + --target=${NIFI_HOME}/python/framework /tmp/cogstack_nifi + +ARG NIFI_UID=1000 +ARG NIFI_GID=1000 + +COPY --chown=${NIFI_UID}:${NIFI_GID} drivers /opt/nifi/drivers +COPY --chown=${NIFI_UID}:${NIFI_GID} user_schemas /opt/nifi/user_schemas +COPY --chown=${NIFI_UID}:${NIFI_GID} user_templates /opt/nifi/user_templates +COPY --chown=${NIFI_UID}:${NIFI_GID} user_scripts /opt/nifi/user_scripts +COPY --chown=${NIFI_UID}:${NIFI_GID} user_python_extensions /opt/nifi/nifi-current/python_extensions +COPY --chmod=755 docker/healthcheck.sh /opt/nifi/scripts/cogstack-healthcheck.sh + +# Keep Apache's configuration defaults and startup script. Deployment credentials +# and mutable configuration from the checkout never enter the image. +RUN sed -i \ + -e 's|^nifi.security.autoreload.enabled=.*|nifi.security.autoreload.enabled=true|' \ + -e 's|^nifi.flowcontroller.graceful.shutdown.period=.*|nifi.flowcontroller.graceful.shutdown.period=30 sec|' \ + "${NIFI_HOME}/conf/nifi.properties" \ + && sed -i 's|^graceful.shutdown.seconds=.*|graceful.shutdown.seconds=60|' "${NIFI_HOME}/conf/bootstrap.conf" \ + && cp -a "${NIFI_HOME}/conf" /tmp/cogstack_nifi/conf + +# Apache ships owner-only executables; remap them only for custom UID builds. +RUN set -eux; \ + if [ "$(id -g nifi)" != "${NIFI_GID}" ]; then groupmod -o -g "${NIFI_GID}" nifi; fi; \ + if [ "$(id -u nifi)" != "${NIFI_UID}" ]; then \ + usermod -o -u "${NIFI_UID}" nifi; \ + chown -R "${NIFI_UID}:${NIFI_GID}" "${NIFI_HOME}" "${NIFI_TOOLKIT_HOME}"; \ + fi; \ + mkdir -p "${NIFI_HOME}/run" "${NIFI_HOME}/work/python" \ + "${NIFI_HOME}/logs/user_scripts" "${NIFI_HOME}/state/user_scripts/db" \ + /opt/nifi/pipeline/flowfile-errors /data /opt/models; \ + rm -rf "${NIFI_HOME}/python/framework/nifi/user_scripts"; \ + ln -s /opt/nifi/user_scripts "${NIFI_HOME}/python/framework/nifi/user_scripts"; \ + ln -s /opt/nifi/drivers /tmp/cogstack_nifi/drivers; \ + ln -s /opt/nifi/user_schemas /tmp/cogstack_nifi/user_schemas; \ + ln -s /opt/nifi/user_templates /tmp/cogstack_nifi/user_templates; \ + chown -R "${NIFI_UID}:${NIFI_GID}" \ + "${NIFI_HOME}"/{conf,logs,run,work,database_repository,flowfile_repository,content_repository,provenance_repository,state,nar_extensions,python_extensions} \ + /home/nifi /opt/nifi/pipeline/flowfile-errors /data /opt/models + +ENV HOME=/home/nifi +ENV NIFI_WEB_HTTPS_HOST="0.0.0.0" +ENV PATH=/usr/local/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin +ENV UV_CACHE_DIR=/opt/nifi/nifi-current/work/python/uv-cache +ENV PYTHONPYCACHEPREFIX=/opt/nifi/nifi-current/work/python/pycache +ENV NIFI_USER_SCRIPT_LOGS_DIR=/opt/nifi/nifi-current/logs/user_scripts +ENV NIFI_USER_SCRIPT_DB_DIR=/opt/nifi/nifi-current/state/user_scripts/db +WORKDIR /opt/nifi/nifi-current +USER ${NIFI_UID}:${NIFI_GID} +HEALTHCHECK --interval=30s --timeout=10s --start-period=300s --retries=3 \ + CMD ["/opt/nifi/scripts/cogstack-healthcheck.sh", "ready"] diff --git a/apps/nifi/README.md b/apps/nifi/README.md new file mode 100644 index 00000000..0c4418fc --- /dev/null +++ b/apps/nifi/README.md @@ -0,0 +1,93 @@ +# CogStack NiFi + +The CogStack NiFi image, Python processors, JDBC drivers, schemas and flow +templates. These files were migrated from the `nifi/` directory of +`cogstack_nifi`; the Python project metadata, lockfile and type stubs now live +alongside the application. + +## Contents + +| Path | Purpose | +| --- | --- | +| `Dockerfile` | Build the customised Apache NiFi image. | +| `pyproject.toml`, `uv.lock` | Python package configuration and locked dependencies. | +| `pyrightconfig.json` | Pyright configuration for the local virtual environment, imports and type stubs. | +| `user_python_extensions/` | NiFi 2 Python processors. | +| `user_scripts/` | Shared Python utilities, processors and legacy scripts. | +| `drivers/` | JDBC drivers bundled in the image. | +| `user_schemas/`, `user_templates/` | Schemas and example ingestion flows. | +| `conf/` | Reference configuration from the original application. | +| `docker/` | Container health check and deployment helpers. | +| `typings/` | NiFi API and Py4J stubs for local type checking. | + +## Build the image + +Run from the platform repository root: + +```bash +docker build --tag cogstack/cogstack-nifi:local apps/nifi +``` + +`apps/nifi` is the build context. The Dockerfile uses the checked-in dependency +lockfile and bundles the application resources. It keeps Apache's default +configuration and startup scripts; host configuration and environment files are +excluded from the build context. + +The `NIFI_BASE_IMAGE`, `NIFI_VERSION`, `GROOVY_VERSION`, `NIFI_UID` and `NIFI_GID` +build arguments can override the Dockerfile defaults. Keep the base image and +`NIFI_VERSION` aligned. Published image names and container resource paths such +as `/opt/nifi/user_scripts` remain the same. + +## Python development + +Use Python 3.11 or later and a version of `uv` satisfying +`tool.uv.required-version` in `pyproject.toml`: + +```bash +uv sync --directory apps/nifi --locked --dev +uv run --directory apps/nifi --locked ruff check user_python_extensions --select F,E9 +uv run --directory apps/nifi --locked mypy --config-file pyproject.toml user_python_extensions +``` + +The package maps this application directory to the existing `nifi` Python +namespace, so imports such as `nifi.user_scripts.utils.generic` continue to work +after installation. When adding Python subpackages, include them in +`tool.setuptools.packages`. Native NiFi processors run inside NiFi, which supplies +the `nifiapi` framework; `typings/` contains stubs for development. + +Some files under `user_scripts/tests/` are integration tests or example scripts +requiring running services, credentials and sample data. + +For Pyright, use `apps/nifi/pyrightconfig.json` as the project configuration. It +uses the application's `.venv`, resolves the `nifi` package from the parent +`apps/` directory, and includes the local processor and type-stub directories. + +## Deployment helpers + +The Kubernetes charts live in +[`deployment/charts/nifi`](../../deployment/charts/nifi/README.md) +and [`deployment/charts/nginx`](../../deployment/charts/nginx/README.md). Their +READMEs describe the required environment ConfigMaps, TLS Secrets and storage. + +The NiFi build context and resource mounts in `docker/docker-compose.dev.yml` +point to this application directory. The Compose file, Makefile and environment +loader were brought over from the wider CogStack deployment and still reference +supporting configuration, security certificates, services and helper scripts. +Those dependencies need to be migrated or supplied before using the full +deployment helpers. The image build above works independently of them. + +Mutable configuration, data repositories, processor logs and databases belong +in deployment-owned storage. The image health check expects the configured TLS +CA certificate at runtime. + +## Dependency auditing + +From the platform repository root, audit the documentation and NiFi dependency +lockfiles with `uv` and `pip-audit` available on `PATH`: + +```bash +bash deployment/scripts/maintenance/audit_pip_dependency.sh --include-nifi +``` + +See the [deployment scripts README](../../deployment/scripts/README.md) for +prerequisites. diff --git a/apps/nifi/__init__.py b/apps/nifi/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/nifi/conf/authorizations.xml b/apps/nifi/conf/authorizations.xml new file mode 100644 index 00000000..a3fb8029 --- /dev/null +++ b/apps/nifi/conf/authorizations.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/nifi/conf/authorizers.xml b/apps/nifi/conf/authorizers.xml new file mode 100644 index 00000000..878cab06 --- /dev/null +++ b/apps/nifi/conf/authorizers.xml @@ -0,0 +1,348 @@ + + + + + + + + file-user-group-provider + org.apache.nifi.authorization.FileUserGroupProvider + ./conf/users.xml + + admin + cogstack + C=UK, ST=London, L=UK, O=cogstack, OU=cogstack, CN=cogstack + + + + + + + + + + + + + + + + + + + + + file-access-policy-provider + org.apache.nifi.authorization.FileAccessPolicyProvider + file-user-group-provider + ./conf/authorizations.xml + admin + C=UK, ST=London, L=UK, O=cogstack, OU=cogstack, CN=cogstack + cogstack + + + + + + managed-authorizer + org.apache.nifi.authorization.StandardManagedAuthorizer + file-access-policy-provider + + + + + single-user-authorizer + org.apache.nifi.authorization.single.user.SingleUserAuthorizer + + \ No newline at end of file diff --git a/apps/nifi/conf/bootstrap-aws.conf b/apps/nifi/conf/bootstrap-aws.conf new file mode 100644 index 00000000..f624dec9 --- /dev/null +++ b/apps/nifi/conf/bootstrap-aws.conf @@ -0,0 +1,27 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# AWS KMS Key ID is required to be configured for AWS KMS Sensitive Property Provider +aws.kms.key.id= + +# NiFi uses the following properties when authentication to AWS when all values are provided. +# NiFi uses the default AWS credentials provider chain when one or more or the following properties are blank +# AWS SDK documentation describes the default credential retrieval order: +# https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials.html#credentials-chain +aws.access.key.id= +aws.secret.access.key= +aws.region= diff --git a/apps/nifi/conf/bootstrap-azure.conf b/apps/nifi/conf/bootstrap-azure.conf new file mode 100644 index 00000000..49e318ea --- /dev/null +++ b/apps/nifi/conf/bootstrap-azure.conf @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Key Identifier for Azure Key Vault Key Sensitive Property Provider +azure.keyvault.key.id= +# Encryption Algorithm for Azure Key Vault Key Sensitive Property Provider +azure.keyvault.encryption.algorithm= + +# Vault URI for Azure Key Vault Secret Sensitive Property Provider +azure.keyvault.uri= diff --git a/apps/nifi/conf/bootstrap-gcp.conf b/apps/nifi/conf/bootstrap-gcp.conf new file mode 100644 index 00000000..440dad23 --- /dev/null +++ b/apps/nifi/conf/bootstrap-gcp.conf @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# These GCP KMS settings must all be configured in order to use the GCP KMS Sensitive Property Provider +gcp.kms.project= +gcp.kms.location= +gcp.kms.keyring= +gcp.kms.key= \ No newline at end of file diff --git a/apps/nifi/conf/bootstrap-hashicorp-vault.conf b/apps/nifi/conf/bootstrap-hashicorp-vault.conf new file mode 100644 index 00000000..bbf54f57 --- /dev/null +++ b/apps/nifi/conf/bootstrap-hashicorp-vault.conf @@ -0,0 +1,51 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# HTTP or HTTPS URI for HashiCorp Vault is required to enable the Sensitive Properties Provider +vault.uri= + +# Transit Path is required to enable the Sensitive Properties Provider Protection Scheme 'hashicorp/vault/transit/{path}' +vault.transit.path= + +# Key/Value Path is required to enable the Sensitive Properties Provider Protection Scheme 'hashicorp/vault/kv/{path}' +vault.kv.path= + +# Token Authentication example properties +# vault.authentication=TOKEN +# vault.token= + +# Optional file supports authentication properties described in the Spring Vault Environment Configuration +# https://docs.spring.io/spring-vault/docs/2.3.x/reference/html/#vault.core.environment-vault-configuration +# +# All authentication properties must be included in bootstrap-hashicorp-vault.conf when this property is not specified. +# Properties in bootstrap-hashicorp-vault.conf take precedence when the same values are defined in both files. +# Token Authentication is the default when the 'vault.authentication' property is not specified. +vault.authentication.properties.file= + +# Optional Timeout properties +vault.connection.timeout=5 secs +vault.read.timeout=15 secs + +# Optional TLS properties +vault.ssl.enabledCipherSuites= +vault.ssl.enabledProtocols= +vault.ssl.key-store= +vault.ssl.key-store-type= +vault.ssl.key-store-password= +vault.ssl.trust-store= +vault.ssl.trust-store-type= +vault.ssl.trust-store-password= diff --git a/apps/nifi/conf/bootstrap-notification-services.xml b/apps/nifi/conf/bootstrap-notification-services.xml new file mode 100644 index 00000000..bbfc65a3 --- /dev/null +++ b/apps/nifi/conf/bootstrap-notification-services.xml @@ -0,0 +1,53 @@ + + + + + + + + + \ No newline at end of file diff --git a/apps/nifi/conf/bootstrap.conf b/apps/nifi/conf/bootstrap.conf new file mode 100644 index 00000000..a36fde47 --- /dev/null +++ b/apps/nifi/conf/bootstrap.conf @@ -0,0 +1,119 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Java command to use when running NiFi +java=java + +# Whether or not to preserve shell environment while using run.as (see "sudo -E" man page). By default, this is set to false. +preserve.environment=true + +# Username to use when running NiFi. This value will be ignored on Windows. +# run.as= + +# Preserve shell environment while runnning as "run.as" user +preserve.environment=false + +# Configure where NiFi's lib and conf directories live +lib.dir=./lib +conf.dir=./conf + +# How long to wait after telling NiFi to shutdown before explicitly killing the Process +graceful.shutdown.seconds=20 + +# Disable JSR 199 so that we can use JSP's without running a JDK +java.arg.1=-Dorg.apache.jasper.compiler.disablejsr199=true + +# JVM memory settings +java.arg.2=-Xms8g +java.arg.3=-Xmx16g + +# Enable Remote Debugging +#java.arg.debug=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 + +#java.arg.4=-Djava.net.preferIPv4Stack=true + +# allowRestrictedHeaders is required for Cluster/Node communications to work properly +java.arg.5=-Dsun.net.http.allowRestrictedHeaders=true +java.arg.6=-Djava.protocol.handler.pkgs=sun.net.www.protocol + +# The G1GC is known to cause some problems in Java 8 and earlier, but the issues were addressed in Java 9. If using Java 8 or earlier, +# it is recommended that G1GC not be used, especially in conjunction with the Write Ahead Provenance Repository. However, if using a newer +# version of Java, it can result in better performance without significant "stop-the-world" delays. +#java.arg.13=-XX:+UseG1GC + +#Set headless mode by default +java.arg.14=-Djava.awt.headless=true + +# Root key in hexadecimal format for encrypted sensitive configuration values +nifi.bootstrap.sensitive.key= + +# Sensitive Property Provider configuration + +# HashiCorp Vault Sensitive Property Providers +#nifi.bootstrap.protection.hashicorp.vault.conf=./conf/bootstrap-hashicorp-vault.conf + +# AWS Sensitive Property Providers +#nifi.bootstrap.protection.aws.conf=./conf/bootstrap-aws.conf + +# Azure Key Vault Sensitive Property Providers +#nifi.bootstrap.protection.azure.keyvault.conf=./conf/bootstrap-azure.conf + +# GCP KMS Sensitive Property Providers +#nifi.bootstrap.protection.gcp.kms.conf=./conf/bootstrap-gcp.conf + +# Sets the provider of SecureRandom to /dev/urandom to prevent blocking on VMs +java.arg.15=-Djava.security.egd=file:/dev/urandom + +# Requires JAAS to use only the provided JAAS configuration to authenticate a Subject, without using any "fallback" methods (such as prompting for username/password) +# Please see https://docs.oracle.com/javase/8/docs/technotes/guides/security/jgss/single-signon.html, section "EXCEPTIONS TO THE MODEL" +java.arg.16=-Djavax.security.auth.useSubjectCredsOnly=true + +# Zookeeper 3.5 now includes an Admin Server that starts on port 8080, since NiFi is already using that port disable by default. +# Please see https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_adminserver_config for configuration options. +java.arg.17=-Dzookeeper.admin.enableServer=false + +# The following options configure a Java Agent to handle native library loading. +# It is needed when a custom jar (eg. JDBC driver) has been configured on a component in the flow and this custom jar depends on a native library +# and tries to load it by its absolute path (java.lang.System.load(String filename) method call). +# Use this Java Agent only if you get "Native Library ... already loaded in another classloader" errors otherwise! +#java.arg.18=-javaagent:./lib/aspectj/aspectjweaver-1.9.6.jar +#java.arg.19=-Daj.weaving.loadersToSkip=sun.misc.Launcher$AppClassLoader,jdk.internal.loader.ClassLoaders$AppClassLoader,org.eclipse.jetty.webapp.WebAppClassLoader,\ +# org.apache.jasper.servlet.JasperLoader,org.jvnet.hk2.internal.DelegatingClassLoader,org.apache.nifi.nar.NarClassLoader +# End of Java Agent config for native library loading. + +### +# Notification Services for notifying interested parties when NiFi is stopped, started, dies +### + +# XML File that contains the definitions of the notification services +notification.services.file=./conf/bootstrap-notification-services.xml + +# In the case that we are unable to send a notification for an event, how many times should we retry? +notification.max.attempts=5 + +# Comma-separated list of identifiers that are present in the notification.services.file; which services should be used to notify when NiFi is started? +#nifi.start.notification.services=email-notification + +# Comma-separated list of identifiers that are present in the notification.services.file; which services should be used to notify when NiFi is stopped? +#nifi.stop.notification.services=email-notification + +# Comma-separated list of identifiers that are present in the notification.services.file; which services should be used to notify when NiFi dies? +#nifi.dead.notification.services=email-notification + +# The first curator connection issue is logged as ERROR, for example when NiFi cannot connect to one of the Zookeeper nodes. +# Additional connection issues are logged as DEBUG until the connection is restored. +java.arg.curator.supress.excessive.logs=-Dcurator-log-only-first-connection-issue-as-error-level=true diff --git a/apps/nifi/conf/logback.xml b/apps/nifi/conf/logback.xml new file mode 100644 index 00000000..6d0a61dc --- /dev/null +++ b/apps/nifi/conf/logback.xml @@ -0,0 +1,302 @@ + + + + + + + + true + + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-app.log + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-app_%d{yyyy-MM-dd_HH}.%i.log + + 128MB + + 30 + + 4GB + + true + + true + + %date %level [%thread] %logger{40} %msg%n + + + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-user.log + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-user_%d.log + + 30 + + 4GB + + true + + + %date %level [%thread] %logger{40} %msg%n + + + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-request.log + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-request_%d.log + + 30 + + 4GB + + true + + + %msg%n + + + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-bootstrap.log + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-bootstrap_%d.log + + 30 + + 4GB + + true + + + %date %level [%thread] %logger{40} %msg%n + + + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-deprecation.log + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-deprecation_%d.%i.log + + 128MB + + 10 + + 128MB + + true + + + %date %level [%thread] %logger %msg%n + + + + + + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-app-${logFileSuffix}.log + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-app-${logFileSuffix}_%d{yyyy-MM-dd_HH}.%i.log + + 128MB + + 30 + + 4GB + + true + + true + + %date %level [%thread] %logger{40} %msg%n + + + + + + + + %date %level [%thread] %logger{40} %msg%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/nifi/conf/login-identity-providers.xml b/apps/nifi/conf/login-identity-providers.xml new file mode 100644 index 00000000..2dc65b02 --- /dev/null +++ b/apps/nifi/conf/login-identity-providers.xml @@ -0,0 +1,125 @@ + + + + single-user-provider + org.apache.nifi.authentication.single.user.SingleUserLoginIdentityProvider + admin + $2b$12$lUtr57TKmfD2ahiCMQu/5OfLqwPDKHp4f04i4aMW7Et7p3TeGWzte + + + + + + + \ No newline at end of file diff --git a/apps/nifi/conf/nifi.properties b/apps/nifi/conf/nifi.properties new file mode 100644 index 00000000..b189b010 --- /dev/null +++ b/apps/nifi/conf/nifi.properties @@ -0,0 +1,365 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Core Properties # +nifi.flow.configuration.file=./conf/flow.json.gz +nifi.flow.configuration.archive.enabled=true +nifi.flow.configuration.archive.dir=./conf/archive/ +nifi.flow.configuration.archive.max.time=30 minutes +nifi.flow.configuration.archive.max.storage=32 GB +nifi.flow.configuration.archive.max.count=10 +nifi.flowcontroller.autoResumeState=true +nifi.flowcontroller.graceful.shutdown.period=30 sec +nifi.flowservice.writedelay.interval=500 ms +nifi.administrative.yield.duration=30 sec +# If a component has no work to do (is "bored"), how long should we wait before checking again for work? +# Higher values of yield.duration decrease CPU utilisation when there is no work to do. +nifi.bored.yield.duration=100 millis +nifi.queue.backpressure.count=10000 +nifi.queue.backpressure.size=256MB + +nifi.authorizer.configuration.file=./conf/authorizers.xml +nifi.login.identity.provider.configuration.file=./conf/login-identity-providers.xml +nifi.templates.directory=./conf/templates +nifi.ui.banner.text= +nifi.ui.autorefresh.interval=60 sec +nifi.nar.library.directory=./lib +nifi.nar.library.autoload.directory=/opt/nifi/nifi-current/nar_extensions +nifi.nar.working.directory=./work/nar/ +nifi.documentation.working.directory=./work/docs/components + +# allow users to upload templates (Legacy NiFi behaviour +nifi.templates.enabled=true + + +# point nifi to the right Python3 version +nifi.python.command=python3.11 +nifi.python.framework.source.directory=/opt/nifi/nifi-current/python/framework +nifi.python.extensions.source.directory.default=/opt/nifi/nifi-current/python_extensions +nifi.python.working.directory=/opt/nifi/nifi-current/work/python +nifi.python.logs.directory=./logs +nifi.python.max.processes.per.extension.type=10 +nifi.python.max.processes=100 + +#################### +# State Management # +#################### +nifi.state.management.configuration.file=./conf/state-management.xml +# The ID of the local state provider +nifi.state.management.provider.local=local-provider +# The ID of the cluster-wide state provider. This will be ignored if NiFi is not clustered but must be populated if running in a cluster. +nifi.state.management.provider.cluster=zk-provider +# Specifies whether or not this instance of NiFi should run an embedded ZooKeeper server +nifi.state.management.embedded.zookeeper.start=false +# Properties file that provides the ZooKeeper properties to use if is set to true +nifi.state.management.embedded.zookeeper.properties=./conf/zookeeper.properties + +# H2 Settings +nifi.database.directory=./database_repository +nifi.h2.url.append=;LOCK_TIMEOUT=25000;WRITE_DELAY=0;AUTO_SERVER=FALSE + +# Repository Encryption properties override individual repository implementation properties +nifi.repository.encryption.protocol.version= +nifi.repository.encryption.key.id= +nifi.repository.encryption.key.provider= +nifi.repository.encryption.key.provider.keystore.location= +nifi.repository.encryption.key.provider.keystore.password= + +# FlowFile Repository +nifi.flowfile.repository.implementation=org.apache.nifi.controller.repository.WriteAheadFlowFileRepository +nifi.flowfile.repository.wal.implementation=org.apache.nifi.wali.SequentialAccessWriteAheadLog +nifi.flowfile.repository.directory=./flowfile_repository +nifi.flowfile.repository.checkpoint.interval=2 secs +nifi.flowfile.repository.always.sync=false +nifi.flowfile.repository.retain.orphaned.flowfiles=false + +nifi.swap.manager.implementation=org.apache.nifi.controller.FileSystemSwapManager +nifi.queue.swap.threshold=20000 + +# Content Repository +nifi.content.repository.implementation=org.apache.nifi.controller.repository.FileSystemRepository +nifi.content.claim.max.appendable.size=1 MB +nifi.content.claim.max.flow.files=100 +nifi.content.repository.directory.default=./content_repository +nifi.content.repository.archive.cleanup.frequency=30 secs +nifi.content.repository.archive.max.retention.period=1 mins +nifi.content.repository.archive.max.usage.percentage=15% +nifi.content.repository.archive.backpressure.percentage=50% +nifi.content.repository.archive.enabled=false +nifi.content.repository.always.sync=false +nifi.content.viewer.url=../nifi-content-viewer/ + +# Provenance Repository Properties +nifi.provenance.repository.implementation=org.apache.nifi.provenance.WriteAheadProvenanceRepository + +# Persistent Provenance Repository Properties +nifi.provenance.repository.directory.default=./provenance_repository +nifi.provenance.repository.max.storage.time=2 hours +nifi.provenance.repository.max.storage.size=32 GB +nifi.provenance.repository.rollover.time=10 mins +nifi.provenance.repository.rollover.size=100 MB +nifi.provenance.repository.query.threads=2 +nifi.provenance.repository.index.threads=2 +nifi.provenance.repository.compress.on.rollover=true +nifi.provenance.repository.always.sync=false +# Comma-separated list of fields. Fields that are not indexed will not be searchable. Valid fields are: +# EventType, FlowFileUUID, Filename, TransitURI, ProcessorID, AlternateIdentifierURI, Relationship, Details +nifi.provenance.repository.indexed.fields=EventType, FlowFileUUID, Filename, ProcessorID, Relationship +# FlowFile Attributes that should be indexed and made searchable. Some examples to consider are filename, uuid, mime.type +nifi.provenance.repository.indexed.attributes= +# Large values for the shard size will result in more Java heap usage when searching the Provenance Repository +# but should provide better performance + +# The repository uses Apache Lucene to performing indexing and searching capabilities. This value indicates how large a Lucene Index should become before the Repository starts writing to a new Index. +# Large values for the shard size will result in more Java heap usage when searching the Provenance Repository but should provide better performance. +# The default value is 500 MB. However, this is due to the fact that defaults are tuned for very small environments where most users begin to use NiFi. +# For production environments, it is advisable to change this value to 4 to 8 GB. Once all Provenance Events in the index have been aged off from the "event files," the index will be destroyed as well. +# NOTE: This value should be smaller than (no more than half of) the nifi.provenance.repository.max.storage.size property. +nifi.provenance.repository.index.shard.size=4GB + +# Indicates the maximum length that a FlowFile attribute can be when retrieving a Provenance Event from +# the repository. If the length of any attribute exceeds this value, it will be truncated when the event is retrieved. +nifi.provenance.repository.max.attribute.length=65536 +nifi.provenance.repository.concurrent.merge.threads=2 + +# Volatile Provenance Respository Properties +nifi.provenance.repository.buffer.size=100000 + +# Component and Node Status History Repository +nifi.components.status.repository.implementation=org.apache.nifi.controller.status.history.VolatileComponentStatusRepository + +# Volatile Status History Repository Properties +nifi.components.status.repository.buffer.size=1440 +nifi.components.status.snapshot.frequency=1 min + +# QuestDB Status History Repository Properties +nifi.status.repository.questdb.persist.node.days=14 +nifi.status.repository.questdb.persist.component.days=3 +nifi.status.repository.questdb.persist.location=./status_repository + +# Site to Site properties +nifi.remote.input.host=nifi +nifi.remote.input.secure=true +nifi.remote.input.socket.port=10000 +nifi.remote.input.http.enabled=true +nifi.remote.input.http.transaction.ttl=30 sec +nifi.remote.contents.cache.expiration=30 secs + +############################################# + +# For security, NiFi will present the UI on 127.0.0.1 and only be accessible through this loopback interface. +# Be aware that changing these properties may affect how your instance can be accessed without any restriction. +# We recommend configuring HTTPS instead. The administrators guide provides instructions on how to do this. + + +# web properties # +#nifi.web.war.directory=./lib + +nifi.web.http.host= +nifi.web.http.port= +nifi.web.http.network.interface.default= + +############################################# + +nifi.web.https.host=0.0.0.0 +nifi.web.https.port=8443 +nifi.web.https.network.interface.default= +nifi.web.jetty.working.directory=./work/jetty +nifi.web.jetty.threads=200 +nifi.web.max.header.size=32 KB +# IMPORTANT : be careful with this setting, it is buggy and single '/' don't work +# After testing it seems that when running nifi in Docker you should set it via the NIFI_WEB_PROXY_CONTEXT_PATH ENV var, otherwise it wont work (needs a bug report) +nifi.web.proxy.context.path=/nifi +nifi.web.proxy.host=localhost:8443,127.0.0.1:8443 +nifi.web.max.content.size= +nifi.web.max.requests.per.second=30000 +nifi.web.max.access.token.requests.per.second=25 +nifi.web.request.timeout=60 secs +nifi.web.request.ip.whitelist= +nifi.web.should.send.server.version=true + +# Include or Exclude TLS Cipher Suites for HTTPS +nifi.web.https.ciphersuites.include= +nifi.web.https.ciphersuites.exclude= + +# security properties # +nifi.sensitive.props.key=cogstackNiFipass +nifi.sensitive.props.key.protected= +nifi.sensitive.props.algorithm=NIFI_PBKDF2_AES_GCM_256 +nifi.sensitive.props.additional.keys= + +nifi.security.autoreload.enabled=true +nifi.security.autoreload.interval=10 secs +nifi.security.keystore=/security/certificates/nifi/nifi-keystore.jks +nifi.security.keystoreType=JKS +nifi.security.keystorePasswd=cogstackNifi +nifi.security.keyPasswd=cogstackNifi +nifi.security.truststore=/security/certificates/nifi/nifi-truststore.jks +nifi.security.truststoreType=JKS +nifi.security.truststorePasswd=cogstackNifi +nifi.security.user.authorizer=single-user-authorizer +nifi.security.allow.anonymous.authentication=false +nifi.security.user.login.identity.provider=single-user-provider +nifi.security.user.jws.key.rotation.period=PT1H +nifi.security.ocsp.responder.url= +nifi.security.ocsp.responder.certificate= + +# OpenId Connect SSO Properties # +nifi.security.user.oidc.discovery.url= +nifi.security.user.oidc.connect.timeout=5 secs +nifi.security.user.oidc.read.timeout=5 secs +nifi.security.user.oidc.client.id= +nifi.security.user.oidc.client.secret= +nifi.security.user.oidc.preferred.jwsalgorithm= +nifi.security.user.oidc.additional.scopes= +nifi.security.user.oidc.claim.identifying.user= +nifi.security.user.oidc.fallback.claims.identifying.user= + +# Apache Knox SSO Properties # +nifi.security.user.knox.url= +nifi.security.user.knox.publicKey= +nifi.security.user.knox.cookieName=hadoop-jwt +nifi.security.user.knox.audiences= + +# SAML Properties # +nifi.security.user.saml.idp.metadata.url= +nifi.security.user.saml.sp.entity.id= +nifi.security.user.saml.identity.attribute.name= +nifi.security.user.saml.group.attribute.name= +nifi.security.user.saml.metadata.signing.enabled=false +nifi.security.user.saml.request.signing.enabled=false +nifi.security.user.saml.want.assertions.signed=true +nifi.security.user.saml.signature.algorithm=http://www.w3.org/2001/04/xmldsig-more#rsa-sha256 +nifi.security.user.saml.signature.digest.algorithm=http://www.w3.org/2001/04/xmlenc#sha256 +nifi.security.user.saml.message.logging.enabled=false +nifi.security.user.saml.authentication.expiration=12 hours +nifi.security.user.saml.single.logout.enabled=false +nifi.security.user.saml.http.client.truststore.strategy=JDK +nifi.security.user.saml.http.client.connect.timeout=30 secs +nifi.security.user.saml.http.client.read.timeout=30 secs + +# Identity Mapping Properties # +# These properties allow normalizing user identities such that identities coming from different identity providers +# (certificates, LDAP, Kerberos) can be treated the same internally in NiFi. The following example demonstrates normalizing +# DNs from certificates and principals from Kerberos into a common identity string: +# +# nifi.security.identity.mapping.pattern.dn=^CN=(.*?), OU=(.*?), O=(.*?), L=(.*?), ST=(.*?), C=(.*?)$ +# nifi.security.identity.mapping.value.dn=$1@$2 +# nifi.security.identity.mapping.transform.dn=NONE +# nifi.security.identity.mapping.pattern.kerb=^(.*?)/instance@(.*?)$ +# nifi.security.identity.mapping.value.kerb=$1@$2 +# nifi.security.identity.mapping.transform.kerb=UPPER + +# Group Mapping Properties # +# These properties allow normalizing group names coming from external sources like LDAP. The following example +# lowercases any group name. +# +# nifi.security.group.mapping.pattern.anygroup=^(.*)$ +# nifi.security.group.mapping.value.anygroup=$1 +# nifi.security.group.mapping.transform.anygroup=LOWER + +# cluster common properties (all nodes must have same values) # +nifi.cluster.protocol.heartbeat.interval=5 sec +nifi.cluster.protocol.heartbeat.missable.max=8 +nifi.cluster.protocol.is.secure=true + +# cluster node properties (only configure for cluster nodes) # +nifi.cluster.is.node=false +nifi.cluster.node.address=nifi +nifi.cluster.node.protocol.port= +nifi.cluster.node.protocol.max.threads=50 +nifi.cluster.node.event.history.size=25 +nifi.cluster.node.connection.timeout=5 sec +nifi.cluster.node.read.timeout=5 sec +nifi.cluster.node.max.concurrent.requests=100 +nifi.cluster.firewall.file= +nifi.cluster.flow.election.max.wait.time=5 mins +nifi.cluster.flow.election.max.candidates= + +# cluster load balancing properties # +nifi.cluster.load.balance.host= +nifi.cluster.load.balance.port=6342 +nifi.cluster.load.balance.connections.per.node=1 +nifi.cluster.load.balance.max.thread.count=8 +nifi.cluster.load.balance.comms.timeout=30 sec + +# zookeeper properties, used for cluster management # +nifi.zookeeper.connect.string= +nifi.zookeeper.connect.timeout=10 secs +nifi.zookeeper.session.timeout=10 secs +nifi.zookeeper.root.node=/nifi +nifi.zookeeper.client.secure=false +nifi.zookeeper.security.keystore= +nifi.zookeeper.security.keystoreType= +nifi.zookeeper.security.keystorePasswd= +nifi.zookeeper.security.truststore= +nifi.zookeeper.security.truststoreType= +nifi.zookeeper.security.truststorePasswd= +nifi.zookeeper.jute.maxbuffer= + +# Zookeeper properties for the authentication scheme used when creating acls on znodes used for cluster management +# Values supported for nifi.zookeeper.auth.type are "default", which will apply world/anyone rights on znodes +# and "sasl" which will give rights to the sasl/kerberos identity used to authenticate the nifi node +# The identity is determined using the value in nifi.kerberos.service.principal and the removeHostFromPrincipal +# and removeRealmFromPrincipal values (which should align with the kerberos.removeHostFromPrincipal and kerberos.removeRealmFromPrincipal +# values configured on the zookeeper server). +nifi.zookeeper.auth.type= +nifi.zookeeper.kerberos.removeHostFromPrincipal= +nifi.zookeeper.kerberos.removeRealmFromPrincipal= + +# kerberos # +nifi.kerberos.krb5.file= + +# kerberos service principal # +nifi.kerberos.service.principal= +nifi.kerberos.service.keytab.location= + +# kerberos spnego principal # +nifi.kerberos.spnego.principal= +nifi.kerberos.spnego.keytab.location= +nifi.kerberos.spnego.authentication.expiration=12 hours + +# external properties files for variable registry +# supports a comma delimited list of file locations +nifi.variable.registry.properties= + +# analytics properties # +nifi.analytics.predict.enabled=false +nifi.analytics.predict.interval=3 mins +nifi.analytics.query.interval=5 mins +nifi.analytics.connection.model.implementation=org.apache.nifi.controller.status.analytics.models.OrdinaryLeastSquares +nifi.analytics.connection.model.score.name=rSquared +nifi.analytics.connection.model.score.threshold=.90 + +# runtime monitoring properties +nifi.monitor.long.running.task.schedule= +nifi.monitor.long.running.task.threshold= + +# Create automatic diagnostics when stopping/restarting NiFi. + +# Enable automatic diagnostic at shutdown. +nifi.diagnostics.on.shutdown.enabled=false + +# Include verbose diagnostic information. +nifi.diagnostics.on.shutdown.verbose=false + +# The location of the diagnostics folder. +nifi.diagnostics.on.shutdown.directory=./diagnostics + +# The maximum number of files permitted in the directory. If the limit is exceeded, the oldest files are deleted. +nifi.diagnostics.on.shutdown.max.filecount=10 + +# The diagnostics folder's maximum permitted size in bytes. If the limit is exceeded, the oldest files are deleted. +nifi.diagnostics.on.shutdown.max.directory.size=10 MB diff --git a/apps/nifi/conf/state-management.xml b/apps/nifi/conf/state-management.xml new file mode 100644 index 00000000..0bfd11b1 --- /dev/null +++ b/apps/nifi/conf/state-management.xml @@ -0,0 +1,138 @@ + + + + + + + local-provider + org.apache.nifi.controller.state.providers.local.WriteAheadLocalStateProvider + ./state/local + true + 16 + 10 mins + + + + + zk-provider + org.apache.nifi.controller.state.providers.zookeeper.ZooKeeperStateProvider + + /nifi + 10 seconds + Open + + + + + diff --git a/apps/nifi/conf/stateless-logback.xml b/apps/nifi/conf/stateless-logback.xml new file mode 100644 index 00000000..0b8602f9 --- /dev/null +++ b/apps/nifi/conf/stateless-logback.xml @@ -0,0 +1,77 @@ + + + + + + true + + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-stateless.log + + + ${org.apache.nifi.bootstrap.config.log.dir}/nifi-stateless_%d{yyyy-MM-dd_HH}.%i.log + 100MB + + 30 + + true + + %date %level [%thread] %logger{40} %msg%n + + + + + + %date %level [%thread] %logger{40} %msg%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/nifi/conf/stateless.properties b/apps/nifi/conf/stateless.properties new file mode 100644 index 00000000..ab7e397d --- /dev/null +++ b/apps/nifi/conf/stateless.properties @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# NAR and Working Directories # +nifi.stateless.nar.directory=./lib +nifi.stateless.working.directory=./work/stateless + +# Security Properties # +nifi.stateless.security.keystore= +nifi.stateless.security.keystoreType= +nifi.stateless.security.keystorePasswd= +nifi.stateless.security.keyPasswd= +nifi.stateless.security.truststore= +nifi.stateless.security.truststoreType= +nifi.stateless.security.truststorePasswd= +nifi.stateless.sensitive.props.key= + +# Extension Client Configuration # +# Zero or more Nexus repositories may be specified here. +# The following client communicates with Maven Central. To use it, uncomment the following 4 lines. +# Additional clients can be added by adding duplicate properties but changing mvn-central to a different key. +#nifi.stateless.extension.client.mvn-central.type=nexus +#nifi.stateless.extension.client.mvn-central.timeout=30 sec +#nifi.stateless.extension.client.mvn-central.baseUrl=https://repo1.maven.org/maven2/ +#nifi.stateless.extension.client.mvn-central.useSslContext=false + +# Kerberos Properties # +nifi.stateless.kerberos.krb5.file=/etc/krb5.conf diff --git a/apps/nifi/conf/users.xml b/apps/nifi/conf/users.xml new file mode 100644 index 00000000..1bdbe395 --- /dev/null +++ b/apps/nifi/conf/users.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/apps/nifi/conf/zookeeper.properties b/apps/nifi/conf/zookeeper.properties new file mode 100644 index 00000000..389b6397 --- /dev/null +++ b/apps/nifi/conf/zookeeper.properties @@ -0,0 +1,72 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +# + +# clientPort=2181 +initLimit=10 +autopurge.purgeInterval=24 +syncLimit=5 +tickTime=2000 +dataDir=./state/zookeeper +autopurge.snapRetainCount=30 + +# Embedded/distributed ZK TLS connection support can be activated by setting these properties at minimum: +# +# secureClientPort=2281 +# serverCnxnFactory=org.apache.zookeeper.server.NettyServerCnxnFactory + +# Most TLS configurations will set these values as well: +# +# ssl.keyStore.location=/example/path/to/key-store.jks +# ssl.keyStore.password=change this value to the actual value in your installation +# ssl.trustStore.location=/example/path/to/trust-store.jks +# ssl.trustStore.password=change this value to the actual value in your installation +# ssl.hostnameVerification=false +# +# Note that many ZK parameters can set as Java system properties, refer to the ZK admin guide for details: +# +# https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_configuration + +# Other common settings: +# +# client.portUnification=true +# admin.enableServer=false + +# The server string has changed as of 3.5.5 and the client port is now specified at the end of the server string: +# https://zookeeper.apache.org/doc/r3.5.5/zookeeperReconfig.html#sc_reconfig_clientport +# +# Specifies the servers that are part of this zookeeper ensemble. For +# every NiFi instance running an embedded zookeeper, there needs to be +# a server entry below. Client port is now specified at the end of the string +# after a semi-colon. +# +# For instance: +# +# server.1=nifi-node1-hostname:2888:3888;2181 +# server.2=nifi-node2-hostname:2888:3888;2181 +# server.3=nifi-node3-hostname:2888:3888;2181 +# +# The index of the server corresponds to the myid file that gets created +# in the dataDir of each node running an embedded zookeeper. See the +# administration guide for more details. +# + +# server.1= \ No newline at end of file diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile new file mode 100644 index 00000000..e8c5cb79 --- /dev/null +++ b/apps/nifi/docker/Makefile @@ -0,0 +1,583 @@ +SHELL := /usr/bin/env bash +.SHELLFLAGS := -o pipefail -c + +DC_START_CMD := up -d +DC_STOP_CMD := stop +DC_DOWN_CMD := down +REMOTE_COMPOSE_FILE ?= services.yml +REMOTE_SSH_KEY ?= +REMOTE_SSH_OPTS ?= +REMOTE_SSH_KEY_ARG = $(if $(strip $(REMOTE_SSH_KEY)),-i $(REMOTE_SSH_KEY),) +SECURITY_DIR ?= ../security +SECURITY_SCRIPTS_DIR ?= $(SECURITY_DIR)/scripts +SECURITY_CERTIFICATES_DIR ?= $(SECURITY_DIR)/certificates +SECURITY_ENV_DIR ?= $(SECURITY_DIR)/env +OPENSEARCH_CERT_NAMES ?= +COGSTACK_CONFIG_DIR ?= +export COGSTACK_CONFIG_DIR + +define WITH_ENV +source ./export_env_vars.sh || exit $$?; +endef + +# list all make targets in this file +help: ## List available targets with descriptions + @echo "Available targets:" + @awk '\ + function default_desc(target) { \ + if (target ~ /^start-/) return "Start a service or service group"; \ + if (target ~ /^stop-/) return "Stop a service or service group"; \ + if (target ~ /^delete-/) return "Delete related containers/images/volumes"; \ + if (target ~ /^git-/) return "Run a git helper script"; \ + if (target == "load-env") return "Load variables from export_env_vars.sh"; \ + if (target == "show-env") return "Print current environment variables"; \ + if (target == "down-all") return "Stop all services from services.yml"; \ + if (target == "cleanup") return "Stop all services and remove volumes"; \ + return "(no description)"; \ + } \ + /^[a-zA-Z0-9][a-zA-Z0-9_-]*:/ { \ + raw=$$0; \ + target=raw; \ + sub(/:.*/, "", target); \ + if (!(target in seen)) { \ + seen[target]=1; \ + } \ + if (index(raw, "##") > 0) { \ + description=raw; \ + sub(/^.*##[[:space:]]*/, "", description); \ + desc[target]=description; \ + } \ + } \ + END { \ + for (target in seen) { \ + description=desc[target]; \ + if (description == "") description=default_desc(target); \ + print target "\t" description; \ + } \ + } \ + ' $(MAKEFILE_LIST) | sort | awk -F '\t' '{printf " %-28s %s\n", $$1, $$2}' + +.PHONY: help + +# utility commands + +git-freeze-security: ## Apply restricted git settings for safer shell operations + @../scripts/git_freeze_security.sh + +git-unfreeze-security: ## Revert restricted git settings + @../scripts/git_unfreeze_security.sh + +git-init-submodules: ## Initialize submodules at the commits recorded by this checkout + @../scripts/git_init_submodules_in_repo.sh + +git-update-submodules: ## Explicitly upgrade direct submodules for review (never stages or commits) + @../scripts/git_update_submodules_in_repo.sh + +.PHONY: git-init-submodules git-update-submodules + +load-env: ## Load variables from export_env_vars.sh in a subshell + $(WITH_ENV) echo "Environment variables loaded." + +show-env: ## Print sorted environment variables after loading export_env_vars.sh + ${WITH_ENV} >/dev/null 2>&1; printenv | sort + +init-security-root-ca: ## Generate the shared root CA only when no CA material exists + @set -euo pipefail; \ + $(WITH_ENV) \ + source "$${COGSTACK_CERTIFICATES_GENERAL_ENV_FILE}"; \ + root_dir="$(SECURITY_CERTIFICATES_DIR)/root"; \ + if [[ -f "$$root_dir/$${ROOT_CERTIFICATE_NAME}.key" \ + && -f "$$root_dir/$${ROOT_CERTIFICATE_NAME}.pem" \ + && -f "$$root_dir/$${ROOT_CERTIFICATE_NAME}.p12" \ + && -f "$$root_dir/$${ROOT_CERTIFICATE_NAME}-keystore.jks" \ + && -f "$$root_dir/$${ROOT_CERTIFICATE_NAME}-truststore.jks" ]]; then \ + echo "Root CA certificates already exist; leaving them unchanged."; \ + elif [[ -d "$$root_dir" && -n "$$(find "$$root_dir" -mindepth 1 -maxdepth 1 -print -quit)" ]]; then \ + echo "ERROR: $$root_dir contains an incomplete root CA set." >&2; \ + echo "Preserve and repair or explicitly replace that CA before rerunning this target." >&2; \ + exit 1; \ + else \ + echo "Generating the shared root CA certificates..."; \ + (cd "$(SECURITY_SCRIPTS_DIR)" && ./create_root_ca_cert.sh); \ + fi + +init-security-nifi: init-security-opensearch init-security-postgresql ## Prepare NiFi certificates and its search/database certificate inputs + @set -euo pipefail; \ + nifi_dir="$(SECURITY_CERTIFICATES_DIR)/nifi"; \ + if [[ -f "$$nifi_dir/nifi.key" \ + && -f "$$nifi_dir/nifi.pem" \ + && -f "$$nifi_dir/nifi.p12" \ + && -f "$$nifi_dir/nifi-keystore.jks" \ + && -f "$$nifi_dir/nifi-truststore.jks" ]]; then \ + echo "NiFi certificates already exist; leaving them unchanged."; \ + else \ + echo "Generating NiFi certificates..."; \ + (cd "$(SECURITY_SCRIPTS_DIR)" && ./create_nifi_certs.sh); \ + fi + +init-security-gitea: init-security-root-ca ## Generate a dedicated Gitea leaf certificate when it is missing + @set -euo pipefail; \ + gitea_dir="$(SECURITY_CERTIFICATES_DIR)/gitea"; \ + if [[ -f "$$gitea_dir/gitea.key" \ + && -f "$$gitea_dir/gitea.pem" \ + && -f "$$gitea_dir/gitea.crt" ]]; then \ + echo "Gitea leaf certificate already exists; leaving it unchanged."; \ + else \ + echo "Generating Gitea leaf certificate..."; \ + (cd "$(SECURITY_SCRIPTS_DIR)" && bash ./create_gitea_certs.sh); \ + fi + +init-security-opensearch: init-security-root-ca ## Generate OpenSearch node, client, and admin certificates when missing + @set -euo pipefail; \ + $(WITH_ENV) \ + source "$${COGSTACK_CERTIFICATES_ELASTICSEARCH_ENV_FILE}"; \ + if [[ -n "$(strip $(OPENSEARCH_CERT_NAMES))" ]]; then \ + read -r -a node_names <<< "$(strip $(OPENSEARCH_CERT_NAMES))"; \ + else \ + node_names=("$$ES_INSTANCE_NAME_1" "$$ES_INSTANCE_NAME_2" "$$ES_INSTANCE_NAME_3"); \ + fi; \ + opensearch_dir="$(SECURITY_CERTIFICATES_DIR)/elastic/opensearch"; \ + node_certificates_missing=0; \ + for node_name in "$${node_names[@]}"; do \ + node_dir="$$opensearch_dir/elasticsearch/$$node_name"; \ + for suffix in .crt .key .p12 -keystore.jks -truststore.key; do \ + if [[ ! -f "$$node_dir/$$node_name$$suffix" ]]; then \ + node_certificates_missing=1; \ + break 2; \ + fi; \ + done; \ + done; \ + if [[ ! -f "$$opensearch_dir/elastic-stack-ca.crt.pem" ]]; then \ + node_certificates_missing=1; \ + fi; \ + if (( node_certificates_missing )); then \ + echo "Generating OpenSearch node certificates for: $${node_names[*]}"; \ + (cd "$(SECURITY_SCRIPTS_DIR)" && ./create_opensearch_node_cert.sh "$${node_names[@]}"); \ + else \ + echo "OpenSearch node certificates already exist; leaving them unchanged."; \ + fi; \ + if [[ -f "$$opensearch_dir/admin.crt" \ + && -f "$$opensearch_dir/admin.key.pem" \ + && -f "$$opensearch_dir/$${ES_CLIENT_CERT_NAME}.pem" \ + && -f "$$opensearch_dir/$${ES_CLIENT_CERT_NAME}.key" ]]; then \ + echo "OpenSearch client and admin certificates already exist; leaving them unchanged."; \ + else \ + echo "Generating OpenSearch client and admin certificates..."; \ + (cd "$(SECURITY_SCRIPTS_DIR)" && ./create_opensearch_client_admin_certs.sh); \ + fi + +init-security-elasticsearch: ## Generate native Elasticsearch certificates when the output directory is absent + @set -euo pipefail; \ + $(WITH_ENV) \ + source "$${COGSTACK_CERTIFICATES_ELASTICSEARCH_ENV_FILE}"; \ + elasticsearch_dir="$(SECURITY_CERTIFICATES_DIR)/elastic/elasticsearch"; \ + certificate_set_complete=1; \ + for required_file in \ + "elastic-stack-ca.crt.pem" \ + "elastic-stack-ca.p12" \ + "elasticsearch/$${ES_INSTANCE_NAME_1}/$${ES_INSTANCE_NAME_1}.crt" \ + "elasticsearch/$${ES_INSTANCE_NAME_1}/$${ES_INSTANCE_NAME_1}.key" \ + "elasticsearch/$${ES_INSTANCE_NAME_2}/$${ES_INSTANCE_NAME_2}.crt" \ + "elasticsearch/$${ES_INSTANCE_NAME_2}/$${ES_INSTANCE_NAME_2}.key" \ + "elasticsearch/$${ES_INSTANCE_NAME_3}/$${ES_INSTANCE_NAME_3}.crt" \ + "elasticsearch/$${ES_INSTANCE_NAME_3}/$${ES_INSTANCE_NAME_3}.key"; do \ + if [[ ! -f "$$elasticsearch_dir/$$required_file" ]]; then \ + certificate_set_complete=0; \ + break; \ + fi; \ + done; \ + if (( certificate_set_complete )); then \ + echo "Native Elasticsearch certificates already exist; leaving them unchanged."; \ + elif [[ -e "$$elasticsearch_dir" ]]; then \ + echo "ERROR: $$elasticsearch_dir exists but contains an incomplete certificate set." >&2; \ + echo "Move or remove that directory after preserving anything needed, then rerun this target." >&2; \ + exit 1; \ + else \ + echo "Generating native Elasticsearch certificates with Docker..."; \ + (cd "$(SECURITY_SCRIPTS_DIR)" && ./create_es_native_certs.sh); \ + fi + +init-security-search: ## Generate certificates for ELASTICSEARCH_VERSION from elasticsearch.env + @set -euo pipefail; \ + $(WITH_ENV) \ + source "$${COGSTACK_ELASTICSEARCH_ENV_FILE}"; \ + case "$${ELASTICSEARCH_VERSION}" in \ + opensearch|elasticsearch) \ + $(MAKE) --no-print-directory "init-security-$${ELASTICSEARCH_VERSION}" \ + ;; \ + *) \ + echo "ERROR: unsupported ELASTICSEARCH_VERSION '$${ELASTICSEARCH_VERSION}'." >&2; \ + exit 1 \ + ;; \ + esac + +init-security-postgresql: init-security-root-ca ## Generate missing PostgreSQL TLS bundles, preserving supplied certificates + @$(WITH_ENV) SECURITY_CERTIFICATES_DIR="$(SECURITY_CERTIFICATES_DIR)" bash "$(SECURITY_SCRIPTS_DIR)/create_postgres_certs.sh" + +init-security: ## Generate missing NiFi, PostgreSQL, Gitea, and selected search-backend certificates + @$(MAKE) --no-print-directory init-security-nifi + @$(MAKE) --no-print-directory init-security-gitea + @$(MAKE) --no-print-directory init-security-search + +.PHONY: init-security init-security-root-ca init-security-nifi init-security-postgresql init-security-gitea init-security-opensearch init-security-elasticsearch init-security-search + +remote-deploy-service: ## Deploy one or more services to a remote machine via SSH + docker compose +remote-deploy-service: _check-remote-params + @ssh $(REMOTE_SSH_KEY_ARG) $(REMOTE_SSH_OPTS) "$(REMOTE_HOST)" 'cd "$(REMOTE_REPO_DIR)/deploy" && set -a && source ./export_env_vars.sh && docker compose -f "$(REMOTE_COMPOSE_FILE)" up -d $(REMOTE_SERVICES)' + +remote-stop-service: ## Stop one or more services on a remote machine via SSH + docker compose +remote-stop-service: _check-remote-params + @ssh $(REMOTE_SSH_KEY_ARG) $(REMOTE_SSH_OPTS) "$(REMOTE_HOST)" 'cd "$(REMOTE_REPO_DIR)/deploy" && set -a && source ./export_env_vars.sh && docker compose -f "$(REMOTE_COMPOSE_FILE)" stop $(REMOTE_SERVICES)' + +remote-delete-service: ## Delete one or more remote service containers via SSH + docker compose rm +remote-delete-service: _check-remote-params + @ssh $(REMOTE_SSH_KEY_ARG) $(REMOTE_SSH_OPTS) "$(REMOTE_HOST)" 'cd "$(REMOTE_REPO_DIR)/deploy" && set -a && source ./export_env_vars.sh && docker compose -f "$(REMOTE_COMPOSE_FILE)" rm -f -s $(REMOTE_SERVICES)' + +_check-remote-params: + @if [ -z "$(REMOTE_HOST)" ]; then \ + echo "REMOTE_HOST is required (example: REMOTE_HOST=user@machine)"; \ + exit 1; \ + fi + @if [ -z "$(REMOTE_REPO_DIR)" ]; then \ + echo "REMOTE_REPO_DIR is required (example: REMOTE_REPO_DIR=/opt/cogstack_nifi)"; \ + exit 1; \ + fi + @if [ -z "$(REMOTE_SERVICES)" ]; then \ + echo "REMOTE_SERVICES is required (example: REMOTE_SERVICES='nifi nifi-nginx')"; \ + exit 1; \ + fi + +.PHONY: remote-deploy-service remote-stop-service remote-delete-service _check-remote-params + +check-nifi-resources: ## Validate NiFi heap sizes against the container memory limit + @$(WITH_ENV) python3 ../scripts/tests/check_nifi_resources.py + +check-opensearch-settings: ## Validate search credentials, encryption keys, and image versions + @$(WITH_ENV) python3 ../scripts/tests/check_opensearch_settings.py + +check-config: check-nifi-resources check-opensearch-settings ## Validate resolved settings and both core Compose files + @$(WITH_ENV) docker compose --profile "*" -f services.yml config --quiet && docker compose --profile "*" -f docker-compose.dev.yml config --quiet + +.PHONY: check-nifi-resources check-opensearch-settings check-config + +# start services + +start-nifi: check-nifi-resources ## Start NiFi and NiFi nginx (services.yml) + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) nifi nifi-nginx + +start-nifi-dev: check-nifi-resources ## Start NiFi and NiFi nginx (docker-compose.dev.yml) + $(WITH_ENV) docker compose -f docker-compose.dev.yml $(DC_START_CMD) nifi nifi-nginx + +start-nifi-dev-build: check-nifi-resources ## Build and start NiFi dev services + $(WITH_ENV) docker compose -f docker-compose.dev.yml up -d --build nifi nifi-nginx + +build-nifi-image: ## Build the local NiFi image without starting services + $(WITH_ENV) docker build \ + --build-arg NIFI_VERSION="$${NIFI_VERSION:-2.12.0}" \ + --build-arg NIFI_BASE_IMAGE="$${NIFI_BASE_IMAGE}" \ + --build-arg NIFI_UID="$${COGSTACK_LOCAL_UID:-1000}" \ + --build-arg NIFI_GID="$${COGSTACK_LOCAL_GID:-1000}" \ + --tag "$${NIFI_LOCAL_DOCKER_IMAGE:-cogstack/cogstack-nifi:local}" \ + --file ../Dockerfile \ + .. + +start-elastic: check-opensearch-settings ## Start elasticsearch-1, elasticsearch-2 and kibana + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) elasticsearch-1 elasticsearch-2 kibana + +start-elastic-cluster: check-opensearch-settings ## Start full 3-node Elasticsearch cluster + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) elasticsearch-1 elasticsearch-2 elasticsearch-3 + +start-elastic-1: check-opensearch-settings + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) elasticsearch-1 + +start-elastic-2: check-opensearch-settings + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) elasticsearch-2 + +start-elastic-3: check-opensearch-settings + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) elasticsearch-3 + +start-metricbeat-1: + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) metricbeat-1 + +start-metricbeat-2: + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) metricbeat-2 + +start-metricbeat-3: + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) metricbeat-3 + +start-filebeat-1: + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) filebeat-1 + +start-filebeat-2: + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) filebeat-2 + +start-filebeat-3: + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) filebeat-3 + +start-kibana: check-opensearch-settings ## Start Kibana or OpenSearch Dashboards + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) kibana + +start-ollama: ## Start the Ollama inference service + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) ollama + +start-ollama-openai-proxy: ## Build and start the OpenSearch-to-Ollama compatibility proxy + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) --build ollama-openai-proxy + +pull-ollama-model: start-ollama ## Pull the model configured by OLLAMA_MODEL + $(WITH_ENV) docker compose -f services.yml exec -T ollama ollama pull "$${OLLAMA_MODEL}" + +setup-ollama: pull-ollama-model ## Start Ollama and pull its configured model + +opensearch-ai-init: ## Create or update OpenSearch AI connectors and agents using OPENSEARCH_AI_PROVIDER + $(WITH_ENV) \ + case "$${OPENSEARCH_AI_PROVIDER:-ollama}" in \ + ollama) docker compose -f services.yml $(DC_START_CMD) --build ollama-openai-proxy ;; \ + sglang) ;; \ + *) echo "Unsupported OPENSEARCH_AI_PROVIDER: $${OPENSEARCH_AI_PROVIDER}" >&2; exit 1 ;; \ + esac && ../scripts/opensearch-ai-init.sh + +opensearch-ai-init-sglang: ## Connect all OpenSearch AI features to the locally hosted SGLang server + $(WITH_ENV) OPENSEARCH_AI_PROVIDER=sglang ../scripts/opensearch-ai-init.sh + +start-openwebui: ## Start Open WebUI and its Ollama dependency + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) open-webui + +restart-openwebui: ## Restart the Open WebUI container + $(WITH_ENV) docker compose -f services.yml restart open-webui + +status-openwebui: ## Show Open WebUI and Ollama container status + $(WITH_ENV) docker compose -f services.yml ps open-webui ollama + +logs-openwebui: ## Follow the Open WebUI logs + $(WITH_ENV) docker compose -f services.yml logs --tail=100 -f open-webui + +start-samples: ## Start the sample database service + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) samples-db && \ + docker compose -f services.yml exec -T -e PGHOST=samples-db samples-db /docker-entrypoint-initdb.d/access/configure.sh + +start-clickhouse: ## Start the ClickHouse ingestion database + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) clickhouse + +status-clickhouse: ## Show ClickHouse container status + $(WITH_ENV) docker compose -f services.yml ps clickhouse + +logs-clickhouse: ## Follow ClickHouse logs + $(WITH_ENV) docker compose -f services.yml logs --tail=100 -f clickhouse + +start-jupyter: + $(WITH_ENV) docker compose -f ../../jupyter-hub/docker/docker-compose.base.yml -f ../../jupyter-hub/docker/docker-compose.prod.yml $(DC_START_CMD) cogstack-jupyter-hub + +start-medcat-service: + $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml $(DC_START_CMD) nlp-medcat-service-production + +start-medcat-service-deid: + $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml $(DC_START_CMD) nlp-medcat-service-production-deid + +start-medcat-trainer: + $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-trainer/docker-compose-prod.yml $(DC_START_CMD) medcattrainer nginx solr + +start-production-db: + $(WITH_ENV) docker compose -f services.yml ${DC_START_CMD} cogstack-databank-db && \ + docker compose -f services.yml exec -T -e PGHOST=cogstack-databank-db cogstack-databank-db /docker-entrypoint-initdb.d/access/configure.sh + +start-production-db-mssql: ## Start SQL Server and wait for its schema initialization job + $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) cogstack-databank-db-mssql && \ + docker compose -f services.yml run --rm --no-deps cogstack-databank-db-mssql-init + +start-ocr-services: + $(WITH_ENV) docker compose -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.base.yml -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.prod.yml $(DC_START_CMD) ocr-service ocr-service-text-only + +start-git-ea: + $(WITH_ENV) docker compose -f services.yml ${DC_START_CMD} gitea + +start-data-infra: start-nifi start-elastic start-samples ## Start core data infrastructure + +start-all: start-data-infra start-medcat-service start-ocr-services ## Start all major services + +.PHONY: start-kibana start-all start-data-infra start-nifi start-nifi-dev start-nifi-dev-build build-nifi-image start-elastic start-ollama start-ollama-openai-proxy pull-ollama-model setup-ollama opensearch-ai-init opensearch-ai-init-sglang start-openwebui restart-openwebui status-openwebui logs-openwebui start-samples start-clickhouse status-clickhouse logs-clickhouse start-jupyter + + +# stop services +# +stop-nifi: ## Stop NiFi and NiFi nginx (services.yml) + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) nifi nifi-nginx + +stop-nifi-dev: ## Stop NiFi and NiFi nginx (docker-compose.dev.yml) + $(WITH_ENV) docker compose -f docker-compose.dev.yml $(DC_STOP_CMD) nifi nifi-nginx + +delete-nifi: delete-nifi-containers ## Delete NiFi containers only + +delete-nifi-containers: ## Remove NiFi containers from services.yml + $(WITH_ENV) docker compose -f services.yml rm -f -s nifi nifi-nginx + +delete-nifi-dev-containers: ## Remove NiFi containers from docker-compose.dev.yml + $(WITH_ENV) docker compose -f docker-compose.dev.yml rm -f -s nifi nifi-nginx + +delete-nifi-images: ## Delete NiFi images referenced in services.yml + $(WITH_ENV) images="$$(docker compose -f services.yml config --images nifi nifi-nginx | sort -u)"; \ + if [ -n "$$images" ]; then \ + docker image rm -f $$images; \ + else \ + echo "No NiFi images found in services.yml"; \ + fi + +delete-nifi-dev-images: ## Delete NiFi images referenced in docker-compose.dev.yml + $(WITH_ENV) images="$$(docker compose -f docker-compose.dev.yml config --images nifi nifi-nginx | sort -u)"; \ + if [ -n "$$images" ]; then \ + docker image rm -f $$images; \ + else \ + echo "No NiFi images found in docker-compose.dev.yml"; \ + fi + +delete-nifi-volumes: ## Delete NiFi volumes + $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) -v nifi nifi-nginx + +delete-elastic: ## Remove Elasticsearch and Kibana containers + $(WITH_ENV) docker compose -f services.yml rm -f -s elasticsearch-1 elasticsearch-2 elasticsearch-3 kibana + +delete-elastic-volumes: ## Delete Elasticsearch and Kibana volumes + $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) -v elasticsearch-1 elasticsearch-2 elasticsearch-3 kibana + +delete-ollama: ## Remove the Ollama container but preserve downloaded models + $(WITH_ENV) docker compose -f services.yml rm -f -s ollama + +delete-ollama-openai-proxy: ## Remove the OpenSearch-to-Ollama compatibility proxy container + $(WITH_ENV) docker compose -f services.yml rm -f -s ollama-openai-proxy + +delete-ollama-proxy: delete-ollama-openai-proxy ## Alias for delete-ollama-openai-proxy + +delete-openwebui: ## Remove the Open WebUI container but preserve its data + $(WITH_ENV) docker compose -f services.yml rm -f -s open-webui + +delete-databank: + $(WITH_ENV) docker compose -f services.yml rm -f -s cogstack-databank-db cogstack-databank-db-mssql-init cogstack-databank-db-mssql + +delete-databank-volumes: + $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) -v cogstack-databank-db cogstack-databank-db-mssql + +delete-samples-db: + $(WITH_ENV) docker compose -f services.yml rm -f -s samples-db + +delete-samples-db-volumes: + $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) -v samples-db + +delete-clickhouse: ## Remove the ClickHouse container but preserve its data + $(WITH_ENV) docker compose -f services.yml rm -f -s clickhouse + +delete-medcat-trainer: ## Remove MedCAT Trainer containers + $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-trainer/docker-compose-prod.yml rm -f -s medcattrainer nginx solr + +delete-medcat-trainer-volumes: ## Delete MedCAT Trainer volumes + $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-trainer/docker-compose-prod.yml $(DC_DOWN_CMD) -v medcattrainer nginx solr + +delete-jupyter: ## Remove Jupyter container + $(WITH_ENV) docker compose -f ../../jupyter-hub/docker/docker-compose.base.yml -f ../../jupyter-hub/docker/docker-compose.prod.yml rm -f -s cogstack-jupyter-hub + +delete-medcat-service: ## Remove MedCAT service container + $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml rm -f -s nlp-medcat-service-production + +delete-medcat-service-deid: ## Remove MedCAT service (deid) container + $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml rm -f -s nlp-medcat-service-production-deid + +delete-ocr-services: ## Remove OCR service containers + $(WITH_ENV) docker compose -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.base.yml -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.prod.yml rm -f -s ocr-service ocr-service-text-only + +make-delete-jupyter: delete-jupyter ## Alias for delete-jupyter + +make-delete-medcat-service: delete-medcat-service ## Alias for delete-medcat-service + +make-delete-medcat-service-deid: delete-medcat-service-deid ## Alias for delete-medcat-service-deid + +make-delete-ocr-services: delete-ocr-services ## Alias for delete-ocr-services + +stop-elastic: ## Stop elasticsearch-1, elasticsearch-2 and kibana + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) elasticsearch-1 elasticsearch-2 kibana + +stop-elastic-cluster: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) elasticsearch-1 elasticsearch-2 + +stop-elastic-1: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) elasticsearch-1 + +stop-elastic-2: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) elasticsearch-2 + +stop-elastic-3: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) elasticsearch-3 + +stop-metricbeat-1: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) metricbeat-1 + +stop-metricbeat-2: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) metricbeat-2 + +stop-filebeat-1: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) filebeat-1 + +stop-filebeat-2: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) filebeat-2 + +stop-filebeat-3: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) filebeat-3 + +stop-kibana: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) kibana + +stop-ollama: ## Stop the Ollama inference service + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) ollama + +stop-openwebui: ## Stop the Open WebUI service + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) open-webui + +stop-samples: ## Stop the sample database service + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) samples-db + +stop-clickhouse: ## Stop the ClickHouse ingestion database + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) clickhouse + +stop-jupyter: + $(WITH_ENV) docker compose -f ../../jupyter-hub/docker/docker-compose.base.yml -f ../../jupyter-hub/docker/docker-compose.yml $(DC_STOP_CMD) cogstack-jupyter-hub + +stop-medcat-trainer: + $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-trainer/docker-compose-prod.yml $(DC_STOP_CMD) medcattrainer nginx solr + +stop-medcat-service: + $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml $(DC_STOP_CMD) nlp-medcat-service-production + +stop-medcat-service-deid: + $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml $(DC_STOP_CMD) nlp-medcat-service-production-deid + +stop-git-ea: + $(WITH_ENV) docker compose -f services.yml ${DC_STOP_CMD} gitea + +stop-ocr-services: + $(WITH_ENV) docker compose -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.base.yml -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.prod.yml $(DC_STOP_CMD) ocr-service ocr-service-text-only + +stop-production-db: + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) cogstack-databank-db + +stop-production-db-mssql: ## Stop the SQL Server initializer and server without removing data + $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) cogstack-databank-db-mssql-init cogstack-databank-db-mssql + +.PHONY: start-production-db-mssql stop-production-db-mssql + +stop-data-infra: stop-nifi stop-elastic stop-samples ## Stop core data infrastructure + +stop-all: stop-data-infra stop-jupyter stop-medcat-service stop-ocr-services ## Stop all major services + +.PHONY: stop-data-infra stop-nifi stop-nifi-dev delete-nifi delete-nifi-containers delete-nifi-dev-containers delete-nifi-images delete-nifi-dev-images delete-nifi-volumes delete-elastic delete-elastic-volumes delete-ollama delete-ollama-openai-proxy delete-ollama-proxy delete-openwebui delete-databank delete-databank-volumes delete-samples-db delete-samples-db-volumes delete-clickhouse delete-medcat-trainer delete-medcat-trainer-volumes delete-jupyter delete-medcat-service delete-medcat-service-deid delete-ocr-services make-delete-jupyter make-delete-medcat-service make-delete-medcat-service-deid make-delete-ocr-services stop-elastic stop-ollama stop-openwebui stop-samples stop-clickhouse stop-jupyter + + +# cleanup +# +down-all: ## Run docker compose down for services.yml + $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) + +# deletes volumes associated with containers +cleanup: ## Run docker compose down -v for services.yml + $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) -v + +.PHONY: down-all cleanup + +# Expose Kubernetes commands when their deployment helpers are present. +-include kubernetes/Makefile diff --git a/apps/nifi/docker/docker-compose.dev.yml b/apps/nifi/docker/docker-compose.dev.yml new file mode 100644 index 00000000..c3b5f313 --- /dev/null +++ b/apps/nifi/docker/docker-compose.dev.yml @@ -0,0 +1,304 @@ +#---------------------------------------------------------------------------# +# Common snippets / anchors # +#---------------------------------------------------------------------------# + +x-nifi-logging-common: &nifi-logging-common + driver: "json-file" + options: + max-size: ${NIFI_DOCKER_LOG_SIZE_PER_FILE:-250m} + max-file: ${NIFI_DOCKER_LOG_NUM_FILES:-10} + +x-env-files: + all: &all-env + - "${COGSTACK_PROJECT_ENV_FILE:-./project.env}" + - "${COGSTACK_GENERAL_ENV_FILE:-./general.env}" + - "${COGSTACK_NIFI_ENV_FILE:-./nifi.env}" + - "${COGSTACK_GITEA_ENV_FILE:-./gitea.env}" + - "${COGSTACK_NGINX_ENV_FILE:-./nginx.env}" + - "${COGSTACK_TELEMETRY_ENV_FILE:-./telemetry.env}" + - "${COGSTACK_ELASTICSEARCH_ENV_FILE:-./elasticsearch.env}" + - "${COGSTACK_NETWORK_SETTINGS_ENV_FILE:-./network_settings.env}" + - "${COGSTACK_USERS_NIFI_ENV_FILE:-../security/env/users_nifi.env}" + - "${COGSTACK_USERS_NGINX_ENV_FILE:-../security/env/users_nginx.env}" + - "${COGSTACK_USERS_ELASTICSEARCH_ENV_FILE:-../security/env/users_elasticsearch.env}" + - "${COGSTACK_CERTIFICATES_GENERAL_ENV_FILE:-../security/env/certificates_general.env}" + - "${COGSTACK_CERTIFICATES_ELASTICSEARCH_ENV_FILE:-../security/env/certificates_elasticsearch.env}" + - "${COGSTACK_CERTIFICATES_NIFI_ENV_FILE:-../security/env/certificates_nifi.env}" + + search: &es-env + - "${COGSTACK_NETWORK_SETTINGS_ENV_FILE:-./network_settings.env}" + - "${COGSTACK_ELASTICSEARCH_ENV_FILE:-./elasticsearch.env}" + - "${COGSTACK_USERS_ELASTICSEARCH_ENV_FILE:-../security/env/users_elasticsearch.env}" + - "${COGSTACK_CERTIFICATES_ELASTICSEARCH_ENV_FILE:-../security/env/certificates_elasticsearch.env}" + + nifi-nginx: &nifi-nginx-env-files + - "${COGSTACK_NGINX_ENV_FILE:-./nginx.env}" + +x-env: + nifi: &nifi-env + POSTGRES_SAMPLES_DB_NAME: ${POSTGRES_SAMPLES_DB_NAME:-db_samples} + POSTGRES_SAMPLES_JDBC_URL: ${POSTGRES_SAMPLES_JDBC_URL:-jdbc:postgresql://samples-db:5432/${POSTGRES_SAMPLES_DB_NAME:-db_samples}?sslmode=verify-full&sslrootcert=/run/database-cas/samples-ca.crt} + POSTGRES_INGEST_USER_SAMPLES: ${POSTGRES_INGEST_USER_SAMPLES:-cogstack_samples} + POSTGRES_INGEST_PASSWORD_SAMPLES: ${POSTGRES_INGEST_PASSWORD_SAMPLES:?Set the sample ingestion password} + DATABASE_DB_NAME: ${DATABASE_DB_NAME:-cogstack} + DATABASE_INGEST_USER: ${DATABASE_INGEST_USER:-cogstack_ingest} + DATABASE_INGEST_PASSWORD: ${DATABASE_INGEST_PASSWORD:?Set the PostgreSQL ingestion password} + MSSQL_INGEST_USER: ${MSSQL_INGEST_USER:-cogstack_ingest} + MSSQL_INGEST_PASSWORD: ${MSSQL_INGEST_PASSWORD:?Set the MSSQL ingestion password} + + # Apache's native startup settings; existing deployment env names remain supported. + AUTH: ${AUTH:-tls} + NIFI_SECURITY_USER_AUTHORIZER: ${NIFI_SECURITY_USER_AUTHORIZER:-single-user-authorizer} + NIFI_SECURITY_USER_LOGIN_IDENTITY_PROVIDER: ${NIFI_SECURITY_USER_LOGIN_IDENTITY_PROVIDER:-single-user-provider} + SINGLE_USER_CREDENTIALS_USERNAME: ${SINGLE_USER_CREDENTIALS_USERNAME:-${NIFI_SINGLE_USER_CREDENTIALS_USERNAME}} + SINGLE_USER_CREDENTIALS_PASSWORD: ${SINGLE_USER_CREDENTIALS_PASSWORD:-${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD}} + KEYSTORE_PATH: ${KEYSTORE_PATH:-${NIFI_KEYSTORE_PATH}} + KEYSTORE_TYPE: ${KEYSTORE_TYPE:-${NIFI_KEYSTORE_TYPE}} + KEYSTORE_PASSWORD: ${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD}} + TRUSTSTORE_PATH: ${TRUSTSTORE_PATH:-${NIFI_TRUSTSTORE_PATH}} + TRUSTSTORE_TYPE: ${TRUSTSTORE_TYPE:-${NIFI_TRUSTSTORE_TYPE}} + TRUSTSTORE_PASSWORD: ${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD}} + NIFI_WEB_HTTPS_PORT: ${NIFI_WEB_HTTPS_PORT:-${NIFI_INTERNAL_PORT:-8443}} + NIFI_REMOTE_INPUT_SOCKET_PORT: ${NIFI_REMOTE_INPUT_SOCKET_PORT:-${NIFI_INPUT_SOCKET_PORT:-10000}} + PYTHONPATH: ${NIFI_PYTHONPATH:-/opt/nifi/nifi-current/python/framework} + JVM_OPTS: ${NIFI_JVM_OPTS:--XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+ParallelRefProcEnabled -Djava.security.egd=file:/dev/./urandom} + + nifi-nginx: &nifi-nginx-env + NIFI_INTERNAL_PORT_NGINX: ${NIFI_INTERNAL_PORT_NGINX:-8443} + NIFI_WEB_PROXY_PORT: ${NIFI_WEB_PROXY_PORT:-8443} + NIFI_INTERNAL_PORT: ${NIFI_INTERNAL_PORT:-8443} + NIFI_UPSTREAM_HOST: ${NIFI_UPSTREAM_HOST:-nifi} + NIFI_UPSTREAM_PORT: ${NIFI_UPSTREAM_PORT:-${NIFI_INTERNAL_PORT:-8443}} + NIFI_UPSTREAM_TLS_NAME: ${NIFI_UPSTREAM_TLS_NAME:-nifi} + +x-mounts: + nifi: &nifi-volumes + # Drivers + - ../drivers:/opt/nifi/drivers:ro + + # User overrides bundled in the image + - ../user_scripts:/opt/nifi/user_scripts:rw + - ../user_schemas:/opt/nifi/user_schemas:ro + + # Python processors (NiFi 2.x) + - ../user_python_extensions:/opt/nifi/nifi-current/python_extensions:rw + + # Security certificates + - ../security/certificates/nifi:/security/certificates/nifi:ro + - ../security/certificates/elastic/opensearch/elasticsearch:/security/certificates/elastic/opensearch/elasticsearch:ro + - ../security/certificates/elastic/opensearch/elastic-stack-ca.crt.pem:/security/certificates/elastic/opensearch/elastic-stack-ca.crt.pem:ro + - ../security/certificates/elastic/opensearch/es_kibana_client.pem:/security/certificates/elastic/opensearch/es_kibana_client.pem:ro + - ../security/certificates/elastic/opensearch/es_kibana_client.key:/security/certificates/elastic/opensearch/es_kibana_client.key:ro + - ../security/certificates/root/root-ca.pem:/security/certificates/root/root-ca.pem:ro + # Database clients receive only the public CA from each TLS bundle. + - type: bind + source: ${POSTGRES_SAMPLES_TLS_DIR:-../security/certificates/postgresql/samples}/ca.crt + target: /run/database-cas/samples-ca.crt + read_only: true + bind: + create_host_path: false + - type: bind + source: ${POSTGRES_DATABANK_TLS_DIR:-../security/certificates/postgresql/databank}/ca.crt + target: /run/database-cas/databank-ca.crt + read_only: true + bind: + create_host_path: false + + # Apache startup configures image defaults in this persistent, writable directory. + - nifi-vol-conf:/opt/nifi/nifi-current/conf + + # Ingest data directory + - ${NIFI_DATA_PATH:-../data/}:/data/:rw + + # MedCAT models + - ${NIFI_MEDCAT_SERVICE_MODEL_PRODUCTION_PATH:-../services/cogstack-nlp/medcat-service/models/}:/opt/models:rw + + # NiFi repositories/state + - nifi-vol-logs:/opt/nifi/nifi-current/logs + - nifi-vol-provenance:/opt/nifi/nifi-current/provenance_repository + - nifi-vol-database:/opt/nifi/nifi-current/database_repository + - nifi-vol-flowfiles:/opt/nifi/nifi-current/flowfile_repository + - nifi-vol-content:/opt/nifi/nifi-current/content_repository + - nifi-vol-state:/opt/nifi/nifi-current/state + + # Flowfile error output + - nifi-vol-errors:/opt/nifi/pipeline/flowfile-errors + + nifi-nginx-tmpfs: &nifi-nginx-tmpfs + - /tmp:mode=1777 + + nifi-nginx: &nifi-nginx-volumes + - ../services/nginx/sites-enabled:/etc/nginx/sites-enabled:ro + - ../security/certificates/nifi:/certificates/nifi:ro + - ../security/certificates/root/root-ca.pem:/certificates/root/root-ca.pem:ro + + otel-collector: &otel-collector-volumes + - ./observability/otel-collector.yaml:/etc/otelcol-contrib/config.yaml:ro + + data-prepper: &data-prepper-volumes + - ./observability/data-prepper/config/data-prepper-config.yaml:/usr/share/data-prepper/config/data-prepper-config.yaml:ro + - ./observability/data-prepper/pipelines:/usr/share/data-prepper/pipelines:ro + +x-networks: + cognet: &cognet + - cognet + +x-common-hosts: &common-hosts + - ${ELASTICSEARCH_1_HOST_NAME:-test-1:0.0.0.0} + - ${ELASTICSEARCH_2_HOST_NAME:-test-2:0.0.0.0} + - ${ELASTICSEARCH_3_HOST_NAME:-test-3:0.0.0.0} + - ${KIBANA_HOST_NAME:-test-4:0.0.0.0} + - ${NIFI_HOST_NAME:-test-5:0.0.0.0} + +x-common-ulimits: &common-ulimits + ulimits: + nofile: + soft: 65535 + hard: 65535 + nproc: 65535 + memlock: + soft: -1 + hard: -1 + +x-nifi-common: &nifi-common + <<: *common-ulimits + restart: unless-stopped + env_file: *all-env + extra_hosts: *common-hosts + networks: *cognet +#---------------------------------------------------------------------------# +# Used services # +#---------------------------------------------------------------------------# +services: + +#---------------------------------------------------------------------------# +# NiFi webapp # +#---------------------------------------------------------------------------# + nifi: + <<: *nifi-common + image: ${NIFI_LOCAL_DOCKER_IMAGE:-cogstack/cogstack-nifi:local} + pull_policy: build + build: + context: .. + dockerfile: Dockerfile + args: + NIFI_VERSION: ${NIFI_VERSION:-2.12.0} + NIFI_BASE_IMAGE: ${NIFI_BASE_IMAGE:?Source deploy/export_env_vars.sh first} + NIFI_UID: ${COGSTACK_LOCAL_UID:-1000} + NIFI_GID: ${COGSTACK_LOCAL_GID:-1000} + container_name: cogstack-nifi + hostname: nifi + shm_size: ${NIFI_DOCKER_SHM_SIZE:-"1g"} + environment: *nifi-env + deploy: + resources: + limits: + cpus: "${NIFI_DOCKER_CPU_MAX}" + memory: "${NIFI_DOCKER_RAM}" + reservations: + cpus: "${NIFI_DOCKER_CPU_MIN}" + memory: "${NIFI_DOCKER_RAM}" + volumes: *nifi-volumes + + stop_grace_period: 120s + ports: + - "${NIFI_OUTPUT_PORT:-8082}:${NIFI_INTERNAL_PORT:-8443}" + - "${NIFI_INPUT_SOCKET_PORT:-10000}" + logging: *nifi-logging-common + + nifi-nginx: + pull_policy: build + build: + context: ../services/nginx + dockerfile: Dockerfile + args: + NGINX_UID: ${COGSTACK_LOCAL_UID:-1000} + NGINX_GID: ${COGSTACK_LOCAL_GID:-1000} + container_name: cogstack-nifi-nginx + restart: always + shm_size: ${NGINX_SHM_SIZE:-512mb} + env_file: *nifi-nginx-env-files + environment: *nifi-nginx-env + stop_grace_period: 90s + read_only: true + tmpfs: *nifi-nginx-tmpfs + deploy: + resources: + limits: + cpus: "${NGINX_DOCKER_CPU_MAX}" + memory: "${NGINX_DOCKER_RAM}" + reservations: + cpus: "${NGINX_DOCKER_CPU_MIN}" + memory: "${NGINX_DOCKER_RAM}" + volumes: *nifi-nginx-volumes + ports: + - "${NIFI_EXTERNAL_PORT_NGINX:-8443}:${NIFI_INTERNAL_PORT_NGINX:-8443}" + networks: *cognet + extra_hosts: *common-hosts + logging: *nifi-logging-common + +#---------------------------------------------------------------------------# +# Observability stack # +#---------------------------------------------------------------------------# + otel-collector: + image: ${OTEL_COLLECTOR_DOCKER_IMAGE:?Source deploy/export_env_vars.sh first} + container_name: cogstack-otel-collector + restart: unless-stopped + command: ["--config=/etc/otelcol-contrib/config.yaml"] + env_file: *all-env + volumes: *otel-collector-volumes + ports: + - "${OTEL_COLLECTOR_OTLP_GRPC_PORT:-4317}:4317" + - "${OTEL_COLLECTOR_OTLP_HTTP_PORT:-4318}:4318" + - "${OTEL_COLLECTOR_HEALTH_PORT:-13133}:13133" + networks: *cognet + extra_hosts: *common-hosts + logging: *nifi-logging-common + + data-prepper: + image: ${DATA_PREPPER_DOCKER_IMAGE:?Source deploy/export_env_vars.sh first} + container_name: cogstack-data-prepper + restart: unless-stopped + env_file: *all-env + volumes: *data-prepper-volumes + ports: + - "${DATA_PREPPER_API_PORT:-4900}:4900" + - "${DATA_PREPPER_OTEL_TRACE_PORT:-21890}:21890" + networks: *cognet + extra_hosts: *common-hosts + logging: *nifi-logging-common + +#---------------------------------------------------------------------------# +# Docker named volumes # +#---------------------------------------------------------------------------# +volumes: + nifi-vol-conf: + # NiFi related + nifi-vol-logs: + driver: local + + nifi-vol-provenance: + driver: local + + nifi-vol-database: + driver: local + + nifi-vol-flowfiles: + driver: local + + nifi-vol-content: + driver: local + + nifi-vol-state: + driver: local + + nifi-vol-errors: + driver: local + +#---------------------------------------------------------------------------# +# Docker networks. # +#---------------------------------------------------------------------------# +networks: + cognet: + driver: bridge + name: cogstack-net diff --git a/apps/nifi/docker/export_env_vars.sh b/apps/nifi/docker/export_env_vars.sh new file mode 100755 index 00000000..f62884b1 --- /dev/null +++ b/apps/nifi/docker/export_env_vars.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash +# Source selected configuration without changing the caller's shell options. + +_cogstack_load_environment() { + local loader_path + if [[ -n "${ZSH_VERSION:-}" ]]; then + # The expression is evaluated only by zsh; Bash uses BASH_SOURCE below. + eval 'loader_path=${(%):-%x}' + else + loader_path="${BASH_SOURCE[0]}" + fi + local deploy_path + deploy_path="$(cd "$(dirname "$loader_path")" && pwd)" || return 1 + # shellcheck disable=SC1091 + source "$deploy_path/config_files.sh" || return 1 + cogstack_config_init "$(cd "$deploy_path/.." && pwd)" || return 1 + + local relative_files=( + security/env/certificates_nifi.env + security/env/certificates_general.env + security/env/certificates_elasticsearch.env + security/env/users_elasticsearch.env + security/env/users_database.env + security/env/users_nifi.env + security/env/users_nginx.env + deploy/general.env + deploy/nifi.env + deploy/elasticsearch.env + deploy/ollama.env + deploy/sglang.env + deploy/openwebui.env + deploy/database.env + deploy/network_settings.env + deploy/project.env + deploy/gitea.env + deploy/nginx.env + deploy/telemetry.env + ) + local relative_file selected_file variable_name file_name + local restore_allexport=1 + case "$-" in *a*) restore_allexport=0 ;; esac + set -a + for relative_file in "${relative_files[@]}"; do + selected_file="$(cogstack_env_file "$relative_file")" || { + if [[ "$restore_allexport" == 1 ]]; then set +a; fi + return 1 + } + file_name="${relative_file##*/}" + variable_name="COGSTACK_$(printf '%s' "${file_name%.env}" | tr '[:lower:]' '[:upper:]')_ENV_FILE" + export "$variable_name=$selected_file" + # shellcheck disable=SC1090 + source "$selected_file" || { + echo "ERROR: Failed to load configuration: $selected_file" >&2 + if [[ "$restore_allexport" == 1 ]]; then set +a; fi + return 1 + } + done + + # Service-owned configuration remains optional and uses its own directories. + local service_files=( + ../jupyter-hub/env/jupyter.env + services/cogstack-platform/apps/ocr-service/env/ocr_service.env + services/cogstack-nlp/medcat-service/env/app.env + services/cogstack-nlp/medcat-service/env/medcat.env + services/cogstack-nlp/medcat-trainer/envs/env-prod + ) + for relative_file in "${service_files[@]}"; do + selected_file="$COGSTACK_REPO_ROOT/$relative_file" + if [[ -f "$selected_file" ]]; then + # shellcheck disable=SC1090 + source "$selected_file" || { + echo "ERROR: Failed to load service configuration: $selected_file" >&2 + if [[ "$restore_allexport" == 1 ]]; then set +a; fi + return 1 + } + fi + done + # Local image builds match bind-mounted configuration/certificate ownership. + # Published images retain their Dockerfile's default non-root UID/GID. + export COGSTACK_LOCAL_UID="${COGSTACK_LOCAL_UID:-$(id -u)}" + export COGSTACK_LOCAL_GID="${COGSTACK_LOCAL_GID:-$(id -g)}" + if [[ "$COGSTACK_LOCAL_UID" == 0 ]]; then export COGSTACK_LOCAL_UID=1000; fi + if [[ "$COGSTACK_LOCAL_GID" == 0 ]]; then export COGSTACK_LOCAL_GID=1000; fi + export DOLLAR='$' + if [[ "$restore_allexport" == 1 ]]; then set +a; fi + echo "Configuration loaded from ${COGSTACK_CONFIG_DIR:-repository defaults}." +} + +if _cogstack_load_environment; then + unset -f _cogstack_load_environment +else + unset -f _cogstack_load_environment + # Also support executing the loader instead of sourcing it. + # shellcheck disable=SC2317 + return 1 2>/dev/null || exit 1 +fi diff --git a/apps/nifi/docker/healthcheck.sh b/apps/nifi/docker/healthcheck.sh new file mode 100755 index 00000000..ae65264e --- /dev/null +++ b/apps/nifi/docker/healthcheck.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +case "${1:-ready}" in + live) + exec "${NIFI_HOME:-/opt/nifi/nifi-current}/bin/nifi.sh" status >/dev/null + ;; + startup|ready) + host="${NIFI_HEALTHCHECK_HOST:-localhost}" + port="${NIFI_WEB_HTTPS_PORT:-${NIFI_INTERNAL_PORT:-8443}}" + exec curl --silent --show-error --fail --max-time "${NIFI_HEALTHCHECK_TIMEOUT:-5}" \ + --noproxy '*' --resolve "${host}:${port}:127.0.0.1" \ + --cacert "${NIFI_HEALTHCHECK_CA_FILE:-/security/certificates/root/root-ca.pem}" \ + --output /dev/null "https://${host}:${port}/nifi-api/authentication/configuration" + ;; + *) echo 'Usage: healthcheck.sh live|startup|ready' >&2; exit 2 ;; +esac diff --git a/apps/nifi/drivers/duckdb_jdbc-1.4.4.0.jar b/apps/nifi/drivers/duckdb_jdbc-1.4.4.0.jar new file mode 100644 index 00000000..6cf1d168 Binary files /dev/null and b/apps/nifi/drivers/duckdb_jdbc-1.4.4.0.jar differ diff --git a/apps/nifi/drivers/mssql-jdbc-13.2.0.jre11.jar b/apps/nifi/drivers/mssql-jdbc-13.2.0.jre11.jar new file mode 100644 index 00000000..684454a4 Binary files /dev/null and b/apps/nifi/drivers/mssql-jdbc-13.2.0.jre11.jar differ diff --git a/apps/nifi/drivers/mysql-connector-j-9.4.0.jar b/apps/nifi/drivers/mysql-connector-j-9.4.0.jar new file mode 100644 index 00000000..465d6575 Binary files /dev/null and b/apps/nifi/drivers/mysql-connector-j-9.4.0.jar differ diff --git a/apps/nifi/drivers/postgresql-42.7.7.jar b/apps/nifi/drivers/postgresql-42.7.7.jar new file mode 100644 index 00000000..886dce11 Binary files /dev/null and b/apps/nifi/drivers/postgresql-42.7.7.jar differ diff --git a/apps/nifi/pyproject.toml b/apps/nifi/pyproject.toml new file mode 100644 index 00000000..a1ccc7d1 --- /dev/null +++ b/apps/nifi/pyproject.toml @@ -0,0 +1,116 @@ +[tool.ruff] +line-length = 120 +exclude = ["user_scripts/legacy_scripts", "typings"] +target-version = "py311" +indent-width = 4 + +[tool.uv] +required-version = ">=0.12.1" + +[tool.ruff.lint] +# Enable flake8-bugbear (`B`) rules, in addition to the defaults. +select = [ + # pycodestyle + "E", + # Pyflakes + "F", + # pyupgrade + "UP", + # flake8-bugbear + "B", + # flake8-simplify + "SIM", + # isort + "I", +] + +fixable = ["ALL"] + +[tool.mypy] +plugins = ["pydantic.mypy"] +python_version = "3.11" +ignore_missing_imports = true +strict = false +files = "." +mypy_path = "$MYPY_CONFIG_FILE_DIR/typings" +warn_unused_configs = true + +[tool.setuptools] +# Preserve nifi.* imports while keeping application files at this project root. +package-dir = { "nifi" = "." } +include-package-data = false +packages = [ + "nifi", + "nifi.user_python_extensions", + "nifi.user_scripts", + "nifi.user_scripts.dto", + "nifi.user_scripts.legacy_scripts", + "nifi.user_scripts.processors", + "nifi.user_scripts.tests", + "nifi.user_scripts.tests.nifi", + "nifi.user_scripts.utils", + "nifi.user_scripts.utils.codecs", + "nifi.user_scripts.utils.data", + "nifi.user_scripts.utils.db", + "nifi.user_scripts.utils.health", + "nifi.user_scripts.utils.nifi", + "nifi.user_scripts.utils.serialization", +] + +[tool.pyright] +venvPath = "." +venv = ".venv" + +[project] +name = "cogstack_nifi" +version = "0.0.1" +requires-python = ">=3.11" +dependencies = [ + "avro==1.12.2", + "bokeh==3.9.2", + "dill>=0.4.0,<1.0.0", + "elasticsearch9==9.5.1", + "fhir.resources==8.3.0", + "geocoder==1.38.1", + "jsonpickle==4.1.4", + "mysql-connector-python==26.7.0", + "neo4j==6.4.1", + "nipyapi==1.7.0", + "nltk==3.10.4", + "numpy==2.4.6", + "opensearch-py==3.2.0", + "overrides==7.7.0", + "pandas==3.0.6", + "polars==1.44.2", + "psycopg[binary,c]==3.3.6", + "py4j==0.10.9.9", + "py7zr==1.1.3", + "pyarrow==25.0.1", + "pydantic==2.13.5", + "pydantic-settings==2.15.0", + "pydicom==3.0.2", + "pymssql==2.4.6", + "PyYAML==6.0.3", + "rancoord==0.0.6", + "requests==2.34.2", + "snowflake==1.13.2", + "snowflake-connector-python==4.7.5", + "wheel==0.48.0", + "xlsxwriter==3.2.9", + "xnat==0.8.1", +] + +[dependency-groups] +dev = [ + "mypy==2.3.1", + "mypy-extensions==1.1.0", + "ruff==0.17.3", + "timeout-decorator==0.5.0", + "types-aiofiles==25.1.0.20260518", + "types-PyYAML==6.0.12.20250516", + "types-setuptools==84.0.0.20260812", +] + +[build-system] +requires = ["setuptools>=84.2.1"] +build-backend = "setuptools.build_meta" diff --git a/apps/nifi/pyrightconfig.json b/apps/nifi/pyrightconfig.json new file mode 100644 index 00000000..445cc0e5 --- /dev/null +++ b/apps/nifi/pyrightconfig.json @@ -0,0 +1,12 @@ +{ + "venvPath": ".", + "venv": ".venv", + "extraPaths": [ + "..", + "user_python_extensions", + "./typings" + ], + "typeCheckingMode": "basic", + "reportMissingTypeStubs": "none", + "reportMissingImports": "warning" +} diff --git a/apps/nifi/typings/nifiapi/__init__.pyi b/apps/nifi/typings/nifiapi/__init__.pyi new file mode 100644 index 00000000..ec36dec9 --- /dev/null +++ b/apps/nifi/typings/nifiapi/__init__.pyi @@ -0,0 +1,23 @@ +__all__ = [ + "FlowFileTransform", + "FlowFileTransformResult", + "ProcessContext", + "PropertyDescriptor", + "StandardValidators", + "Relationship", +] + +import nifiapi.flowfiletransform # noqa: F401 +import nifiapi.properties # noqa: F401 +import nifiapi.relationship # noqa: F401 + +from .flowfiletransform import ( + FlowFileTransform, + FlowFileTransformResult, +) +from .properties import ( + ProcessContext, + PropertyDescriptor, + StandardValidators, +) +from .relationship import Relationship diff --git a/apps/nifi/typings/nifiapi/flowfiletransform.py b/apps/nifi/typings/nifiapi/flowfiletransform.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/nifi/typings/nifiapi/flowfiletransform.pyi b/apps/nifi/typings/nifiapi/flowfiletransform.pyi new file mode 100644 index 00000000..f9f369e7 --- /dev/null +++ b/apps/nifi/typings/nifiapi/flowfiletransform.pyi @@ -0,0 +1,19 @@ +from typing import Any, Protocol + +from py4j.java_gateway import JavaObject + +from .properties import ProcessContext + +# --------------------- +# FlowFileTransform + Result +# --------------------- +class FlowFileTransform(Protocol): + def transform(self, context: ProcessContext, flowFile: JavaObject) -> Any: ... + +class FlowFileTransformResult: + def __init__( + self, + relationship: str, + attributes: dict[str, str], + contents: str | bytes | bytearray | None = None, + ) -> None: ... diff --git a/apps/nifi/typings/nifiapi/properties.py b/apps/nifi/typings/nifiapi/properties.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/nifi/typings/nifiapi/properties.pyi b/apps/nifi/typings/nifiapi/properties.pyi new file mode 100644 index 00000000..526ebd93 --- /dev/null +++ b/apps/nifi/typings/nifiapi/properties.pyi @@ -0,0 +1,57 @@ +from enum import Enum +from typing import Any, Protocol + +class ExpressionLanguageScope(Enum): + NONE = 1 + ENVIRONMENT = 2 + FLOWFILE_ATTRIBUTES = 3 + + +class ProcessContext(Protocol): + def getProperties(self) -> dict[str, Any]: ... + + +class PropertyDescriptor: + def __init__(self, name, description, required=False, sensitive=False, + display_name=None, default_value=None, allowable_values=None, + dependencies=None, expression_language_scope=ExpressionLanguageScope.NONE, + dynamic=False, validators=None, + resource_definition=None, controller_service_definition=None): + if validators is None: + validators = [StandardValidators.ALWAYS_VALID] + + self.name = name + self.description = description + self.required = required + self.sensitive = sensitive + self.displayName = display_name + self.defaultValue = None if default_value is None else str(default_value) + self.allowableValues = allowable_values + self.dependencies = dependencies + self.expressionLanguageScope = expression_language_scope + self.dynamic = dynamic + self.validators = validators + self.resourceDefinition = resource_definition + self.controllerServiceDefinition = controller_service_definition + + +class StandardValidators: + ALWAYS_VALID: object + NON_EMPTY_VALIDATOR: object + INTEGER_VALIDATOR: object + POSITIVE_INTEGER_VALIDATOR: object + POSITIVE_LONG_VALIDATOR: object + NON_NEGATIVE_INTEGER_VALIDATOR: object + NUMBER_VALIDATOR: object + LONG_VALIDATOR: object + PORT_VALIDATOR: object + NON_EMPTY_EL_VALIDATOR: object + HOSTNAME_PORT_LIST_VALIDATOR: object + BOOLEAN_VALIDATOR: object + URL_VALIDATOR: object + URI_VALIDATOR: object + REGULAR_EXPRESSION_VALIDATOR: object + REGULAR_EXPRESSION_WITH_EL_VALIDATOR: object + TIME_PERIOD_VALIDATOR: object + DATA_SIZE_VALIDATOR: object + FILE_EXISTS_VALIDATOR: object diff --git a/apps/nifi/typings/nifiapi/relationship.py b/apps/nifi/typings/nifiapi/relationship.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/nifi/typings/nifiapi/relationship.pyi b/apps/nifi/typings/nifiapi/relationship.pyi new file mode 100644 index 00000000..90acc47e --- /dev/null +++ b/apps/nifi/typings/nifiapi/relationship.pyi @@ -0,0 +1,8 @@ + +class Relationship: + def __init__(self, name: str, description: str = "") -> None: ... + + name: str + description: str + + raise NotImplementedError \ No newline at end of file diff --git a/apps/nifi/typings/py4j/__init__.pyi b/apps/nifi/typings/py4j/__init__.pyi new file mode 100644 index 00000000..e69de29b diff --git a/apps/nifi/typings/py4j/java_gateway.pyi b/apps/nifi/typings/py4j/java_gateway.pyi new file mode 100644 index 00000000..f618f3df --- /dev/null +++ b/apps/nifi/typings/py4j/java_gateway.pyi @@ -0,0 +1,10 @@ +from typing import Any, Protocol + +class JavaObject(Protocol): + """Stub for Py4J JavaObject with the methods we use in NiFi""" + def getContentsAsBytes(self) -> bytes: ... + def getAttributes(self) -> dict[str, Any]: ... + +class JVMView(Protocol): + """Stub JVM view""" + pass diff --git a/apps/nifi/user_python_extensions/convert_avro_binary_field_to_base64.py b/apps/nifi/user_python_extensions/convert_avro_binary_field_to_base64.py new file mode 100644 index 00000000..6f836a3f --- /dev/null +++ b/apps/nifi/user_python_extensions/convert_avro_binary_field_to_base64.py @@ -0,0 +1,147 @@ +import base64 +import copy +import io +import json + +from avro.datafile import DataFileReader, DataFileWriter +from avro.io import DatumReader, DatumWriter +from avro.schema import RecordSchema, Schema, parse +from nifiapi.flowfiletransform import FlowFileTransformResult +from nifiapi.properties import ( + ProcessContext, + PropertyDescriptor, + StandardValidators, +) +from py4j.java_gateway import JavaObject, JVMView + +from nifi.user_scripts.utils.nifi.base_nifi_processor import BaseNiFiProcessor + + +class CogStackConvertAvroBinaryRecordFieldToBase64(BaseNiFiProcessor): + """NiFi Python processor to convert a binary field in Avro records to base64-encoded string. + + Reads each FlowFile as Avro, locates the configured binary_field_name, and rewrites the Avro schema, + so that field becomes a nullable string, preventing NiFi’s JSON + converters from turning raw bytes into integer arrays. + + Streams every record through a new Avro writer, base64-encoding the binary payload when operation_mode=base64 + (or leaving bytes untouched for raw), then reattaching the remaining fields + so downstream processors still see the original record structure. + + Emits the updated Avro binary along success with attributes capturing document ID field, + binary field, mode, and MIME type application/avro-binary; + + Exception routes to failure after logging a stack trace. + """ + + class Java: + implements = ['org.apache.nifi.python.processor.FlowFileTransform'] + + class ProcessorDetails: + version = '0.0.1' + + def __init__(self, jvm: JVMView): + super().__init__(jvm) + + self.operation_mode: str = "base64" + self.binary_field_name: str = "binarydoc" + self.document_id_field_name: str = "id" + + # this is directly mirrored to the UI + self._properties = [ + PropertyDescriptor(name="binary_field_name", + description="Avro field containing binary data", + default_value="binarydoc", + required=True, + validators=[StandardValidators.NON_EMPTY_VALIDATOR]), + PropertyDescriptor(name="operation_mode", + description="Decoding mode (e.g. base64 or raw)", + default_value="base64", + required=True, + allowable_values=["base64", "raw"]), + PropertyDescriptor(name="document_id_field_name", + description="Field name containing document ID", + default_value="id", + required=True, + validators=[StandardValidators.NON_EMPTY_VALIDATOR]), + ] + + self.descriptors: list[PropertyDescriptor] = self._properties + + def process(self, context: ProcessContext, flowFile: JavaObject) -> FlowFileTransformResult: + """ + Processes an Avro flow file by converting a specified binary field to a base64-encoded string. + + Args: + context (ProcessContext): The process context containing processor properties. + flowFile (JavaObject): The flow file to be transformed. + + Raises: + TypeError: If the Avro record is not a dictionary. + Exception: For any other errors during Avro processing. + + Returns: + FlowFileTransformResult: The result containing the transformed flow file, updated attributes, + and relationship. + """ + # read avro record + input_raw_bytes: bytes = flowFile.getContentsAsBytes() + input_byte_buffer: io.BytesIO = io.BytesIO(input_raw_bytes) + reader: DataFileReader = DataFileReader(input_byte_buffer, DatumReader()) + + schema: Schema | None = reader.datum_reader.writers_schema + + # change the datatype of the binary field from bytes to string + # (avoids headaches later on when converting avro to json) + # because if we dont change the schema the native NiFi converter will convert bytes to an array of integers. + output_schema = None + if schema is not None and isinstance(schema, RecordSchema): + schema_dict = copy.deepcopy(schema.to_json()) + for field in schema_dict["fields"]: # type: ignore + self.logger.info(str(field)) + if field["name"] == self.binary_field_name: + field["type"] = ["null", "string"] + break + output_schema = parse(json.dumps(schema_dict)) + + # Write them to a binary avro stream + output_byte_buffer = io.BytesIO() + writer = DataFileWriter(output_byte_buffer, DatumWriter(), output_schema) + + for record in reader: + if type(record) is dict: + record_document_binary_data = record.get(str(self.binary_field_name), None) + + if record_document_binary_data is not None: + if self.operation_mode == "base64": + record_document_binary_data = base64.b64encode(record_document_binary_data).decode() + else: + self.logger.info("No binary data found in record, using empty content") + else: + raise TypeError("Expected Avro record to be a dictionary, but got: " + str(type(record))) + + _tmp_record = {} + _tmp_record[str(self.binary_field_name)] = record_document_binary_data + + for k, v in record.items(): + if k != str(self.binary_field_name): + _tmp_record[k] = v + + writer.append(_tmp_record) + + input_byte_buffer.close() + reader.close() + writer.flush() + output_byte_buffer.seek(0) + + attributes: dict = {k: str(v) for k, v in flowFile.getAttributes().items()} + attributes["document_id_field_name"] = str(self.document_id_field_name) + attributes["binary_field"] = str(self.binary_field_name) + attributes["operation_mode"] = str(self.operation_mode) + attributes["mime.type"] = "application/avro-binary" + + return FlowFileTransformResult( + relationship=self.REL_SUCCESS.name, + attributes=attributes, + contents=output_byte_buffer.getvalue(), + ) diff --git a/apps/nifi/user_python_extensions/convert_json_record_schema.py b/apps/nifi/user_python_extensions/convert_json_record_schema.py new file mode 100644 index 00000000..baf2a4b1 --- /dev/null +++ b/apps/nifi/user_python_extensions/convert_json_record_schema.py @@ -0,0 +1,348 @@ +import json +from collections import defaultdict +from typing import Any + +from nifiapi.flowfiletransform import FlowFileTransformResult +from nifiapi.properties import ProcessContext, PropertyDescriptor, StandardValidators +from nifiapi.relationship import Relationship +from py4j.java_gateway import JavaObject, JVMView + +from nifi.user_scripts.utils.nifi.base_nifi_processor import BaseNiFiProcessor + + +class CogStackConvertJsonRecordSchema(BaseNiFiProcessor): + """ + Remaps each incoming JSON record (single dict or list of dicts) using a lookup loaded from + json_mapper_schema_path. + + Supports: + - simple renames: {"new_field": "old_field"} + - constants/null placeholders: {"new_field": null} + - composite concatenation: {"new_field": ["field1", "field2", ...]} + - dotted destination keys for nesting: {"a.b.c": "old_field"} => {"a": {"b": {"c": value}}} + - dotted destination keys applied to nested dict/list containers: + {"document_Fields.valueText": "Answer"} will be applied to each object in record["document_Fields"] + if document_Fields is a list[dict]. + + For every mapping entry it can rename fields, populate constant null placeholders, + or stitch together composite fields by concatenating multiple source values with newline separators. + + Optionally preserves any source fields not covered by the mapping via the + preserve_non_mapped_fields boolean property, which defaults to true to avoid accidental data loss. + + Emits the transformed payload as JSON (mime.type=application/json) and tags the FlowFile with the schema path used, + routing successes to success and any exceptions to failure + """ + + class Java: + implements = ['org.apache.nifi.python.processor.FlowFileTransform'] + + class ProcessorDetails: + version = '0.0.1' + + def __init__(self, jvm: JVMView): + super().__init__(jvm) + + self.json_mapper_schema_path: str = "/opt/nifi/user_schemas/json/cogstack_common_schema_mapping.json" + self.preserve_non_mapped_fields: bool = True + self.composite_first_non_empty_field: list[str] = [] + + # this is directly mirrored to the UI + self._properties = [ + PropertyDescriptor(name="json_mapper_schema_path", + description="The path to the json schema mapping file, " \ + "the schema directory is mounted as a volume in" \ + " the nifi container in the /opt/nifi/user_schemas/ folder", + default_value="/opt/nifi/user_schemas/json/cogstack_common_schema_mapping.json", + required=True, + validators=[StandardValidators.NON_EMPTY_VALIDATOR]), + PropertyDescriptor(name="preserve_non_mapped_fields", + description="Whether to preserve fields that are not mapped in the schema", + default_value="true", + required=True, + allowable_values=["true", "false"], + validators=[StandardValidators.BOOLEAN_VALIDATOR]), + PropertyDescriptor(name="composite_first_non_empty_field", + description="List of fields that are composite fields taking the first non-empty value e.g." + " 'new_field_mapping': [field1, field2] if field1 is empty then field2 is taken", + default_value="", + required=False) + ] + + self._relationships = [ + Relationship( + name="success", + description="All FlowFiles processed successfully." + ), + Relationship( + name="failure", + description="FlowFiles that failed processing." + ) + ] + + self.descriptors: list[PropertyDescriptor] = self._properties + self.relationships: list[Relationship] = self._relationships + + # ----------------------------- + # Helpers for nested destinations + # ----------------------------- + @staticmethod + def _set_nested(out: dict, dotted_key: str, value: Any) -> None: + parts = dotted_key.split(".") + cur = out + for p in parts[:-1]: + nxt = cur.get(p) + if nxt is None: + nxt = {} + cur[p] = nxt + elif not isinstance(nxt, dict): + raise ValueError(f"Cannot nest into '{dotted_key}': '{p}' is not an object") + cur = nxt + cur[parts[-1]] = value + + def _set_field(self, out: dict, key: str, value: Any) -> None: + if "." in key: + self._set_nested(out, key, value) + else: + out[key] = value + + @staticmethod + def _split_schema(schema: dict) -> tuple[dict, dict[str, dict]]: + """ + Splits schema into: + flat_schema: keys without a dot + nested_schema: {container: {subpath: old_field}} + Example: + "document_Fields.valueText": "Answer" + becomes: + nested_schema["document_Fields"]["valueText"] = "Answer" + """ + flat: dict = {} + nested: dict[str, dict] = defaultdict(dict) + for new_field, old_field in schema.items(): + if "." in new_field: + container, subpath = new_field.split(".", 1) + nested[container][subpath] = old_field + else: + flat[new_field] = old_field + return flat, nested + + @staticmethod + def _parse_list_property(raw: str) -> list[str]: + raw = (raw or "").strip() + if not raw: + return [] + # JSON list? + if raw.startswith("["): + try: + val = json.loads(raw) + if isinstance(val, list): + return [str(x).strip() for x in val if str(x).strip()] + except Exception: + pass + # comma-separated fallback + return [x.strip() for x in raw.split(",") if x.strip()] + + def _render_list_items( + self, + items: list[dict], + keys: list[str] = ["label", "valueText", "valueNum", "valueDate", "comment"], + ) -> str | None: + """ + Render a list of dict items (typically nested records such as `document_Fields`) + into a readable multi-line text block for use inside composite fields like `document_Content`. + + Each item is rendered by extracting the first non-empty values for the provided `keys` + (in the given order). The formatting is: + +