ECR¶
Utilities for working with Amazon Elastic Container Registry.
Overview¶
| Module | Description |
|---|---|
| Core | Core ECR utilities |
| Image Replicator | Container image replication |
ECRImage
dataclass
¶
ECRImage(
account_id,
region,
repository_name,
image_digest,
image_manifest=None,
client=None,
)
Bases: ECRMixins, DataClassModel
Source code in src/aibs_informatics_aws_utils/ecr/core.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
add_image_tags ¶
add_image_tags(*image_tags)
Add tags to image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*image_tags
|
str
|
Tags to add to image. |
()
|
Source code in src/aibs_informatics_aws_utils/ecr/core.py
490 491 492 493 494 495 496 497 498 | |
get_image_config ¶
get_image_config()
Get ECR or docker image configuration json metadata.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with image configuration. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
get_image_config_layer ¶
get_image_config_layer()
Get the image config layer from image manifest.
The schema of the image manifest config layer is defined here: https://distribution.github.io/distribution/spec/manifest-v2-2/#image-manifest-field-descriptions
Note
While docker image manifests can have multiple formats, ECR only supports the schema defined in the link above, a v2 single image manifest. There is a manifest list, that describes multiple architectures, but ECR does not support this. This method assumes the image manifest is in the correct format.
Returns:
| Type | Description |
|---|---|
LayerTypeDef
|
Layer Type dict of the config object. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
get_image_detail ¶
get_image_detail()
Get image detail of this image from ECR.
Returns:
| Type | Description |
|---|---|
ImageDetailTypeDef
|
Image detail dictionary. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
get_image_layers ¶
get_image_layers()
Get layers from image manifest into ECR Layer objects.
The schema of the image manifest layers is defined here: https://distribution.github.io/distribution/spec/manifest-v2-2/#image-manifest-field-descriptions
Note
While docker image manifests can have multiple formats, ECR only supports the schema defined in the link above, a v2 single image manifest. There is a manifest list, that describes multiple architectures, but ECR does not support this. This method assumes the image manifest is in the correct format.
Returns:
| Type | Description |
|---|---|
List[LayerTypeDef]
|
List of ECR Image layers. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
put_image ¶
put_image(image_tag)
Make a call to put_image API to add image to ECR repository.
This method will add an image to the ECR repository. If the image already exists, it will not raise an error. Instead, it will log that the image already exists with the given tag.
Note
This operation does not push an image to the repository. It only adds the image manifest to the repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_tag
|
Optional[str]
|
Tag to associate with image. If None, image is untagged. |
required |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
ECRImageReplicator ¶
Bases: LoggingMixin
put_image ¶
put_image(
source_image,
destination_repository,
destination_image_tags=None,
)
Put image manifest and tags for an image.
This is the final step in copying an ECR image. It must be done once all the layers of the image have been uploaded.
If the put_image request fails with a 'LayersNotFoundException', this will attempt to upload the missing layers and retry the put_image request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_image
|
ECRImage
|
Source image that has been copied. |
required |
destination_repository
|
ECRRepository
|
Destination repository. |
required |
destination_image_tags
|
Optional[List[str]]
|
Destination image tags. Optional. If not provided, source image's tags are added. |
None
|
Returns:
| Type | Description |
|---|---|
ECRImage
|
Destination ECR Image. |
Source code in src/aibs_informatics_aws_utils/ecr/image_replicator.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
replicate ¶
replicate(
source_image,
destination_repository,
destination_image_tags=None,
)
Copies the source image into the destination repository.
This allows the user to facilitate replication:
- between AWS accounts
- to a new repository
- with new tags
Note
This has exactly the same effect as docker pull; docker tag; docker push,
but is done with the AWS ECR SDK so we can run this in a lambda when our
stack updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_image
|
ECRImage
|
Configuration of image to pull. |
required |
destination_repository
|
ECRRepository
|
Repository to push to. |
required |
destination_image_tags
|
Optional[List[str]]
|
Optional list of tags to apply to the destination image. |
None
|
Returns:
| Type | Description |
|---|---|
ECRImage
|
Configuration of destination image pushed. |
Source code in src/aibs_informatics_aws_utils/ecr/image_replicator.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
upload_layers ¶
upload_layers(source_image, destination_repository)
Upload image layers of the source image to the destination repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_image
|
ECRImage
|
Source image that has been copied. |
required |
destination_repository
|
ECRRepository
|
Destination repository. |
required |
Source code in src/aibs_informatics_aws_utils/ecr/image_replicator.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
ECRImageUri ¶
Bases: ECRRepositoryUri
from_components
classmethod
¶
from_components(
repository_name,
image_tag=None,
image_digest=None,
account_id=None,
region=None,
)
Generate an Image URI.
If account ID not provided, account Id of credentials is used. If region is not provided, region of credentials is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repository_name
|
str
|
Name of ECR repository. |
required |
image_tag
|
Optional[str]
|
Tag associated with image. Defaults to None. |
None
|
image_digest
|
Optional[str]
|
The image digest. Defaults to None. |
None
|
account_id
|
Optional[str]
|
The registry ID. Defaults to None. |
None
|
region
|
Optional[str]
|
AWS region. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both or neither image tag / image digest are provided. |
Returns:
| Type | Description |
|---|---|
ECRImageUri
|
ECR Image URI. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
ECRRegistry
dataclass
¶
ECRRegistry(account_id, region, client=None)
Bases: ECRResource
Source code in src/aibs_informatics_aws_utils/ecr/core.py
322 323 324 325 | |
get_repositories ¶
get_repositories(
repository_name=None, repository_tags=None
)
Filter repositories based on resource tags specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repository_name
|
Optional[Union[str, Pattern]]
|
Repository name or pattern to filter by. |
None
|
repository_tags
|
Optional[List[ResourceTag]]
|
List of resource tags to filter by. |
None
|
Returns:
| Type | Description |
|---|---|
List[ECRRepository]
|
Filtered list of repositories with resource tags. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 | |
list_repositories ¶
list_repositories()
List all repositories in the Registry.
Returns:
| Type | Description |
|---|---|
List[ECRRepository]
|
List of repositories in the registry. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 | |
ECRRegistryUri ¶
Bases: ValidatedStr
from_components
classmethod
¶
from_components(account_id=None, region=None, **kwargs)
Generate a Registry URI.
If account ID not provided, account Id of credentials is used. If region is not provided, region of credentials is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_id
|
Optional[str]
|
The registry ID. Defaults to None. |
None
|
region
|
Optional[str]
|
AWS region. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments (unused). |
{}
|
Returns:
| Type | Description |
|---|---|
ECRRegistryUri
|
AWS Registry URI. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
ECRRepository
dataclass
¶
ECRRepository(
account_id, region, repository_name, client=None
)
Bases: ECRResource
Source code in src/aibs_informatics_aws_utils/ecr/core.py
629 630 631 632 633 634 635 636 637 | |
create ¶
create(
tags=None,
image_tag_mutability="MUTABLE",
exists_ok=True,
)
Create an ECR Repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tags
|
Optional[List[ResourceTag]]
|
List of repo tags to add. Defaults to None. |
None
|
image_tag_mutability
|
ImageTagMutabilityType
|
Whether image tag is immutable. Defaults to "MUTABLE". |
'MUTABLE'
|
exists_ok
|
bool
|
Suppress error if repository already exists. Defaults to True. |
True
|
Source code in src/aibs_informatics_aws_utils/ecr/core.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | |
delete ¶
delete(force)
Delete the ECR repository described by this instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
bool
|
Ignore if images in repository. |
required |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
708 709 710 711 712 713 714 715 716 | |
exists ¶
exists()
Check if repository exists.
Returns:
| Type | Description |
|---|---|
bool
|
True if repository exists. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
get_image ¶
get_image(image_tag=None, image_digest=None)
Get the image associated with the following tag or digest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_tag
|
Optional[str]
|
Image tag. Defaults to None. |
None
|
image_digest
|
Optional[str]
|
Image digest. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
ECRImage
|
The image with the image tag or digest. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | |
get_images ¶
get_images(tag_status='ANY')
Fetches all images in a given repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag_status
|
TagStatusType
|
Filter non-tagged images. Defaults to "ANY". |
'ANY'
|
Returns:
| Type | Description |
|---|---|
List[ECRImage]
|
List of images in repository. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 | |
ECRRepositoryUri ¶
Bases: ECRRegistryUri
from_components
classmethod
¶
from_components(
repository_name, account_id=None, region=None
)
Generate a Repository URI.
If account ID not provided, account Id of credentials is used. If region is not provided, region of credentials is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repository_name
|
str
|
Name of ECR repository. |
required |
account_id
|
Optional[str]
|
The registry ID. Defaults to None. |
None
|
region
|
Optional[str]
|
AWS region. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
ECRRepositoryUri
|
AWS Repository URI. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
ECRResource
dataclass
¶
ECRResource(account_id, region, client=None)
Bases: ECRMixins, DataClassModel
Source code in src/aibs_informatics_aws_utils/ecr/core.py
322 323 324 325 | |
get_resource_tags ¶
get_resource_tags()
Gets the tags for this ECR Resource.
Returns:
| Type | Description |
|---|---|
List[ResourceTag]
|
List of tags. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
586 587 588 589 590 591 592 593 594 595 596 | |
update_resource_tags ¶
update_resource_tags(
*tags, mode=cast(TagMode, TagMode.APPEND)
)
Updates the tags for an ECR Resource.
An update can either append or overwrite the existing tags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*tags
|
ResourceTag
|
Resource tags to update. |
()
|
mode
|
TagMode
|
Either append or overwrite tags of resource. Defaults to TagMode.APPEND. |
cast(TagMode, APPEND)
|
Source code in src/aibs_informatics_aws_utils/ecr/core.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | |
resolve_image_uri ¶
resolve_image_uri(name, default_tag=None)
Resolve full image URI from input name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Partial or fully qualified uri, name of image or repository. |
required |
default_tag
|
Optional[str]
|
Default tag to use if not specified. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Fully qualified image URI. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 | |