Development¶
Contributions are welcome! See the organisation's contributing guide, and mind our code of conduct.
Tests¶
Dependencies are managed with uv: pyproject.toml
lists them (the runtime dependencies, and the dependency groups dev for
tests, linters and type checks, and docs for the documentation), and
uv.lock pins them; the image installs the locked runtime dependencies. After
changing dependencies, run uv lock (CI checks that the lock matches). The
app runs from its source directory, not as an installed package.
make test installs the locked dependencies into .venv (uv sync, with
Python 3.13, the version of the base image) and runs the tests with
coverage (written to coverage.xml; 100% coverage is required). Without
make:
The tests need no network access and no database. Unit tests mock the
database (mongomock) and clone
a local repository instead of one on GitHub (Git rewrites the URL, see
tests/conftest.py). The integration tests in tests/integration/ run
the app as deployed, with response validation, and test registering,
publishing and notifying through its API, with a local subscriber. They
use mongomock too, unless MONGODB_TEST_URI is set: then they use the
MongoDB at that URI, which must not have a database pubgradeStore (the
tests drop it before each test). CI runs all tests with mongomock, and the
integration tests also against MongoDB 7.0; to do the latter locally:
docker run -d --rm --name pubgrade-test-mongo -p 127.0.0.1:27017:27017 mongo:7.0
MONGODB_TEST_URI=mongodb://localhost:27017 uv run pytest tests/integration
docker stop pubgrade-test-mongo
The app is built on FOCA 0.23: its
configuration is pubgrade/config.yaml, and pubgrade/app.py creates the app
(create_app()). The image serves it with Gunicorn, with FOCA's settings
and more threads and shutdown time (pubgrade/gunicorn_config.py);
python -m pubgrade.app runs Flask's development server instead. FOCA is
bumped by hand: the tag and digest of the base image in the Dockerfile
and foca in pyproject.toml and uv.lock together, following FOCA's
migration guides; tests/test_image.py fails if they don't match.
tests/start.sh <image> starts an image of Pubgrade with MongoDB in Docker,
on port 8080; tests/smoke.sh <base URL> checks the API of a running
Pubgrade with an empty database, and tests/chart.sh the rendered chart.
The action that notifies Pubgrade from CI (actions/notify, see
Notify Pubgrade from CI) is a composite
action around actions/notify/notify.sh. tests/test_notify_action.py
runs the script against a stub of Pubgrade (it needs bash, curl and
jq; NOTIFY_RETRY_DELAY=0 skips the waits between attempts), and the CI
job "Notify action" runs the action itself against
Pubgrade from the branch's image. The action is versioned with Pubgrade:
callers pin the commit of a release.
tests/e2e/upgrade.sh tests the whole path, and needs Docker, Helm and jq: it
starts a throwaway k3s cluster, installs Pubgrade from its chart, sets up two
namespaces with a Deployment and a sidecar each, publishes one image and checks
that both roll out. It also covers an unreachable subscriber and a tag that
doesn't exist, which takes a few minutes, as sidecars retry first. Sidecars are
built from the branch dev of
Pubgrade-Sidecar; set
SIDECAR_IMAGE to use a local image instead.
tests/e2e/check-local.sh runs the operators' check tests/e2e/check.sh
(see Deployment) against such a
cluster from outside, with its kubeconfig and Pubgrade's URL, as against a
deployment, in a few minutes. It needs Docker, Helm, kubectl, curl and jq, and
takes SIDECAR_IMAGE as well. The check's defaults (test image and tags,
sidecar manifest) are its own, as operators run it without this repository's
other scripts: keep them in line with upgrade.sh.
Lint¶
Code style, type hints and the absence of secrets are checked with
pre-commit (.pre-commit-config.yaml):
- Ruff lints and formats the Python code
(Black style; rules in
[tool.ruff]ofpyproject.toml), including Google-style docstrings for all modules, classes and functions. - mypy checks the type hints, which must be
complete (
[tool.mypy]). - gitleaks looks for secrets in the staged changes; CI also scans all files.
- actionlint checks the GitHub workflows, and further hooks the YAML syntax, whitespace and file endings.
make lint runs all hooks on all files, including the scan of all files
for secrets, as CI does. To run them on each commit, install them once:
uv sync --all-groups # mypy also checks the hook of the docs build
uv run pre-commit install
uv run pre-commit run --all-files # without make
The Sidecar's submodule in external/ is left out. Formatting changes that
touch many lines go in a commit of their own, listed in
.git-blame-ignore-revs, so that git blame skips them; for GitHub's blame
view this works as is, locally after
git config blame.ignoreRevsFile .git-blame-ignore-revs.
CI¶
CI
runs on pull requests and pushes to dev: the pull request title (Conventional
Commits, at most 50 characters, as it becomes the commit message of the squash
merge), lint (the pre-commit hooks, see Lint, and the citation
metadata in CITATION.cff), the tests (with mongomock, with coverage to
Codecov; the integration tests also against MongoDB 7.0), the chart, the smoke
test, the notify action, the upgrade test, the deployment check, the
documentation, and a scan of the images. The scan fails on critical and high
vulnerabilities that have a fix in the app's image; the updater's image,
which isn't built on FOCA, is only reported for now. The job CI passed sums
up all other jobs and is the only required check.
Pushes to dev publish elixircloud/pubgrade and
elixircloud/pubgrade-updater, signed with Sigstore and tagged dev and
sha-<commit>; releases tag X.Y.Z and latest (see
Versioning and releases).
Publishing runs in the environment dev-images (branch dev only), with the
Docker Hub secrets DOCKERHUB_LOGIN and DOCKERHUB_TOKEN; the variable
DOCKERHUB_ORG sets the Docker Hub organization (by default elixircloud),
and the secret CODECOV_TOKEN is for the coverage report. Verify an image's
signature with cosign:
cosign verify elixircloud/pubgrade:dev \
--certificate-identity-regexp '^https://github\.com/elixir-cloud-aai/Pubgrade/\.github/workflows/ci\.yml@refs/heads/dev$' \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
Documentation¶
The documentation is built with MkDocs and
Material for MkDocs from
docs/ and mkdocs.yml, and published on Read the
Docs (.readthedocs.yaml). The README's
synopsis and quick start are included in the home page, between
--8<-- [start:<name>] and --8<-- [end:<name>] markers in README.md.
The section Pubgrade-Sidecar is the documentation of
Pubgrade-Sidecar, which
keeps it in its own repository (docs/, built strictly in its own CI). It is
included from the Git submodule external/pubgrade-sidecar, pinned to a commit
of the Sidecar's branch dev, by the hook docs/hooks.py: it adds the
Sidecar's pages under sidecar/, in the order of the Sidecar's mkdocs.yml.
Dependabot proposes updates of the submodule monthly; to update it by hand:
To build the documentation as CI and Read the Docs do, with the submodule checked out:
git submodule update --init
uv run --only-group docs mkdocs build --strict # or `mkdocs serve` to preview
The build fails on warnings, e.g. of broken links.
Versioning and releases¶
The project follows semantic versioning. It is in
beta, so the API may change without notice. The app, its two images and its
chart are released together, with one version: the tag vX.Y.Z (or
vX.Y.ZaN, vX.Y.ZbN and vX.Y.ZrcN for pre-releases), version in
[project] of pyproject.toml, the chart's appVersion and version
(the SemVer form, e.g., 1.2.3-rc1 for 1.2.3rc1), and the version in
CITATION.cff.
Until 1.0.0, all releases are GitHub pre-releases.
The first release, 0.2.0, took the chart's earlier version (0.2.0, from
before the release workflow) for the app, which was 0.1.0 before.
- Release-prep pull request to
dev: set the version inpyproject.toml(then runuv lock),helm/Chart.yaml(versionandappVersion) andCITATION.cff(python scripts/citation.py set <version>, which also sets the release date), and add the curated release notesdocs/releases/<version>.md(see below), also to thenavofmkdocs.yml, newest first, in the section "Releases" after "Development" (before the section thatdocs/hooks.pyappends; the first notes add it):
dev, check the notes, as the
release workflow does after the tag (a failure there needs a new version):
python scripts/release_notes.py require <version>,
! grep -n TODO docs/releases/<version>.md and
python scripts/release_notes.py check docs/releases/<version>.md. Then
bring that commit to main.
3. Tag it on main with a signed, annotated tag and push the tag:
git tag -s v<version> -m v<version>, then
git push origin v<version>.
The release workflow
checks the tag (a release version, annotated, with a signature that GitHub
verified, on main), that the versions above match it
(scripts/check_versions.py and scripts/citation.py check) and that CI
passed for a push of the commit. It packages the chart, with the images of
the release as defaults (elixircloud/pubgrade:X.Y.Z and
elixircloud/pubgrade-updater:X.Y.Z), pushes both images by digest, scans
them, then attests and signs the images and the chart, tags the images
X.Y.Z (and latest if it is the highest stable release;
scripts/release_version.py) and creates the GitHub release, with the chart
and its Sigstore bundle attached; then it notifies Pubgrade, once the
repository is registered there (see below). Pushing the images, publishing
the release and notifying Pubgrade each need approval in the environment
release, which holds the Docker Hub secrets DOCKERHUB_LOGIN and
DOCKERHUB_TOKEN (and PUBGRADE_TOKEN). Verify a released
image's signature with:
cosign verify elixircloud/pubgrade:<version> \
--certificate-identity-regexp '^https://github\.com/elixir-cloud-aai/Pubgrade/\.github/workflows/release\.yml@refs/tags/v' \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
After publishing the release, the job Notify Pubgrade registers the app's
image (elixircloud/pubgrade:X.Y.Z, with the organization in
DOCKERHUB_ORG if set), with the release tag, at a Pubgrade instance in
publish mode (builds disabled, the default;
#33) with
POST /repositories/{id}/builds. Pubgrade then notifies the deployments
that subscribed to upgrades, the instance's own deployment among them if it
subscribed. The build has a tag and no build type, so it reaches the
subscriptions of type tag whose value is the release tag (vX.Y.Z)
or *, and whose build_types are missing or empty; * also matches
pre-releases (vX.Y.ZrcN and the like), and subscriptions of type
branch or commit never match. Whether each deployment accepted the
notification is in the build's notifications (see
Notifications); the job doesn't fail if one
didn't. It uses
this repository's action actions/notify (see
Notify Pubgrade from CI), pinned to the
commit of
0.3.0,
not the action of the tagged commit. The updater's image isn't registered:
Pubgrade runs it for builds, not in a Deployment that a sidecar upgrades.
The job runs after the GitHub release, because the same job (publish)
tags the images and creates the release.
| Setting | Kind | Where | Meaning |
|---|---|---|---|
PUBGRADE_URL |
Variable | Organization | Base URL of the Pubgrade API, with https://. |
PUBGRADE_REPOSITORY_ID |
Variable | Repository | The repository's id from registering it at Pubgrade. Switches the notification on. |
PUBGRADE_TOKEN |
Secret | The release environment |
The repository's access_token from registering it at Pubgrade. |
- Switching it on:
PUBGRADE_URLis an organization variable, so every repository it is shared with sees it. The job is skipped until the repository variablePUBGRADE_REPOSITORY_IDis set too, i.e. until the repository is registered at Pubgrade (and in forks, which have neither), so releases don't wait for its approval. SetPUBGRADE_REPOSITORY_IDfor the repository, not in thereleaseenvironment: a job's condition is evaluated before the job enters its environment, so a variable there doesn't switch the job on (and would override the repository's identifier within the job: remove it there). Up to 0.3.1,PUBGRADE_URLalone switched the job on: an identifier set only in thereleaseenvironment now leaves the job skipped, without an error; move it to the repository. Once it is set, the job waits for an approval in thereleaseenvironment, like pushing and publishing. - Failures: the job fails if the token is missing, or the identifier
or the token is invalid: both may only hold letters, digits,
.,~and-(as Pubgrade issues them). The action masks the token and retries a request only if it never reached Pubgrade, so that one run registers the build at most once. If only this job fails or is rejected, the release is published all the same: fix the settings and re-run this job alone (notpublish, see below), or leave it; don't release a new version for it. - Re-runs: re-running the job registers the build again and notifies
the subscribed deployments again, without a new release. Unless it failed
on an invalid setting or with "Could not reach Pubgrade (curl exit status
6)" or "(… 7)" (no connection), Pubgrade may have registered the build all
the same: check the repository's builds (
GET /repositories/{id}/builds) before re-running it. Re-running the job of an older release sends its older tag again, also after a newer release: sidecars withrefuseDowngradesignore it, other subscribers may roll back.
Release notes follow the format agreed for all repositories of the organization:
- An intro paragraph saying what the release brings, with a link to the upgrade or migration guide if there is one.
- Grouped sections, empty ones left out, in this order:
## Breaking changes,## Features,## Security,## Fixes,## Documentation,## Maintenance. Each bullet ends with its issue and pull request numbers, e.g.,(#12, #34). ## Commits: GitHub's generated notes, verbatim (including "New Contributors"), without their## What's Changedheader.- Last, GitHub's generated
**Full Changelog**: ...line.
The curated notes in docs/releases/<version>.md hold parts 1 and 2,
without a title (the release's title is its tag). The release body never
changes, so they link with full URLs to the release's docs
(https://pubgrade.readthedocs.io/en/v<version>/...) and files
(blob/v<version>/), never to versions that move (latest, dev) and
never with relative links, which don't work in the release body. The notes must be
a regular file (not a symbolic link). The release
workflow fails if the notes contain TODO, aren't in this format, or are
missing once any release has curated notes (scripts/release_notes.py, the
same as Pubgrade-Sidecar's); the tests check all notes in docs/releases/
too. The workflow adds parts 3 and 4 from GitHub's generated notes; for a
first release (no published release before it), scripts/release_notes.py
first builds them instead, because without a previous tag GitHub starts at
an older tag of its own choice. The notes of immutable releases stay
editable, their assets don't, so the release is created as a draft, gets its
assets and is published last
(scripts/release_assets.py); a re-run of failed jobs finishes it. Every
job reads the notes of the tagged commit, which can't change, so the notes
must be right before the tag (the checks above). To fix the notes of a
published release, edit them by hand (they stay editable), and make the same
change in docs/releases/<version>.md on dev, for the docs. A re-run of
publish writes the notes of the tagged commit back into a published
release, over hand edits, so don't re-run it after editing them. Don't
re-run all jobs of a release that was published: that builds new image
digests and moves the release's image tags to them before it fails at the
release.
The images are scanned for known vulnerabilities with Trivy: in CI, in the
release workflow before the images are signed and tagged, and weekly for
latest
(scan.yml).
The scans of the app's image in CI and of releases fail on critical and high
vulnerabilities that have a fix; accept a finding only with a reason and an
expiry date, in .trivyignore.yaml. The updater's image, which isn't built
on FOCA, is reported only. Since 0.2.0, latest is the image of the highest
stable release; its weekly scan fails on the same findings as the other
scans of the app's image.
The scripts in scripts/ use only the standard library and are tested in
tests/scripts/, with the app's coverage.