Skip to content

build!: adopt pyproject, harden image and Compose - #223

Merged
uniqueg merged 4 commits into
devfrom
build/pyproject-image
Oct 22, 2026
Merged

uniqueg merged 4 commits into
devfrom
build/pyproject-image

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #204. This follows the cloud-registry template (elixir-cloud-aai/cloud-registry#97, #120 and #142).

  • Packaging:
    • pyproject.toml with setuptools-scm. The version comes from vX.Y.Z tags, with fallback 0.0.0.dev0.
    • Bounded dependencies, a dev extra and package data.
    • Removed setup.py, setup.cfg, both requirements files, pro_tes/version.py and the stray file =0.12.1.
    • flake8's settings move to .flake8. pylintrc stays until style: adopt the shared ruff, mypy and pre-commit #206 replaces flake8 and pylint with ruff.
  • Image:
    • Dependency wheels are built in a gcc stage, because ip2geotools needs typed-ast.
    • Non-editable install as root, then USER 1000. Base image pinned by digest.
    • HEALTHCHECK on the Swagger UI. SETUPTOOLS_SCM_PRETEND_VERSION build argument. Labels name ELIXIR On-Cloud.
    • CMD gunicorn --config python:pro_tes.gunicorn_config 'pro_tes.app:init_app()'. The Gunicorn settings follow cloud-registry and drop forwarded_allow_ips = "*"; FORWARDED_ALLOW_IPS is documented instead.
    • gunicorn.py and wsgi.py are removed. The worker runs celery --app pro_tes.celery_worker worker.
  • Compose:
    • Ports bound to 127.0.0.1 only (proTES, plus Flower when enabled). MongoDB and RabbitMQ are no longer published.
    • Health checks, including one for the worker, so docker compose up --wait works.
    • RabbitMQ credentials go into CELERY_BROKER_URL.
    • Flower is in the opt-in profile monitoring and refuses to start without FLOWER_BASIC_AUTH.
    • Named volumes, no links/version, pinned images (rabbitmq:4.1, mher/flower:2.0.1).
  • Helm chart: commands updated for the new image. Chart version 3.0.0 (breaking, see below). The rewrite itself is build(chart)!: use the FOCA library chart #216.
  • CI:
    • Installs .[dev], builds the distributions and checks the wheel contents.
    • Starts Compose with --wait, checks the version the app reports, and shows logs on failure.
    • The publish job now uses docker/build-push-action, passing the version from setuptools-scm as a build argument (same tags as before: latest and the date).
  • Dependabot: pip, GitHub Actions and Docker, as in cloud-registry. FOCA minors are bumped by hand.
  • Tests: Gunicorn settings and image command, including the app factory and the health check port and path, plus package version and setuptools-scm.

Breaking change (in the commit footer):

  • The image no longer has /app/pro_tes, gunicorn.py or wsgi.py.
  • GUNICORN_PROCESSES and GUNICORN_THREADS are replaced by GUNICORN_CMD_ARGS.
  • Chart 3.0.0 needs images built from this change, and older charts need older images. With latest and imagePullPolicy: Always, chart and image must be upgraded together.

Local Compose data: MongoDB data in the former bind mount (PROTES_DATA_DIR, default ../data/pro_tes) is not migrated to the named volume.

Not done here:

Full review lane.

How it was verified

  • Python 3.10 and 3.12, with pytest tests --ignore=tests/unitTest --ignore=tests/test_integration: 41 passed on each.
  • flake8 pro_tes: clean. pylint pro_tes: 10.00/10. mypy pro_tes: no issues.
  • python -m build: wheel contains only pro_tes, its YAML data and the license.
  • docker compose config validated, with and without --profile monitoring. The stack itself is started by CI (no local docker run).
  • Review: two rounds of adversarial and quality reviews. All high and medium findings were fixed (breaking-change footer and chart bump, Compose data note, broker credential guidance, health check path test, narrower build mount).

CI: all checks pass (linting and unit tests on 3.10 and 3.12; Compose stack healthy with --wait, app version check and integration tests; CodeQL).

Declined review findings

  • Pin all CI actions by SHA, and add concurrency and timeouts (quality, medium): deferred to style: adopt the shared ruff, mypy and pre-commit #206, which replaces the lint jobs with one pre-commit job.

  • Default chart image tags to the chart's appVersion instead of latest (adversarial, low): belongs to the chart rewrite in build(chart)!: use the FOCA library chart #216.

  • Version goes back from 0.2.0 (old version.py) to 0.0.0.devN, because the repository has no vX.Y.Z tags (adversarial, medium): tags are part of the release process (ci: release from signed version tags #44). Tagging v0.2.0 on 5f80afe (where 0.2.0 was set) would restore it. This is noted for the maintainers, not a blocker.

  • Sourcery: keep MongoDB on the PROTES_DATA_DIR bind mount or migrate it. Declined: the Compose file is for local development only, the change is documented, and a bind mount can be added in an override.

  • Sourcery: test_load_settings_restores does not change the working directory. Declined: Gunicorn's load_config() calls chdir(), so the test covers the restore.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 3 commits October 22, 2026 20:34
Package with pyproject.toml as cloud-registry does: version from Git
tags via setuptools-scm (fallback 0.0.0.dev0), bounded dependencies, a
dev extra, package data. Remove setup.py, setup.cfg (flake8 settings
move to .flake8 until ruff replaces flake8), the requirements files,
pro_tes/version.py and the stray file =0.12.1.

Image: dependencies from pyproject.toml, non-editable install as root,
then UID 1000; health check on the Swagger UI; version as build
argument; Gunicorn settings in pro_tes/gunicorn_config.py with the app
factory as command, replacing gunicorn.py (which trusted X-Forwarded-*
headers from any address) and wsgi.py. The Celery worker runs as
pro_tes.celery_worker, also in the Helm chart.

Compose: ports on 127.0.0.1 only, health checks for docker compose up
--wait, RabbitMQ credentials in CELERY_BROKER_URL, Flower in an opt-in
profile with required basic auth, named volumes.

CI installs the dev extra, builds and checks the wheel, waits for the
healthy Compose stack and checks the app version; the publish job
passes the version to the image build. Add Dependabot config.

Closes #204

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mount only the dependency wheels and requirements of the build stage,
test the health check path against the app, explain the mypy pin, and
document the broker credential rules and that data of the former bind
mounts is not migrated. Bump the chart to 3.0.0, as its commands need
the new image.

BREAKING CHANGE: The image installs proTES into site-packages: the app
runs with `gunicorn --config python:pro_tes.gunicorn_config
'pro_tes.app:init_app()'` and the worker with `celery --app
pro_tes.celery_worker worker`; `/app/pro_tes`, `gunicorn.py` and
`wsgi.py` are gone, and `GUNICORN_PROCESSES` and `GUNICORN_THREADS` are
replaced by `GUNICORN_CMD_ARGS`. Chart 3.0.0 needs images built from
this version, and earlier charts need earlier images.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
appVersion is the version of proTES, not of the chart; it is set with
the release process (#44).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This breaking change adopts pyproject.toml/setuptools-scm packaging, produces a hardened non-root image with new Gunicorn/Celery entry points, and rewrites Compose and Helm execution around health checks, safer networking, pinned dependencies, and coordinated versioned builds.

Sequence diagram for Compose health-gated startup

sequenceDiagram
    participant Compose
    participant MongoDB
    participant RabbitMQ
    participant ProTES
    participant Worker

    Compose->>MongoDB: healthcheck ping
    MongoDB-->>Compose: healthy
    Compose->>RabbitMQ: rabbitmq-diagnostics ping
    RabbitMQ-->>Compose: healthy
    Compose->>ProTES: start after dependencies are healthy
    Compose->>Worker: start after dependencies are healthy
    Compose->>ProTES: HTTP healthcheck /ga4gh/tes/v1/ui/
    ProTES-->>Compose: healthy
    Compose->>Worker: celery inspect ping
    Worker-->>Compose: healthy
    Compose-->>Compose: docker compose up --wait completes
Loading

File-Level Changes

Change Details Files
Migrates packaging and version management to pyproject.toml with setuptools-scm.
  • Derives versions from vX.Y.Z tags with a development fallback and Docker build override.
  • Defines bounded runtime dependencies, development extras, package discovery, and YAML/license data.
  • Removes legacy setup and requirements files plus the checked-in version module and stray artifact.
  • Moves Flake8 configuration to its dedicated file and updates CI to build and validate wheel contents.
pyproject.toml
.flake8
setup.py
setup.cfg
requirements.txt
requirements_dev.txt
pro_tes/version.py
=.0.12.1
.github/workflows/checks.yaml
Hardens the container image and replaces legacy application entry points with packaged Gunicorn and Celery commands.
  • Builds dependency wheels in a compiler stage, installs the application non-editably as root, and runs it as UID 1000.
  • Pins the base image by digest, adds metadata and a Swagger health check, and passes setuptools-scm version data through a build argument.
  • Uses the app factory with packaged Gunicorn configuration and documents GUNICORN_CMD_ARGS/FORWARDED_ALLOW_IPS behavior.
  • Removes /app/pro_tes-era gunicorn.py and wsgi.py entry points and updates the worker module path.
  • Adds tests covering Gunicorn settings, command behavior, app loading, health-check endpoint, and temporary-directory handling.
Dockerfile
pro_tes/gunicorn_config.py
pro_tes/gunicorn.py
pro_tes/wsgi.py
tests/gunicorn_settings.py
tests/test_gunicorn_config.py
Reworks local Compose orchestration for safer exposure, reproducible dependencies, and health-aware startup.
  • Binds published services to loopback, removes links and deprecated Compose version metadata, and stops publishing MongoDB/RabbitMQ.
  • Adds named MongoDB/RabbitMQ volumes, pinned RabbitMQ and Flower images, service health checks, and dependency ordering for docker compose up --wait.
  • Constructs CELERY_BROKER_URL from RabbitMQ credentials and gates Flower behind a monitoring profile with required authentication.
  • Adds a dedicated Celery worker health check and supports local image version build arguments.
docker-compose.yaml
Updates Kubernetes deployment commands and marks the chart as a breaking release.
  • Removes the old working directory and invokes the packaged Gunicorn app factory and Celery module.
  • Bumps the chart version to 3.0.0 while retaining the current appVersion.
deployment/Chart.yaml
deployment/templates/protes/protes-deployment.yaml
deployment/templates/protes/celery-deployment.yaml
Modernizes CI publishing and dependency automation around the new build model.
  • Installs the dev extra, builds distributions, validates wheel contents, and tests Compose health and reported package version.
  • Derives the release version with setuptools-scm from full Git history and passes it to docker/build-push-action.
  • Adds grouped Dependabot updates for Python, GitHub Actions, and Docker dependencies, with coordinated FOCA exclusions.
.github/workflows/checks.yaml
.github/dependabot.yml

Assessment against linked issues

Issue Objective Addressed Explanation
#204 Modernize packaging with pyproject.toml, Git-tag-derived versions, bounded dependencies, the requested metadata and extras, and remove the legacy packaging and version files. ❌ The PR replaces the legacy packaging files, uses setuptools-scm, and configures package data, but it omits the requested docs extra.
#204 Harden the Docker image and Compose setup, including non-root runtime, health checks, safer forwarded-header trust, working installed-package commands, loopback-only published ports, secured opt-in Flower, and a local-development config overlay. ❌ The PR implements the image hardening, Compose health checks and port restrictions, the worker command, and opt-in authenticated Flower. It explicitly does not add the requested config.dev.yaml overlay or FOCA_CONFIG_OVERLAY configuration.
#204 Update CI and dependency automation to install the project extras, build and verify distributions, and pass the derived version into image builds. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@uniqueg
uniqueg marked this pull request as ready for review October 22, 2026 19:06

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="docker-compose.yaml" line_range="86" />
<code_context>
+        image: mongo:7.0
+        restart: unless-stopped
+        volumes:
+            - mongodb-data:/data/db
+        healthcheck:
+            test: ["CMD", "mongosh", "--quiet", "--eval", "db.adminCommand('ping').ok"]
</code_context>
<issue_to_address>
**Existing MongoDB data disappears**

When an existing Compose installation upgrades with task records in its former `PROTES_DATA_DIR` database, compose mounts a new named volume, so `TaskRuns.list_tasks` and `TaskRuns.get_task` cannot find those records, and `PROTES_DATA_DIR` no longer controls MongoDB storage; users see an empty task list.

Keep MongoDB on the configured `PROTES_DATA_DIR` bind mount or migrate the existing database into the named volume.

Also at `docker-compose.yaml:121`.
</issue_to_address>

### Comment 2
<location path="pro_tes/gunicorn_config.py" line_range="27" />
<code_context>
+!LICENSE
+!pyproject.toml
+!README.md
+
+# Exclude caches and local files within the included paths
+**/__pycache__
</code_context>
<issue_to_address>
**Port configuration guidance is stale**

When a user changes the app’s `server` settings expecting the container’s production server to use them, gunicorn binds to the configured fixed address rather than `config.yaml`’s `server.host` and `server.port`, so users following the README’s instruction to change those settings do not change the image’s listening address.

Update the README to say that the image’s Gunicorn bind is controlled with `GUNICORN_CMD_ARGS` and that the Compose port mapping must also be changed as needed.
</issue_to_address>

### Comment 3
<location path="tests/test_gunicorn_config.py" line_range="119" />
<code_context>
+    monkeypatch.chdir(tmp_path)
+    monkeypatch.setattr(sys, "argv", ["pytest"])
+    monkeypatch.setenv("GUNICORN_CMD_ARGS", "--workers 3")
+    assert load_settings("--chdir /").cfg.workers == 1
+    assert load_settings().cfg.workers == 1
+    assert (os.getcwd(), sys.argv) == (str(tmp_path), ["pytest"])
</code_context>
<issue_to_address>
**Working-directory restoration goes untested**

When `load_settings` constructs a `WSGIApplication` without running Gunicorn, when Gunicorn only parses `--chdir /` without running its chdir path, `test_load_settings_restores` line 119 never changes the working directory, so line 121 still passes if `load_settings`’s `os.chdir(cwd)` cleanup is removed.

Make the test cause a controlled working-directory change during `load_settings`, then assert that the helper restores the original directory.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and docker Compose switches MongoDB from the existing host directory to a new named volume, so prior data is left behind and the app starts with a fresh database; records written to the new volume remain there after a revert and require manual recovery or migration to access.

Blocking findings: docker-compose.yaml:86, pro_tes/gunicorn_config.py:27, tests/test_gunicorn_config.py:119


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread docker-compose.yaml Resolved
Comment thread pro_tes/gunicorn_config.py Resolved
Comment thread tests/test_gunicorn_config.py Resolved
The `server.host` and `server.port` settings apply to Flask's
development server only; the image's Gunicorn binds to the address of
`pro_tes/gunicorn_config.py`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 3c94cdb into dev Oct 22, 2026
10 checks passed
@uniqueg
uniqueg deleted the build/pyproject-image branch October 22, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: adopt pyproject, harden image and Compose

1 participant