libera_utils.aws.ecr_upload#
Module for uploading docker images to the ECR
Functions
|
Build a Docker image from a specified directory and tag it with a custom name. |
|
CLI handler function for ecr-upload CLI subcommand. |
|
Perform programmatic docker login to the default ECR for the current AWS credential account (e.g. AWS_PROFILE) and return a DockerClient object for interacting with the ECR. |
|
Programmatically upload a docker image for a science algorithm to an ECR. |
Classes
|
Context manager object, suitable for use with docker-py DockerClient.login |
- class libera_utils.aws.ecr_upload.DockerConfigManager(override_default_config: bool = False)#
Context manager object, suitable for use with docker-py DockerClient.login
If override_default_config is True, dockercfg_path points to a temporary directory with a blank config. Otherwise, dockercfg_path is None, which allows DockerClient.login to use the default config location.
- libera_utils.aws.ecr_upload.build_docker_image(context_dir: str | Path, image_name: str, tag: str = 'latest', target: str | None = None, platform: str = 'linux/amd64') None #
Build a Docker image from a specified directory and tag it with a custom name.
- Parameters:
context_dir (Union[str, Path]) – The path to the directory containing the Dockerfile and other build context.
image_name (str) – The name to give the Docker image.
tag (str, optional) – The tag to apply to the image (default is ‘latest’).
target (Optional[str]) – Name of the target to build.
platform (str) – Default “linux/amd64”.
- Raises:
ValueError – If the specified directory does not exist or the build fails.
- libera_utils.aws.ecr_upload.ecr_upload_cli_func(parsed_args: Namespace) None #
CLI handler function for ecr-upload CLI subcommand.
- Parameters:
parsed_args (argparse.Namespace) – Namespace of parsed CLI arguments
- Return type:
None
- libera_utils.aws.ecr_upload.get_ecr_docker_client(region_name: str | None = None, dockercfg_path: Path | None = None) DockerClient #
Perform programmatic docker login to the default ECR for the current AWS credential account (e.g. AWS_PROFILE) and return a DockerClient object for interacting with the ECR.
- Parameters:
region_name (Optional[str]) – AWS region name. Each region has a separate default ECR. If region_name is None, boto3 uses the default region for the configured credentials.
dockercfg_path (Optional[Path]) – Use a custom path for the Docker config file. (default $HOME/.docker/config.json if present, otherwise $HOME/.dockercfg)
- Returns:
Logged in docker client.
- Return type:
docker.DockerClient
- libera_utils.aws.ecr_upload.push_image_to_ecr(image_name: str, image_tag: str, algorithm_name: str | ProcessingStepIdentifier, *, ecr_image_tags: List[str] | None = None, region_name: str = 'us-west-2', ignore_docker_config: bool = False) None #
Programmatically upload a docker image for a science algorithm to an ECR. ECR name is determined based on the algorithm name.
- Parameters:
image_name (str) – Local name of the image
image_tag (str) – Local tag of the image (often latest)
algorithm_name (Union[str, constants.ProcessingStepIdentifier]) – Processing step ID string or object. Used to infer the ECR repository name. L0 processing step IDs are not allowed because they have no associated ECR.
ecr_image_tags (Optional[List[str]]) – List of tags to apply to the pushed image in the ECR (e.g. [“1.3.4”, “latest”]). Default None, results in pushing only as “latest”.
region_name (str) – AWS region. Used to infer the ECR name.
ignore_docker_config (bool) – Default False. If True, creates a temporary docker config.json file to prevent using stored credentials.
- Return type:
None