docker
docker
Prepare Docker build variables to match the legacy bash script.
Classes
RegistryTag
Published state of an image tag in a registry.
RegistryTag
docker.RegistryTag(last_updated, platforms)
Published state of an image tag in a registry.
Attributes
last_updated
str
ISO8601 time the tag was last published, or an empty string when the registry does not report it.
platforms
set [str ]
Published os/arch[/variant] platforms.
Functions
base_image_name
docker.base_image_name(dockerfile)
Get base image names from a Dockerfile.
Matches the bash behavior: only lines starting with “FROM” are used and the literal “FROM” substring is removed everywhere on that line.
dockerfile_last_commit_iso
docker.dockerfile_last_commit_iso(dockerfile_path)
Get the last git commit timestamp for the Dockerfile.
Parameters
dockerfile_path
str
Path to the Dockerfile in the repository.
required
Returns
str
str
ISO8601 timestamp from git %cI format, or an empty string
str
when the file is missing, untracked, or has no git history.
dockerhub_tag_info
docker.dockerhub_tag_info(
dockerhub_namespace,
repo_name,
image_tag,
timeout= 20 ,
session= requests,
)
Get the published state of a Docker Hub tag.
Parameters
dockerhub_namespace
str
Docker Hub namespace/org.
required
repo_name
str
Docker Hub repository name.
required
image_tag
str
Docker image tag.
required
timeout
int
HTTP timeout in seconds.
20
session
Object with a requests-compatible get method.
requests
Returns
RegistryTag | None
RegistryTag or None: Tag state, or None when the tag is absent.
dockerhub_tag_last_updated
docker.dockerhub_tag_last_updated(
dockerhub_namespace,
repo_name,
image_tag,
timeout= 20 ,
session= requests,
)
Get Docker Hub tag last_updated timestamp.
Parameters
dockerhub_namespace
str
Docker Hub namespace/org.
required
repo_name
str
Docker Hub repository name.
required
image_tag
str
Docker image tag.
required
timeout
int
HTTP timeout in seconds.
20
session
Object with a requests-compatible get method.
requests
Returns
str | None
str or None: ISO8601 last_updated value, or None when tag is absent.
evaluate_docker_build_staleness
docker.evaluate_docker_build_staleness(
dockerfile_path,
image_name,
dockerhub_namespace,
repo_name,
registries= 'dockerhub' ,
ghcr_namespace= '' ,
platforms= '' ,
github_token= '' ,
)
Decide whether to build a Docker image based on Dockerfile git history and tag freshness.
The build is skipped only when every selected registry already has the tag, the tag is at least as new as the Dockerfile’s last commit, and it includes every requested platform.
Parameters
dockerfile_path
str
Path to Dockerfile in repository.
required
image_name
str
Target image name, including tag.
required
dockerhub_namespace
str
Docker Hub namespace/org.
required
repo_name
str
Image repository name.
required
registries
str
Comma-separated registries to check (dockerhub, ghcr).
'dockerhub'
ghcr_namespace
str
GHCR owner or organization.
''
platforms
str
Comma-separated requested platforms; empty to skip platform checks.
''
github_token
str
Token for reading private GHCR packages.
''
Returns
dict
dict [str , str ]
Build decision fields suitable for GitHub Action outputs.
evaluate_docker_build_staleness_and_set_outputs
docker.evaluate_docker_build_staleness_and_set_outputs(
dockerfile_path,
image_name,
dockerhub_namespace,
repo_name,
registries= 'dockerhub' ,
ghcr_namespace= '' ,
platforms= '' ,
github_token= '' ,
)
Evaluate Docker build staleness and set step outputs.
Parameters
dockerfile_path
str
Path to Dockerfile in repository.
required
image_name
str
Target image name, including tag.
required
dockerhub_namespace
str
Docker Hub namespace/org.
required
repo_name
str
Image repository name.
required
registries
str
Comma-separated registries to check (dockerhub, ghcr).
'dockerhub'
ghcr_namespace
str
GHCR owner or organization.
''
platforms
str
Comma-separated requested platforms.
''
github_token
str
Token for reading private GHCR packages.
''
Returns
dict
dict [str , str ]
Build decision fields written to GitHub Action outputs.
ghcr_tag_info
docker.ghcr_tag_info(
ghcr_namespace,
repo_name,
image_tag,
github_token= '' ,
timeout= 20 ,
session= requests,
)
Get the published state of a GitHub Container Registry tag.
The publish time is the oldest image config created time among the tag’s platform images, which buildx sets to the build time.
Parameters
ghcr_namespace
str
GHCR owner or organization.
required
repo_name
str
GHCR image repository name.
required
image_tag
str
Docker image tag.
required
github_token
str
Token for private packages; public packages are read anonymously when empty.
''
timeout
int
HTTP timeout in seconds.
20
session
Object with a requests-compatible get method.
requests
Returns
RegistryTag | None
RegistryTag or None: Tag state, or None when the tag is absent.
image_tag_from_image_name
docker.image_tag_from_image_name(image_name)
Extract the tag suffix from a Docker image name.
Parameters
image_name
str
Docker image reference, optionally including a tag.
required
Returns
str
str
Tag string, or an empty string if no tag is present.
parse_iso_timestamp
docker.parse_iso_timestamp(raw)
Parse an ISO timestamp and normalize it to UTC.
Parameters
raw
str
ISO8601 timestamp (for example 2026-01-01T12:00:00Z).
required
prepare_docker_build_variables
docker.prepare_docker_build_variables(
dockerfile,
suffix,
dockerhub_account,
github_env= None ,
now= None ,
)
Prepare Docker build variables and optionally write them to GITHUB_ENV.
For a root-level Dockerfile, derive the image repository name from GITHUB_REPOSITORY and write the README path relative to the workspace.
Parameters
dockerfile
str
Path to the Dockerfile.
required
suffix
str
Suffix for the image tag (e.g., “dev”, “main”).
required
dockerhub_account
str
Docker Hub account/namespace.
required
github_env
str
Path to the GitHub Actions env file.
None
now
datetime
Override current time for deterministic output.
None
Returns
dict
dict [str , str ]
Mapping of variable names to their values.
registry_build_reason
docker.registry_build_reason(tag, dockerfile_last_commit, platforms)
Explain why a registry tag needs rebuilding.
Parameters
tag
RegistryTag or None
Published tag state, or None when absent.
required
dockerfile_last_commit
str
ISO8601 time of the Dockerfile’s last commit.
required
platforms
list [str ]
Requested platforms; empty to skip platform checks.
required
Returns
str
str
Build reason, or an empty string when the tag is up-to-date.
tag_from_dockerfile
docker.tag_from_dockerfile(dockerfile)
Extract the tag from the Dockerfile name (last extension).
Mirrors bash ${bn_dockerfile##*.} behavior.