|
1 | 1 | # docker-variant |
2 | | -Docker extension with PEP 817-like variant properties matching for container images |
| 2 | + |
| 3 | +Hardware-variant-aware container image selection for Docker, modeled on |
| 4 | +Python's [PEP 817 wheel variants](https://peps.python.org/pep-0817/). |
| 5 | + |
| 6 | +Publish one *base version* of an image as several *variants* — say a CUDA |
| 7 | +12.8 build, a CUDA 12.6 build, and a CPU-only fallback — and let the client |
| 8 | +pick the right one for the machine it runs on: |
| 9 | + |
| 10 | +```console |
| 11 | +$ docker variant pull registry.example.com/myorg/app:2.1.0 |
| 12 | +Selected variant "cu128" of registry.example.com/myorg/app version 2.1.0 |
| 13 | +... |
| 14 | +Tagged registry.example.com/myorg/app:2.1.0 and registry.example.com/myorg/app:2.1.0-cu128 |
| 15 | +``` |
| 16 | + |
| 17 | +The same command on a GPU-less machine selects the `null` (CPU-only) |
| 18 | +variant, and on a machine with no compatible variant at all it falls back to |
| 19 | +the plain `2.1.0` tag. |
| 20 | + |
| 21 | +## How it works |
| 22 | + |
| 23 | +PEP 817's wheel-variant concepts are mapped onto standard Docker/OCI |
| 24 | +primitives — no registry modifications required: |
| 25 | + |
| 26 | +| PEP 817 | docker-variant | |
| 27 | +|---|---| |
| 28 | +| variant label in the wheel filename | tag suffix: `app:2.1.0-cu128` | |
| 29 | +| variant properties (`ns :: feature :: value`) | image config labels: `dev.pep817.variant.nvidia.cuda_version_lower_bound=12.8` | |
| 30 | +| `{name}-{version}-variants.json` on the index | variant index: an OCI artifact at `app:2.1.0-variants` mapping labels → properties + manifest **digests** | |
| 31 | +| provider plugins (hardware detection) | compiled-in detectors (NVIDIA via nvidia-smi, x86-64 levels via CPUID, arm64) | |
| 32 | +| null variant | `app:2.1.0-null`, zero properties, always compatible, ranked last | |
| 33 | + |
| 34 | +Declaring a variant is just Dockerfile labels: |
| 35 | + |
| 36 | +```dockerfile |
| 37 | +LABEL dev.pep817.variant-label="cu128" \ |
| 38 | + dev.pep817.variant.nvidia.cuda_version_lower_bound="12.8" |
| 39 | +``` |
| 40 | + |
| 41 | +`docker variant pull` fetches the index, detects the local hardware, ranks |
| 42 | +the compatible variants (index priorities → system preference → |
| 43 | +deterministic tie-breaks), and pulls the winner **by digest**. |
| 44 | + |
| 45 | +## Commands |
| 46 | + |
| 47 | +| Command | What it does | |
| 48 | +|---|---| |
| 49 | +| `docker variant detect` | Show this machine's variant properties | |
| 50 | +| `docker variant pull REPO:VERSION` | Pull the best-matching variant (`--dry-run`, `--properties-file`, `--no-fallback`) | |
| 51 | +| `docker variant push REPO:VERSION-LABEL` | Push a variant tag and update the repository's variant index | |
| 52 | +| `docker variant list REPO:VERSION` | Table of variants with match ranking for this host | |
| 53 | +| `docker variant inspect REPO:VERSION` | Raw variant index JSON | |
| 54 | +| `docker variant index update REPO:VERSION` | Rebuild the index by scanning the registry's tags | |
| 55 | + |
| 56 | +All registry-touching commands accept `--plain-http`; loopback registries |
| 57 | +use plain HTTP automatically. |
| 58 | + |
| 59 | +## Registry side |
| 60 | + |
| 61 | +Two deployment modes: |
| 62 | + |
| 63 | +1. **Any V2 registry** (Docker Hub, registry:2, Harbor, …): `variant push` / |
| 64 | + `index update` maintain the `-variants` index artifact from the client. |
| 65 | +2. **variant-proxy**: a stateless reverse proxy in front of the registry |
| 66 | + that serves `GET /v2/<name>/_variants/<version>` computed on the fly from |
| 67 | + image labels — publishers then need nothing but plain `docker push`. |
| 68 | + The client tries the endpoint first and falls back to the artifact. |
| 69 | + |
| 70 | +```console |
| 71 | +$ variant-proxy --listen :5599 --upstream registry.internal:5000 |
| 72 | +``` |
| 73 | + |
| 74 | +## Try it |
| 75 | + |
| 76 | +```console |
| 77 | +$ make demo # full walkthrough against a throwaway local registry |
| 78 | +$ make install-plugin # installs into ~/.docker/cli-plugins => `docker variant ...` |
| 79 | +$ make e2e # the same flows as CI assertions |
| 80 | +``` |
| 81 | + |
| 82 | +The demo builds three variants of a runnable hello image, publishes them, |
| 83 | +then pulls under three mocked hardware profiles (`demo/profiles/*.json`) so |
| 84 | +you can watch the selection change — and repeats the flow through |
| 85 | +variant-proxy with plain `docker push` only. |
| 86 | + |
| 87 | +## Development |
| 88 | + |
| 89 | +```console |
| 90 | +$ make test # unit tests (pkg/variant is pure and I/O-free) |
| 91 | +$ make vet |
| 92 | +$ make e2e # needs docker |
| 93 | +``` |
| 94 | + |
| 95 | +Design and rationale: [docs/PLAN.md](docs/PLAN.md) (roadmap, plugin-vs-fork |
| 96 | +and registry-side decisions) and [docs/DESIGN.md](docs/DESIGN.md) (frozen v1 |
| 97 | +contracts: label schema, index schema, selection algorithm, ADRs). |
| 98 | + |
| 99 | +## Status / roadmap |
| 100 | + |
| 101 | +Working end-to-end (see `e2e/run.sh`): publish, list, select, pull, |
| 102 | +fallback chain, proxy. Planned next: OCI 1.1 referrers-based index |
| 103 | +attachment, index signing (cosign), an exec-based detection-provider |
| 104 | +protocol behind explicit opt-in, and a moby fork PoC to demonstrate native |
| 105 | +`docker pull` integration. |
0 commit comments