Skip to main content

Resolve Docker images to their source code commits on GitHub

Project description

code-provenance

Resolve Docker images in a docker-compose file to their exact source code commits on GitHub.

Installation

pip install code-provenance

Requires Python 3.10+.

CLI Usage

code-provenance [compose-file] [--image IMAGE] [--json] [--verbose]
  • compose-file -- path to a docker-compose file (default: docker-compose.yml)
  • --image IMAGE -- resolve a single image reference instead of a compose file
  • --json -- output results as JSON
  • --verbose, -v -- show resolution steps for each image

Examples

Resolve all images in a docker-compose file:

code-provenance docker-compose.yml
web: traefik:v3.6.0
  repo:       github.com/traefik/traefik
  commit:     06db5168c0d9
  status:     resolved
  confidence: exact
  url:        https://github.com/traefik/traefik/commit/06db5168c0d9...

Resolve a single image:

code-provenance --image ollama/ollama:0.12.3
image: ollama/ollama:0.12.3
  repo:       github.com/ollama/ollama
  commit:     b04e46da3ebc
  status:     resolved
  confidence: exact
  url:        https://github.com/ollama/ollama/commit/b04e46da3ebc...

Library Usage

from code_provenance.compose_parser import parse_compose, parse_image_ref
from code_provenance.resolver import resolve_image

yaml_content = open("docker-compose.yml").read()
for service, image in parse_compose(yaml_content):
    ref = parse_image_ref(image)
    result = resolve_image(service, ref)
    print(f"{result.service}: {result.commit} ({result.confidence})")

API Reference

Functions

  • parse_compose(yaml_content: str) -> list[tuple[str, str]] -- parse a docker-compose YAML string and return (service_name, image_string) pairs
  • parse_image_ref(image: str) -> ImageRef -- parse a Docker image string into its components
  • resolve_image(service: str, ref: ImageRef) -> ImageResult -- resolve an image reference to its source code commit

ImageRef

Field Type Description
registry str e.g. "ghcr.io", "docker.io"
namespace str e.g. "myorg", "library"
name str e.g. "traefik", "postgres"
tag str e.g. "v3.6.0", "latest"
raw str original image string from docker-compose

ImageResult

Field Type Description
service str service name from docker-compose
image str original image string
registry str image registry
repo str | None GitHub repository URL
tag str image tag
commit str | None resolved commit SHA
commit_url str | None URL to the commit on GitHub
status str "resolved", "repo_not_found", "repo_found_tag_not_matched", or "no_tag"
resolution_method str | None how the commit was resolved (e.g. "oci_labels", "tag_match")
confidence str | None "exact" or "approximate"
steps list[str] resolution steps taken (useful with --verbose)

Authentication

Set GITHUB_TOKEN for full functionality (digest resolution, :latest on GHCR, higher rate limits):

export GITHUB_TOKEN=ghp_your_token_here

Create a classic token at https://github.com/settings/tokens with read:packages scope. If using the gh CLI, run gh auth refresh -h github.com -s read:packages first.

The run.sh wrapper auto-detects the token from gh CLI if available.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_provenance-0.1.13.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_provenance-0.1.13-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file code_provenance-0.1.13.tar.gz.

File metadata

  • Download URL: code_provenance-0.1.13.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for code_provenance-0.1.13.tar.gz
Algorithm Hash digest
SHA256 29a18a405d6cee72ddd06ccb360ee3fd8908d7d8a779ab26c436af65dfe275a5
MD5 0b0887dbc62601295ae44d55267d8d65
BLAKE2b-256 43378e6ee89fbc84768e0a628e96061a1964ce4e61edf357549e0556dea337b1

See more details on using hashes here.

File details

Details for the file code_provenance-0.1.13-py3-none-any.whl.

File metadata

File hashes

Hashes for code_provenance-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 c68e0408e019aa16d310520fcfbc11041d6dfab1e214fd0f86973f35b2ae997a
MD5 f5207f235f42c71066ff7356da6c790c
BLAKE2b-256 6e4cfadfb8d37a7027d3a43d9519197da3f676ad1d933d135edb9a39780192f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page