id: python-hashed-offline-wheelhouse
namespace: company.platform
inputs:
- id: requirements
type: FILE
description: Trusted UTF-8 lock with exact package==version pins and SHA256
hashes for every dependency; no URLs, includes or markers.
- id: python_image
type: STRING
defaults: python:3.13-slim
description: Trusted Linux Python image providing pip and venv. Use the
deployment image, preferably pinned by digest.
tasks:
- id: lock_size
type: io.kestra.plugin.core.storage.Size
uri: "{{ inputs.requirements }}"
- id: bound_lock
type: io.kestra.plugin.core.execution.Assert
conditions:
- "{{ outputs.lock_size.size > 0 and outputs.lock_size.size <= 65536 }}"
- id: workspace
type: io.kestra.plugin.core.flow.WorkingDirectory
description: Keep the validated lock and downloaded wheels available to a
separate container with networking disabled.
inputFiles:
requirements.lock: "{{ inputs.requirements }}"
tasks:
- id: validate_lock
type: io.kestra.plugin.scripts.python.Script
containerImage: "{{ inputs.python_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: none
env:
TARGET_IMAGE: "{{ inputs.python_image }}"
script: |
import importlib.metadata
import json
import os
import platform
import re
import sys
from pathlib import Path
text = Path("requirements.lock").read_text(encoding="utf-8")
text = text.replace("\\\n", " ")
pattern = re.compile(
r"([A-Za-z0-9][A-Za-z0-9._-]*)(?:\[[A-Za-z0-9_,.-]+\])?"
r"==[A-Za-z0-9][A-Za-z0-9.!+_-]*\s+"
r"(?:--hash=sha256:[0-9a-fA-F]{64}(?:\s+|$))+"
)
names = set()
for line in text.splitlines():
line = line.split("#", 1)[0].strip()
if not line:
continue
match = pattern.fullmatch(line)
if not match:
raise ValueError("Use exact pins with SHA256 hashes; URLs, includes, options and markers are unsupported")
name = re.sub(r"[-_.]+", "-", match[1]).lower()
if name in names:
raise ValueError("Duplicate distribution in lock: " + name)
names.add(name)
if not 1 <= len(names) <= 100:
raise ValueError("Provide 1-100 fully pinned distributions, including transitive dependencies")
Path("platform.json").write_text(json.dumps({
"image": os.environ["TARGET_IMAGE"], "python": sys.version,
"platform": platform.platform(), "machine": platform.machine(),
"pip": importlib.metadata.version("pip"), "locked_distributions": len(names)
}, indent=2), encoding="utf-8")
- id: download_wheels
type: io.kestra.plugin.scripts.python.Commands
description: Resolve the complete locked dependency set using wheels only and
require hashes for every download.
containerImage: "{{ inputs.python_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
timeout: PT15M
commands:
- "python -m pip --isolated download --disable-pip-version-check
--no-cache-dir --require-hashes --only-binary=:all:
--index-url=https://pypi.org/simple --dest=wheels
--requirement=requirements.lock"
- id: prove_offline_install
type: io.kestra.plugin.scripts.python.Commands
description: A fresh venv must install the lock, validate dependencies and
produce a report with no container network access.
containerImage: "{{ inputs.python_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: none
timeout: PT10M
commands:
- python -m venv offline-env
- "offline-env/bin/python -m pip --isolated install
--disable-pip-version-check --no-cache-dir --no-index
--find-links=wheels --require-hashes --only-binary=:all:
--ignore-installed --report=install-report.json
--requirement=requirements.lock"
- offline-env/bin/python -m pip check
- offline-env/bin/python -m pip inspect --local > installed.json
- id: package_verified_wheels
type: io.kestra.plugin.scripts.python.Script
containerImage: "{{ inputs.python_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: none
outputFiles:
- wheelhouse.zip
- manifest.json
- install-report.json
script: |
import hashlib
import json
import zipfile
from pathlib import Path
wheels = sorted(Path("wheels").glob("*.whl"))
if not wheels or len(wheels) > 100:
raise ValueError("Expected 1-100 verified wheel files")
paths = [Path(name) for name in (
"requirements.lock", "platform.json", "install-report.json", "installed.json"
)] + wheels
if sum(path.stat().st_size for path in paths) > 268435456:
raise ValueError("Verified files exceed the 256 MiB publication limit")
manifest = {path.as_posix(): {
"sha256": hashlib.sha256(path.read_bytes()).hexdigest(), "bytes": path.stat().st_size
} for path in paths}
Path("manifest.json").write_text(json.dumps(manifest, indent=2), encoding="utf-8")
with zipfile.ZipFile("wheelhouse.zip", "w", compression=zipfile.ZIP_STORED) as archive:
for path in sorted(paths + [Path("manifest.json")]):
info = zipfile.ZipInfo(path.as_posix(), date_time=(1980, 1, 1, 0, 0, 0))
info.external_attr = 0o100644 << 16
archive.writestr(info, path.read_bytes())
outputs:
- id: wheelhouse
type: FILE
required: false
value: "{{ outputs.package_verified_wheels.outputFiles['wheelhouse.zip'] ?? null
}}"
- id: manifest
type: FILE
required: false
value: "{{ outputs.package_verified_wheels.outputFiles['manifest.json'] ?? null
}}"
- id: installation_report
type: FILE
required: false
value: "{{ outputs.package_verified_wheels.outputFiles['install-report.json'] ??
null }}"
triggers:
- id: lock_ready
type: io.kestra.plugin.core.trigger.Webhook
key: "{{ secret('WHEELHOUSE_WEBHOOK_KEY') }}"
inputs:
requirements: "{{ trigger.body.requirements }}"
python_image: "{{ trigger.body.python_image ?? 'python:3.13-slim' }}"