Skip to content

PyPI Packaging & Release Publishing Guide

This guide details packaging architecture, build verification, and automated GitHub Actions PyPI publishing for CIS Benchmarks Tools Suite (cis-benchmarks-tools).


1. Packaging Architecture & Standards

  • PyPA Standard: Setuptools build backend (setuptools.build_meta) in pyproject.toml.
  • PSL ONLY: Strictly zero third-party dependencies (dependencies = []).
  • Dynamic Versioning: Resolved from the root VERSION file. Installed wheels fall back to importlib.metadata.version("cis-benchmarks-tools").
  • Data Bundling: 18 JSON rules (rules/*.json) and 2 HTML templates (templates/*.html) package into wheels via packages = ["rules", "templates"] and [tool.setuptools.package-data].
  • Console Entrypoints: audit-cis = "audit_cis:main" and audit_cis = "audit_cis:main".

2. Local Distribution Build & Verification

Build distribution archives (sdist and wheel) locally:

python -m pip install --upgrade build twine
python -m build

Verify wheel data assets using Python Standard Library:

python -c "import glob, zipfile; z = zipfile.ZipFile(glob.glob('dist/*.whl')[0]); assert len([n for n in z.namelist() if n.startswith('rules/') and n.endswith('.json')]) == 18; assert len([n for n in z.namelist() if n.startswith('templates/') and n.endswith('.html')]) == 2; print('Wheel data assets verified successfully!')"

3. Preflight Distribution Validation (twine check)

Validate metadata rendering and distribution integrity before PyPI upload:

python -m twine check --strict dist/*

Verifies README.md CommonMark syntax, metadata schema, and archive integrity with zero warnings.


4. Automated GitHub Actions Publishing Workflow

Automated publication is orchestrated by .github/workflows/pypi-publish.yml:

  • Triggers: Exclusively release: types: [published] and workflow_dispatch (with repository choice: pypi or testpypi, matching jmrenouard/MicroLLM). Tag pushes (push: tags:) are excluded to prevent premature publishing.
  • Concurrency: cancel-in-progress: false ensures active uploads are never aborted mid-transmission.
  • Preflight Twine Check: Executes python -m twine check --strict dist/* right after python -m build.
  • Authentication Modes:
  • PyPI Trusted Publishing (OIDC): Passwordless OpenID Connect token minting via id-token: write and pypa/gh-action-pypi-publish@release/v1.
  • API Token: Uses PYPI_API_TOKEN, PIPY_API_TOKEN, PYPI_TOKEN, TEST_PYPI_API_TOKEN, or TEST_PIPY_API_TOKEN with twine upload --non-interactive --skip-existing dist/*.
  • Graceful Notice: Emits an informational notice if neither credential method is configured.

5. Release Publication Procedure

  1. Local Validation: Run python scripts/pre_commit_checks.py and python -m unittest discover -s tests -v.
  2. Publish GitHub Release:
    gh release create v2.10.0 --title "v2.10.0" --notes-file docs/RELEASE_NOTES_v2.10.0.md
    
  3. Workflow Execution: Monitor Actions → Publish to PyPI.
  4. PyPI Verification: Verify live installation via pip install --upgrade cis-benchmarks-tools.

6. Docker Hub Container Packaging & Release Publishing

Multi-platform container published to Docker Hub at jmrenouard/cis-benchmarks-tools.

Architecture & Standards

  • Base Image: python:3.12-slim.
  • Non-Root: cisuser:cisgroup (UID/GID 10001).
  • PSL ONLY: Zero external dependencies.
  • Assets: Bundles 18 CIS rule specs (rules/*.json) and HTML templates (templates/*.html).
  • Volume: /app/reports.

Local Container Build & Verification

docker build -t jmrenouard/cis-benchmarks-tools:latest .
docker run --rm jmrenouard/cis-benchmarks-tools --list-targets
docker run --rm -v $(pwd)/reports:/app/reports jmrenouard/cis-benchmarks-tools --target mariadb106 -o /app/reports/audit.html

Automated GitHub Actions Workflow

Orchestrated by .github/workflows/docker-publish.yml:

  • Triggers: release: types: [published] and manual workflow_dispatch.
  • Platforms: linux/amd64 and linux/arm64 (Buildx/QEMU).
  • Tags: latest, vX.Y.Z, and X.Y.Z (resolved dynamically from github.event.release.tag_name or VERSION).
  • OCI Metadata & Release Notes: Embeds org.opencontainers.image.* and com.cis-benchmarks-tools.release-notes labels (major/MySQLTuner-perl & jmrenouard/MicroLLM conventions).
  • Secrets: Supports DOCKERHUB_USERNAME (fallback: DOCKER_USER_LOGIN or DOCKER_USERNAME) and DOCKERHUB_TOKEN (fallback: DOCKER_USER_PASSWORD or DOCKER_PASSWORD).

7. Versioned MkDocs Publishing (IONOS SFTP)

Versioned documentation publishes to https://cis-benchmarks.lightpath.fr/ via MkDocs Material (mkdocs.yml, requirements-docs.txt).

  • Builder & Hooks: scripts/build_versioned_docs.py builds /main/ (/dev/), release tags (/latest/, v2.9.0–v2.10.0), versions.json (mike), and .htaccess redirects with assert_no_private_files. scripts/mkdocs_hooks.py mounts virtual root docs and rewrites links.
  • Local Preview:
pip install -r requirements-docs.txt
python scripts/build_versioned_docs.py --output /tmp/cis-site-dist --main-ref WORKTREE
  • CI & Deploy Workflows: .github/workflows/docs-ci.yml validates documentation structure, links, and mkdocs build --strict. .github/workflows/docs-publish.yml builds and uploads via SFTP (sftp_only: true, explicit .htaccess upload) on main, published releases, or workflow_dispatch.
  • Required IONOS Secrets: IONOS_FTP_SERVER, IONOS_FTP_USERNAME, IONOS_FTP_PASSWORD, IONOS_FTP_PORT (22), and IONOS_REMOTE_PATH (cis-benchmarks.lightpath.fr).