genvid.toolbox.DockerTool¶
-
class
genvid.toolbox.
DockerTool
¶ Bases:
genvid.toolbox.network.NetworkTool
Handle manipulation of a Docker image archive.
-
RE_IMAGE_IMAGEID
= re.compile('(?P<image>.+)_(?P<version>[^_]*)_(?P<imageid>[0-9a-f]{12})\\.(?P<archfmt>[^.]*)')¶ Decompose an image filename into <image>_<version>_<id>.<archfmt>
-
RE_SUCCESSFUL_BUILD
= re.compile('(Successfully built |sha256:)([0-9a-f]+)')¶ Docker build success-message regular expression.
-
RE_DIRTY_VERSION
= re.compile('^(latest|dev|.*[.+]dirty|\\d+\\.\\d+\\.\\d+\\.0)$')¶ Regex to determine if an image version is dirty.
Dirty versions are those whose build number is 0.
Changed in version 1.20.0: Updated the regex to follow the new convention for dirty builds introduced in the new release model.
-
IMAGE_TEMPLATE
= '{image}_{version}_{imageid}.{archfmt}'¶ Template of an image filename. Must match
RE_IMAGE_IMAGEID
.
-
DOCKER_MACHINE_NAME
= None¶ A mirror of
DOCKER_MACHINE_NAME
, giving the name of the Docker machine.
-
docker
¶ A Docker client.
-
set_docker_env
()¶ Set up the Docker environment using Docker machine.
Changed in version 1.20.1: DOCKER_MACHINE_NAME no longer default to
default
. If not set, the environment will not be changed.
-
build_docker
(tag, path=None, rm=True, forcerm=True, **kwargs)¶ Build a Docker image.
Returns the image build.
-
static
version_to_imagetag
(image, version)¶ Return a tag suitable for Docker.
-
get_images_config_from_folder
(baseurl, basedir: typing.Union[pathlib.Path, str, NoneType] = None)¶ Returns the configuration for all images under basedir.
Parameters: - baseurl – The baseurl for all images.
- basedir – The folder under which the images are found.
Changed in version 1.20.0: * Renamed from
get_images_config
to avoid conflict with thegenvid.toolbox.SDK.get_images_config()
. * Addedbasedir
parameter.
-
update_image
(image: str, version: str = 'latest', clean: bool = False, compress: bool = False, basedir: typing.Union[pathlib.Path, str, NoneType] = None)¶ Update the image archive.
Parameters: - image – The name of the image.
- version – The version of the image.
- clean – If True, old images will be removed.
- compress – If True, the image will be compressed.
- basedir – The folder under which the image is saved. Default to
ARTIFACTS_DIR
.
Changed in version 1.12.0: Added the
compress
parameter.Changed in version 1.20.0: Added the
basedir
parameter.
-
get_image_path
(image, version, imageid, archfmt='docker', basedir: typing.Union[pathlib.Path, str, NoneType] = None) → str¶ Return the path for the specified image.
Parameters: basedir – The base path of the images. Default to ARTIFACTS_DIR
.Changed in version 1.20.0: Added the
basedir
parameter.
-
get_image_filename
(image, version, imageid, archfmt='docker') → str¶ Return the filename for the specified image.
New in version 1.20.0.
-
get_images
(basedir: typing.Union[pathlib.Path, str, NoneType] = None)¶ Generate a list of images under the
artifacts_dir
that matchRE_IMAGE_IMAGEID
.Parameters: basedir – Directory where to find the images. Default to ARTIFACTS_DIR
.Returns: a generated list of tuples containing the image, version, imageid and archfmt. Changed in version 1.20.0:: Added parameter
basedir
.
-
get_latest_images
(basedir: typing.Union[pathlib.Path, str, NoneType] = None)¶ Retun a dictionary of all the latest images in
basedir
.Parameters: basedir – Directory where to find the images. Default to ARTIFACTS_DIR
.Returns: dictionary of tuple of version, imageid and archfmt keyed with the image name. Changed in version 1.20.0:: Added parameter
basedir
.
-
-
class
docker.
DockerTool
¶ Implementation of
genvid.toolbox.DockerTool