docker#

Make docker cli easier to work with AWS ECR.

simple_aws_ecr.docker.get_ecr_registry_url(aws_account_id: str, aws_region: str)[source]#

Get the full ECR registry URL.

Parameters:
  • aws_account_id – The AWS account id of your ECR repo.

  • aws_region – The AWS region of your ECR repo

simple_aws_ecr.docker.get_ecr_image_uri(aws_account_id: str, aws_region: str, ecr_repo_name: str, tag: str) str[source]#

Get the full ECR repo URI with image tag.

Parameters:
  • aws_account_id – The AWS account id of your ECR repo.

  • aws_region – The AWS region of your ECR repo

  • ecr_repo_name – the ECR repo name

  • tag – the image tag

simple_aws_ecr.docker.get_ecr_auth_token(ecr_client: ECRClient) Tuple[str, str][source]#

Get ECR auth token using boto3 SDK.

Reference:

Returns:

username and password

simple_aws_ecr.docker.docker_login(username: str, password: str, registry_url: str) bool[source]#

Login docker cli to AWS ECR. Run:

echo ${password} | docker login -u ${username} --password-stdin ${registry_url}

Reference:

Returns:

a boolean flag to indicate if the login is successful.

simple_aws_ecr.docker.ecr_login(ecr_client: ECRClient, aws_account_id: str, aws_region: str) bool[source]#

Login docker cli to AWS ECR using boto3 SDK and AWS CLI.

Returns:

a boolean flag to indicate if the login is successful.

class simple_aws_ecr.docker.EcrContext(aws_account_id: str, aws_region: str, repo_name: str, path_dockerfile: Path)[source]#

A utility class to help build and push docker image to ECR.

Parameters:
  • aws_account_id – The AWS account id of your ECR repo.

  • aws_region – The AWS region of your ECR repo

  • repo_name – the repo name

  • dir_dockerfile – the directory where the Dockerfile is located.

classmethod from_bsm(bsm: BotoSesManager, repo_name: str, path_dockerfile: Path)[source]#

Create a new instance of EcrContext.

Parameters:
  • bsmboto_session_manager.BotoSesManager object.

  • repo_name – ECR repo name.

  • path_dockerfile – the path to the Dockerfile.

get_image_uri(tag: str) str[source]#

Get the ECR container image URI.

Parameters:

tag – the container image tag.

build_image(image_tag_list: Optional[List[str]] = None, additional_args: Optional[List[str]] = None)[source]#

Build docker image.

Parameters:

image_tag_list – the list of tag you want to give to the built image,

e.g. [“latest”, “0.1.1”] :param additional_args: additional command line arguments for docker build ...

Note

If you are trying to build a linux/amd64 compatible image on an ARM chip Mac you need to set "--platform=linux/amd64" in the additional_args.

push_image(image_tag_list: Optional[List[str]] = None, additional_args: Optional[List[str]] = None)[source]#

Push Docker image to ECR.

test_image(tag: Optional[str] = None, additional_args: Optional[List[str]] = None)[source]#

Test the container image locally by running it.

Parameters:

additional_args – additional command line arguments for docker run ...