docker_tag_updater.skopeo
#
Tools for Skopeo.
This module defines the functions that are used for the CLI tool (image-version-checker).
- compare_versions(source_ver, target_ver, rule='default', verbose=False)#
Compare the current and newest semver, return the neweset version.
The comparision will be done using the python-semver package. A simple comparison of the major, minor, and patch versions only, is implemented in this version.
- Parameters:
- Return type:
- Returns:
The most up-to-date semver string.
See also
docker_tag_updater.helpers.regex_rules
For more information about
RegexRules
.
Examples
>>> compare_versions("v1.2.3", "v1.2.4", rule="default") v1.2.4
>>> compare_versions("v1.2.4", "v1.2.3", rule="default") v1.2.4
Comparing linuxserver semver strings will only consider up to its patch version.
>>> compare_versions("v1.2.3.456-ls789", "v1.2.3.456-ls798", rule="lscr") v1.2.3.456-ls789
- image_version(image, registry='docker.io', base_tag='latest', inspector=<function inspect>, verbose=False)#
Get the container image version from its annotations.
- Parameters:
image (
str
) – The container image, e.g., hello-world.registry (
str
) – The registry where the image is hosted on. Default'docker.io'
.base_tag (
str
) – The name of the base tag to refer against. Default'latest'
.inspector (
Callable
) – The inspection method. Defaultdocker_tag_updater.skopeo.inspect()
.verbose (
bool
) – Specify the verbosity of the inspector function. DefaultFalse
.
- Return type:
- Returns:
The most up-to-date version of the image with the specified tag on the specified registry.
- Raises:
KeyError – If annotations of the container image is not set.
Examples
The current tagged version of traefik is v2.11.0. This is also reflected in their annotated Docker container image.
>>> image_version("traefik") v2.11.0
On the other hand, the official hello-world Docker container image does not have the right annotations. It will raise a KeyError.
>>> image_version("hello-world") KeyError: 'The version label for docker.io/hello-world:latest is not set.'
- inspect(image, registry='docker.io', base_tag='latest', verbose=False)#
Run ‘skopeo inspect’.
A container image will be queried by skopeo and the contents of the inspection will be returned as a dictionary as-is.
- Parameters:
- Returns:
The result of the skopeo process as a dictionary.
- Return type:
- parse(image_string)#
Parse the image string to get its registry, image, and tag.
- Parameters:
image_string (
str
) – The container image possibly with the registry and tag included.- Returns:
The registry, image, and tag as a tuple.
- Return type:
Examples
>>> _parse('hello-world') ('docker.io', 'hello-world', 'latest')
>>> _parse('lscr.io/linuxserver/mariadb:10.11.6-r0-ls136') ('lscr.io', 'linuxserver/mariadb', '10.11.6-r0-ls136')