ECR¶
Utilities for working with Amazon Elastic Container Registry.
Overview¶
| Module | Description |
|---|---|
| Core | Core ECR utilities |
| Image Replicator | Container image replication |
ECRImage ¶
ECRImage(
*,
account_id,
region,
repository_name,
image_digest,
image_manifest=None,
client=None
)
Bases: ECRResourceBase
Source code in src/aibs_informatics_aws_utils/ecr/core.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
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
523 524 525 526 527 528 529 530 531 | |
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
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | |
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
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
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
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
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
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
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
|
str | None
|
Tag to associate with image. If None, image is untagged. |
required |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
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
|
list[str] | None
|
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
125 126 127 128 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 | |
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
|
list[str] | None
|
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
43 44 45 46 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 | |
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
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
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
|
str | None
|
Tag associated with image. Defaults to None. |
None
|
image_digest
|
str | None
|
The image digest. Defaults to None. |
None
|
account_id
|
str | None
|
The registry ID. Defaults to None. |
None
|
region
|
str | None
|
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
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 | |
ECRRegistry ¶
ECRRegistry(client=None, **data)
Bases: ECRResource
Source code in src/aibs_informatics_aws_utils/ecr/core.py
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
|
str | Pattern | None
|
Repository name or pattern to filter by. |
None
|
repository_tags
|
list[ResourceTag] | None
|
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
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 | |
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
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 | |
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
|
str | None
|
The registry ID. Defaults to None. |
None
|
region
|
str | None
|
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
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
ECRRepository ¶
ECRRepository(client=None, **data)
Bases: ECRResource
Source code in src/aibs_informatics_aws_utils/ecr/core.py
323 324 325 | |
create ¶
create(
tags=None,
image_tag_mutability="MUTABLE",
exists_ok=True,
)
Create an ECR Repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tags
|
list[ResourceTag] | None
|
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
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
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
746 747 748 749 750 751 752 753 754 | |
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
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 | |
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
|
str | None
|
Image tag. Defaults to None. |
None
|
image_digest
|
str | None
|
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
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 | |
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
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 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
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
|
str | None
|
The registry ID. Defaults to None. |
None
|
region
|
str | None
|
AWS region. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
ECRRepositoryUri
|
AWS Repository URI. |
Source code in src/aibs_informatics_aws_utils/ecr/core.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
ECRResource ¶
ECRResource(client=None, **data)
Bases: ECRResourceBase
Source code in src/aibs_informatics_aws_utils/ecr/core.py
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
635 636 637 638 639 640 641 642 643 644 645 | |
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
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
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
|
str | None
|
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
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 | |