Image import handles more scenarios#152
Conversation
Merge changes from upstream
* Add support for image import * Enable image import commands * Enable Image Import Commands * Error handling * Rewrite acr_image_import + Help messages * Image import without support of docker hub and cross-subscription registires * Listify tags and repository arguments for image import * Support import image cross subscription * Help message for arguments
ee791f7 to
c409f36
Compare
| c.argument('source_image', help='A fully qualified image identifier.') | ||
| c.argument('tags', nargs='+', options_list=['--image', '-t'], help="Space-separated list of images in the 'repository:tag' format where tag is optional.") | ||
| c.argument('repository', nargs='+', help='Space-separared list of image repository without tag to do a manifest only copy.') | ||
| c.argument('target', options_list=['--image', '-t'], help="The image repository and optionally a tag in the 'repository:tag' format where tag is optional.", action='append') |
There was a problem hiding this comment.
You can just use target_tags from the SDK since there is an options_list to override it.
There was a problem hiding this comment.
The help doesn't read right. Can you reuse the same help from build-task --image?
|
|
||
| IMPORT_NOT_SUPPORTED = "Image imports are only supported for managed registries." | ||
| INVALID_SOURCE_IMAGE = "Please specify source image in the form of 'regsitry.azurecr.io/repository[:tag]'." | ||
| INVALID_SOURCE_IMAGE = "Please specify source image in the form of 'registry.azurecr.io/repository[:tag]" |
| IMPORT_NOT_SUPPORTED = "Image imports are only supported for managed registries." | ||
| INVALID_SOURCE_IMAGE = "Please specify source image in the form of 'regsitry.azurecr.io/repository[:tag]'." | ||
| INVALID_SOURCE_IMAGE = "Please specify source image in the form of 'registry.azurecr.io/repository[:tag]" | ||
| SOURCE_REGISTRY_NOT_FOUND = "Source registry cannot be found in the current subscription. Please specify the full resource id for it:" |
| def acr_image_import(cmd, | ||
| client, | ||
| registry_name, | ||
| registry_name, |
| try: | ||
| resource_id = get_resource_id_by_registry_name(cmd.cli_ctx, source_registry) | ||
| except CLIError: | ||
| resource_id = input(SOURCE_REGISTRY_NOT_FOUND) |
| resource_id = get_resource_id_by_registry_name(cmd.cli_ctx, source_registry) | ||
| try: | ||
| resource_id = get_resource_id_by_registry_name(cmd.cli_ctx, source_registry) | ||
| except CLIError: |
There was a problem hiding this comment.
I guess you only want to catch when registry couldn't be found, but throw other errors out.
| c.argument('tags', nargs='+', options_list=['--image', '-t'], help="Space-separated list of images in the 'repository:tag' format where tag is optional.") | ||
| c.argument('repository', nargs='+', help='Space-separared list of image repository without tag to do a manifest only copy.') | ||
| c.argument('target_tags', options_list=['--image', '-t'], help="The image repository and optionally a tag in the 'repository:tag' format.", action='append') | ||
| c.argument('repository', help='The repository names to do a manifest only copy.', action='append') |
| result = list(result) | ||
|
|
||
| result = todict(result, AzCliCommandInvoker.remove_additional_prop_layer) | ||
| result = todict(result) |
There was a problem hiding this comment.
Revert this change, rebase from dev branch, create a new venv, run dev setup again, this problem should go away.
| text: > | ||
| az acr image import -n yugongTest --resource-id /subscriptions/dfb63c8c-7c89-4ef8-af13-75c1d873c895/resourceGroups/yugong/providers/Microsoft.ContainerRegistry/registries/yugongeast --source-image yugongeast.azurecr.io/builder:latest -t test:test . | ||
| az acr image import -n targetRegistry --resource-id /subscriptions/dfb63c8c-7c89-4ef8-af13-75c1d873c895/resourceGroups/yugong/providers/Microsoft.ContainerRegistry/registries/yugongeast --source-image yugongeast.azurecr.io/builder:latest | ||
| -t test:test |
There was a problem hiding this comment.
Replace your names with some common strings, also the sub id with empty guid, see other examples.
| resource_id = get_resource_id_by_registry_name(cmd.cli_ctx, source_registry) | ||
| source_image = source_image[slash + 1 :] | ||
| resource_id = get_resource_id_by_registry_name(cmd.cli_ctx, source_registry, SOURCE_REGISTRY_NOT_FOUND) | ||
| registry_name_from_resource_id = get_registry_name_by_resource_id( |
There was a problem hiding this comment.
Don't we already have registry name from source_registry?
| if tags is None and repository is None: | ||
| tags = [source_image] | ||
| image_source = ImportSource( | ||
| resource_id=resource_id, source_image=source_image) |
There was a problem hiding this comment.
Revert this line break. Line length max is 120.
| resource_id = get_resource_id_by_registry_name(cmd.cli_ctx, source_registry, SOURCE_REGISTRY_NOT_FOUND) | ||
| registry_name_from_resource_id = get_registry_name_by_resource_id( | ||
| resource_id) | ||
| if source_registry != registry_name_from_resource_id: |
There was a problem hiding this comment.
Not getting this condition. resource_id is obtained from source_registry, registry_name_from_resource_id is obtained from resource_id, shouldn't registry_name_from_resource_id always match source_registry?
|
|
||
| if not elements or len(elements) != 1: | ||
| try: | ||
| resource_id = prompt(msg) |
There was a problem hiding this comment.
This method would be confusing here, at least it shouldn't be in _utils as it won't be used by any other commands due to this special handling.
I would suggest that you do a get_resource_id_by_registry_name but instead of throwing, returning an empty result so you know the registry doesn't exist in the subscription.
| """Returns the resource ID for the container registry. | ||
| :param str login_server: The login server of the container registry. | ||
| """ | ||
| from .custom import acr_list |
There was a problem hiding this comment.
No need to import. Call client.list directly here.
| """ | ||
| from .custom import acr_list | ||
| registry_list = acr_list(client) | ||
| elements = [item for item in registry_list if item.login_server.lower() == login_server.lower()] |
There was a problem hiding this comment.
Create a var = login_server.lower() and reuse it, rather than calling lower() every time.
| elements = [item for item in registry_list if item.login_server.lower() == login_server.lower()] | ||
|
|
||
| if not elements or len(elements) != 1: | ||
| return "" |
There was a problem hiding this comment.
edit: rename this method to get_registry_by_login_server and return the Registry object if it exists in the current sub, None otherwise, so that this method can be generic enough to be used by others.
| @@ -1,54 +1,69 @@ | |||
| from knack.util import CLIError | |||
| from knack.prompting import prompt, NoTTYException | |||
There was a problem hiding this comment.
Move this line to where they are used for better perf.
|
|
||
| from azure.mgmt.containerregistry.v2017_10_01.models import SkuName, Sku | ||
|
|
||
| #from .custom import acr_list |
|
|
||
| if resource_id and resource_id_from_login_server and resource_id_from_login_server != resource_id: | ||
| raise CLIError("Registry mismatch. Please check either source-image or resource ID " \ | ||
| "to make sure that they are referring to the same registry and give another try.") |
* Enable Image Import Commands (#148) * Add support for image import * Enable image import commands * Enable Image Import Commands * Error handling * Rewrite acr_image_import + Help messages * Image import without support of docker hub and cross-subscription registires * Listify tags and repository arguments for image import * Support import image cross subscription * Help message for arguments * Enable Image Import Commands with Prompt for resource_id * Add help message * . * Move tty to _utils * Enable Image Import Commands with Prompt for resource_id * Add help message * . * Move tty to _utils * Move prompt out of _util * . * Validate using login server * . * .
* Enable Image Import Commands (#148) * Add support for image import * Enable image import commands * Enable Image Import Commands * Error handling * Rewrite acr_image_import + Help messages * Image import without support of docker hub and cross-subscription registires * Listify tags and repository arguments for image import * Support import image cross subscription * Help message for arguments * Enable Image Import Commands with Prompt for resource_id * Add help message * . * Move tty to _utils * Enable Image Import Commands with Prompt for resource_id * Add help message * . * Move tty to _utils * Move prompt out of _util * . * Validate using login server * . * .
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR has modified HISTORY.rst describing any customer-facing, functional changes. Note that this does not include changes only to help content. (see Modifying change log).
I adhere to the Command Guidelines.