From b0324301607f8629fa258fa6ebd529964984a2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Markus=20Kristiansen=20Tern=C3=B8?= Date: Fri, 3 Jun 2022 13:11:37 +0200 Subject: [PATCH 01/16] add `Dockerfile` to source upload if context is local directory --- .../azure/cli/command_modules/acr/_utils.py | 27 +++++++++++++++++-- .../azure/cli/command_modules/acr/task.py | 9 ++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index 152065e4960..847be062c9e 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -405,7 +405,12 @@ def get_task_id_from_task_name(cli_ctx, resource_group, registry_name, task_name ) -def prepare_source_location(cmd, source_location, client_registries, registry_name, resource_group_name): +def prepare_source_location(cmd, + source_location, + docker_file_path, + client_registries, + registry_name, + resource_group_name): if not source_location or source_location.lower() == ACR_NULL_CONTEXT: source_location = None elif os.path.exists(source_location): @@ -413,13 +418,26 @@ def prepare_source_location(cmd, source_location, client_registries, registry_na raise CLIError( "Source location should be a local directory path or remote URL.") + # NOTE: If docker_file_path is not specified, the default is Dockerfile in source_location. + # Otherwise, it's based on current working directory. + if not docker_file_path: + docker_file_path = os.path.join(source_location, "Dockerfile") + logger.info("'--file or -f' is not provided. '%s' is used.", docker_file_path) + + _check_local_docker_file(docker_file_path) + tar_file_path = os.path.join(tempfile.gettempdir( ), 'cli_source_archive_{}.tar.gz'.format(uuid.uuid4().hex)) try: + # NOTE: os.path.basename is unable to parse "\" in the file path + original_docker_file_name = os.path.basename( + docker_file_path.replace("\\", "/")) + docker_file_in_tar = '{}_{}'.format( + uuid.uuid4().hex, original_docker_file_name) source_location = upload_source_code( cmd, client_registries, registry_name, resource_group_name, - source_location, tar_file_path, "", "") + source_location, tar_file_path, docker_file_path, docker_file_in_tar) except Exception as err: raise CLIError(err) finally: @@ -572,3 +590,8 @@ def get_task_details_by_name(cli_ctx, resource_group_name, registry_name, task_n from ._client_factory import cf_acr_tasks client = cf_acr_tasks(cli_ctx) return client.get_details(resource_group_name, registry_name, task_name) + + +def _check_local_docker_file(docker_file_path): + if not os.path.isfile(docker_file_path): + raise CLIError("Unable to find '{}'.".format(docker_file_path)) diff --git a/src/azure-cli/azure/cli/command_modules/acr/task.py b/src/azure-cli/azure/cli/command_modules/acr/task.py index 88142c3a599..3922b6e8699 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/task.py +++ b/src/azure-cli/azure/cli/command_modules/acr/task.py @@ -877,7 +877,14 @@ def acr_task_run(cmd, # pylint: disable=too-many-locals update_trigger_token = base64.b64encode(update_trigger_token.encode()).decode() task_id = get_task_id_from_task_name(cmd.cli_ctx, resource_group_name, registry_name, task_name) - context_path = prepare_source_location(cmd, context_path, client_registries, registry_name, resource_group_name) + context_path = prepare_source_location( + cmd, + context_path, + file, + client_registries, + registry_name, + resource_group_name + ) timeout = None task_details = get_task_details_by_name(cmd.cli_ctx, resource_group_name, registry_name, task_name) From d75f8c9c52100bb92277d547f1c5c777e1efed53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Markus=20Kristiansen=20Tern=C3=B8?= Date: Tue, 7 Jun 2022 08:27:59 +0200 Subject: [PATCH 02/16] check for optional local dockerfile --- .../azure/cli/command_modules/acr/_utils.py | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index 847be062c9e..9d500f3fe88 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -420,21 +420,28 @@ def prepare_source_location(cmd, # NOTE: If docker_file_path is not specified, the default is Dockerfile in source_location. # Otherwise, it's based on current working directory. - if not docker_file_path: + if docker_file_path: + _check_local_docker_file(docker_file_path) + else: docker_file_path = os.path.join(source_location, "Dockerfile") - logger.info("'--file or -f' is not provided. '%s' is used.", docker_file_path) - - _check_local_docker_file(docker_file_path) + if os.path.isfile(docker_file_path): + logger.info("'--file or -f' is not provided. '%s' is used.", docker_file_path) + else: + docker_file_path = "" tar_file_path = os.path.join(tempfile.gettempdir( ), 'cli_source_archive_{}.tar.gz'.format(uuid.uuid4().hex)) try: - # NOTE: os.path.basename is unable to parse "\" in the file path - original_docker_file_name = os.path.basename( - docker_file_path.replace("\\", "/")) - docker_file_in_tar = '{}_{}'.format( - uuid.uuid4().hex, original_docker_file_name) + if docker_file_path: + # NOTE: os.path.basename is unable to parse "\" in the file path + original_docker_file_name = os.path.basename( + docker_file_path.replace("\\", "/")) + docker_file_in_tar = '{}_{}'.format( + uuid.uuid4().hex, original_docker_file_name) + else: + docker_file_in_tar = "" + source_location = upload_source_code( cmd, client_registries, registry_name, resource_group_name, source_location, tar_file_path, docker_file_path, docker_file_in_tar) From 63b2626b81273d5a8be8f8f5f2031c213451e8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Markus=20Kristiansen=20Tern=C3=B8?= Date: Tue, 7 Jun 2022 08:31:10 +0200 Subject: [PATCH 03/16] change order of arguments --- src/azure-cli/azure/cli/command_modules/acr/_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index 9d500f3fe88..5133f1736b4 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -407,10 +407,10 @@ def get_task_id_from_task_name(cli_ctx, resource_group, registry_name, task_name def prepare_source_location(cmd, source_location, - docker_file_path, client_registries, registry_name, - resource_group_name): + resource_group_name, + docker_file_path): if not source_location or source_location.lower() == ACR_NULL_CONTEXT: source_location = None elif os.path.exists(source_location): From 788fdb58717e3376981e2d785d348bbb1307e8e4 Mon Sep 17 00:00:00 2001 From: "Magnus Longva (IT MSS LID)" Date: Tue, 7 Jun 2022 10:23:23 +0200 Subject: [PATCH 04/16] fixed prepare_source_location args --- src/azure-cli/azure/cli/command_modules/acr/pack.py | 2 +- src/azure-cli/azure/cli/command_modules/acr/run.py | 2 +- src/azure-cli/azure/cli/command_modules/acr/task.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/pack.py b/src/azure-cli/azure/cli/command_modules/acr/pack.py index d30ff81c7c9..b2d5c6cda0f 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/pack.py +++ b/src/azure-cli/azure/cli/command_modules/acr/pack.py @@ -49,7 +49,7 @@ def acr_pack_build(cmd, # pylint: disable=too-many-locals client_registries = cf_acr_registries_tasks(cmd.cli_ctx) source_location = prepare_source_location( - cmd, source_location, client_registries, registry_name, resource_group_name) + cmd, source_location, client_registries, registry_name, resource_group_name, None) if not source_location: raise CLIError('Building with Buildpacks requires a valid source location.') diff --git a/src/azure-cli/azure/cli/command_modules/acr/run.py b/src/azure-cli/azure/cli/command_modules/acr/run.py index 1c02bfaf11c..41269f64d8f 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/run.py +++ b/src/azure-cli/azure/cli/command_modules/acr/run.py @@ -53,7 +53,7 @@ def acr_run(cmd, # pylint: disable=too-many-locals client_registries = cf_acr_registries_tasks(cmd.cli_ctx) source_location = prepare_source_location( - cmd, source_location, client_registries, registry_name, resource_group_name) + cmd, source_location, client_registries, registry_name, resource_group_name, file) platform_os, platform_arch, platform_variant = get_validate_platform(cmd, platform) diff --git a/src/azure-cli/azure/cli/command_modules/acr/task.py b/src/azure-cli/azure/cli/command_modules/acr/task.py index 3922b6e8699..bb3a8416866 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/task.py +++ b/src/azure-cli/azure/cli/command_modules/acr/task.py @@ -880,10 +880,10 @@ def acr_task_run(cmd, # pylint: disable=too-many-locals context_path = prepare_source_location( cmd, context_path, - file, client_registries, registry_name, - resource_group_name + resource_group_name, + file ) timeout = None From 0cd346d151c0ec374755be296196deeb492248c5 Mon Sep 17 00:00:00 2001 From: "Magnus Longva (IT MSS LID)" Date: Tue, 7 Jun 2022 10:37:04 +0200 Subject: [PATCH 05/16] default to None --- src/azure-cli/azure/cli/command_modules/acr/_utils.py | 2 +- src/azure-cli/azure/cli/command_modules/acr/pack.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index 5133f1736b4..d1a56aa77b8 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -410,7 +410,7 @@ def prepare_source_location(cmd, client_registries, registry_name, resource_group_name, - docker_file_path): + docker_file_path=None): if not source_location or source_location.lower() == ACR_NULL_CONTEXT: source_location = None elif os.path.exists(source_location): diff --git a/src/azure-cli/azure/cli/command_modules/acr/pack.py b/src/azure-cli/azure/cli/command_modules/acr/pack.py index b2d5c6cda0f..d30ff81c7c9 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/pack.py +++ b/src/azure-cli/azure/cli/command_modules/acr/pack.py @@ -49,7 +49,7 @@ def acr_pack_build(cmd, # pylint: disable=too-many-locals client_registries = cf_acr_registries_tasks(cmd.cli_ctx) source_location = prepare_source_location( - cmd, source_location, client_registries, registry_name, resource_group_name, None) + cmd, source_location, client_registries, registry_name, resource_group_name) if not source_location: raise CLIError('Building with Buildpacks requires a valid source location.') From 2ae3263614da5a9d2a42e272f7de2273ecb93c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Markus=20Kristiansen=20Tern=C3=B8?= Date: Tue, 7 Jun 2022 11:14:15 +0200 Subject: [PATCH 06/16] check for yaml --- src/azure-cli/azure/cli/command_modules/acr/_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index d1a56aa77b8..4f8d6e1768d 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -421,7 +421,10 @@ def prepare_source_location(cmd, # NOTE: If docker_file_path is not specified, the default is Dockerfile in source_location. # Otherwise, it's based on current working directory. if docker_file_path: - _check_local_docker_file(docker_file_path) + if docker_file_path.endswith(('.yml', '.yaml')) or docker_file_path.startswith('-'): + docker_file_path = "" + else: + _check_local_docker_file(docker_file_path) else: docker_file_path = os.path.join(source_location, "Dockerfile") if os.path.isfile(docker_file_path): From bc8cd21ec78b0bf2db673956b2fbf5cb81844752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Markus=20Kristiansen=20Tern=C3=B8?= Date: Tue, 7 Jun 2022 11:14:58 +0200 Subject: [PATCH 07/16] dockerfile path relative to source path --- src/azure-cli/azure/cli/command_modules/acr/_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index 4f8d6e1768d..777057d8f12 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -424,7 +424,7 @@ def prepare_source_location(cmd, if docker_file_path.endswith(('.yml', '.yaml')) or docker_file_path.startswith('-'): docker_file_path = "" else: - _check_local_docker_file(docker_file_path) + _check_local_docker_file(os.path.join(source_location, docker_file_path)) else: docker_file_path = os.path.join(source_location, "Dockerfile") if os.path.isfile(docker_file_path): From cbe4bd8d42d3a02d8c08736af4e4a430823195ec Mon Sep 17 00:00:00 2001 From: "Magnus Longva (IT MSS LID)" Date: Tue, 7 Jun 2022 13:35:10 +0200 Subject: [PATCH 08/16] use ALLOWED_TASK_FILE_TYPES. move check dockerfile method --- .../azure/cli/command_modules/acr/_constants.py | 3 +++ .../azure/cli/command_modules/acr/_utils.py | 13 ++++++------- .../azure/cli/command_modules/acr/_validators.py | 5 +++++ src/azure-cli/azure/cli/command_modules/acr/task.py | 5 ++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_constants.py b/src/azure-cli/azure/cli/command_modules/acr/_constants.py index f2cd5c078f0..7f6d69c033c 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_constants.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_constants.py @@ -27,6 +27,9 @@ ACR_RUN_DEFAULT_TIMEOUT_IN_SEC = 60 * 60 # 60 minutes +ALLOWED_TASK_FILE_TYPES = ('.yaml', '.yml', '.toml', '.json', '.sh', '.bash', '.zsh', '.ps1', + '.ps', '.cmd', '.bat', '.ts', '.js', '.php', '.py', '.rb', '.lua') + def get_classic_sku(cmd): SkuName = cmd.get_models('SkuName') diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index 777057d8f12..01281efd48c 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -23,10 +23,13 @@ get_valid_os, get_valid_architecture, get_valid_variant, - ACR_NULL_CONTEXT + ACR_NULL_CONTEXT, + ALLOWED_TASK_FILE_TYPES ) from ._client_factory import cf_acr_registries +from ._validators import validate_docker_file_path + from ._archive_utils import upload_source_code, check_remote_source_code logger = get_logger(__name__) @@ -421,10 +424,10 @@ def prepare_source_location(cmd, # NOTE: If docker_file_path is not specified, the default is Dockerfile in source_location. # Otherwise, it's based on current working directory. if docker_file_path: - if docker_file_path.endswith(('.yml', '.yaml')) or docker_file_path.startswith('-'): + if docker_file_path.endswith(ALLOWED_TASK_FILE_TYPES): docker_file_path = "" else: - _check_local_docker_file(os.path.join(source_location, docker_file_path)) + validate_docker_file_path(os.path.join(source_location, docker_file_path)) else: docker_file_path = os.path.join(source_location, "Dockerfile") if os.path.isfile(docker_file_path): @@ -601,7 +604,3 @@ def get_task_details_by_name(cli_ctx, resource_group_name, registry_name, task_n client = cf_acr_tasks(cli_ctx) return client.get_details(resource_group_name, registry_name, task_name) - -def _check_local_docker_file(docker_file_path): - if not os.path.isfile(docker_file_path): - raise CLIError("Unable to find '{}'.".format(docker_file_path)) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_validators.py b/src/azure-cli/azure/cli/command_modules/acr/_validators.py index f2e26265f29..9111f161d20 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_validators.py @@ -140,3 +140,8 @@ def validate_repository(namespace): if ':' in namespace.repository: raise InvalidArgumentValueError("Parameter 'name' refers to a repository and" " should not include a tag or digest.") + + +def validate_docker_file_path(docker_file_path): + if not os.path.isfile(docker_file_path): + raise CLIError("Unable to find '{}'.".format(docker_file_path)) diff --git a/src/azure-cli/azure/cli/command_modules/acr/task.py b/src/azure-cli/azure/cli/command_modules/acr/task.py index bb3a8416866..cc7ca39bdd2 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/task.py +++ b/src/azure-cli/azure/cli/command_modules/acr/task.py @@ -26,7 +26,8 @@ from ._constants import ( ACR_NULL_CONTEXT, ACR_TASK_QUICKTASK, - ACR_RUN_DEFAULT_TIMEOUT_IN_SEC + ACR_RUN_DEFAULT_TIMEOUT_IN_SEC, + ALLOWED_TASK_FILE_TYPES ) logger = get_logger(__name__) @@ -37,8 +38,6 @@ IDENTITY_LOCAL_ID = '[system]' IDENTITY_GLOBAL_REMOVE = '[all]' DEFAULT_CPU = 2 -ALLOWED_TASK_FILE_TYPES = ('.yaml', '.yml', '.toml', '.json', '.sh', '.bash', '.zsh', '.ps1', - '.ps', '.cmd', '.bat', '.ts', '.js', '.php', '.py', '.rb', '.lua') def acr_task_create(cmd, # pylint: disable=too-many-locals From de6822085d9ef99f1c1f1f5038f4ee4f31be0226 Mon Sep 17 00:00:00 2001 From: "Magnus Longva (IT MSS LID)" Date: Tue, 7 Jun 2022 13:37:44 +0200 Subject: [PATCH 09/16] parse as task yaml if starts with - --- src/azure-cli/azure/cli/command_modules/acr/_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index 01281efd48c..1fae0989ba2 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -424,7 +424,7 @@ def prepare_source_location(cmd, # NOTE: If docker_file_path is not specified, the default is Dockerfile in source_location. # Otherwise, it's based on current working directory. if docker_file_path: - if docker_file_path.endswith(ALLOWED_TASK_FILE_TYPES): + if docker_file_path.endswith(ALLOWED_TASK_FILE_TYPES) or docker_file_path.startswith('-'): docker_file_path = "" else: validate_docker_file_path(os.path.join(source_location, docker_file_path)) From 7c9d789de16bb6565ca451d6e5f59447cf23c336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Markus=20Kristiansen=20Tern=C3=B8?= Date: Tue, 7 Jun 2022 13:48:20 +0200 Subject: [PATCH 10/16] remove trailing newline --- src/azure-cli/azure/cli/command_modules/acr/_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index 1fae0989ba2..f9f1032f90c 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -603,4 +603,3 @@ def get_task_details_by_name(cli_ctx, resource_group_name, registry_name, task_n from ._client_factory import cf_acr_tasks client = cf_acr_tasks(cli_ctx) return client.get_details(resource_group_name, registry_name, task_name) - From 1d92852f908563c8e47a94abe0c54aa670707908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Markus=20Kristiansen=20Tern=C3=B8?= Date: Wed, 8 Jun 2022 15:36:26 +0200 Subject: [PATCH 11/16] upload dockerfile with original basename --- src/azure-cli/azure/cli/command_modules/acr/_utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index f9f1032f90c..3264cb81ced 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -441,16 +441,14 @@ def prepare_source_location(cmd, try: if docker_file_path: # NOTE: os.path.basename is unable to parse "\" in the file path - original_docker_file_name = os.path.basename( + docker_file_name = os.path.basename( docker_file_path.replace("\\", "/")) - docker_file_in_tar = '{}_{}'.format( - uuid.uuid4().hex, original_docker_file_name) else: - docker_file_in_tar = "" + docker_file_name = "" source_location = upload_source_code( cmd, client_registries, registry_name, resource_group_name, - source_location, tar_file_path, docker_file_path, docker_file_in_tar) + source_location, tar_file_path, docker_file_path, docker_file_name) except Exception as err: raise CLIError(err) finally: From 520a85ba9432b68ad220b13f3048ed08425ca1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Markus=20Kristiansen=20Tern=C3=B8?= Date: Thu, 9 Jun 2022 09:54:17 +0200 Subject: [PATCH 12/16] fix prepare_source_location args --- src/azure-cli/azure/cli/command_modules/acr/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/run.py b/src/azure-cli/azure/cli/command_modules/acr/run.py index 41269f64d8f..1c02bfaf11c 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/run.py +++ b/src/azure-cli/azure/cli/command_modules/acr/run.py @@ -53,7 +53,7 @@ def acr_run(cmd, # pylint: disable=too-many-locals client_registries = cf_acr_registries_tasks(cmd.cli_ctx) source_location = prepare_source_location( - cmd, source_location, client_registries, registry_name, resource_group_name, file) + cmd, source_location, client_registries, registry_name, resource_group_name) platform_os, platform_arch, platform_variant = get_validate_platform(cmd, platform) From acf07a8f5e2633e239ad9d11dc73b86b11956646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Markus=20Kristiansen=20Tern=C3=B8?= Date: Thu, 9 Jun 2022 10:27:35 +0200 Subject: [PATCH 13/16] fix check for pipe arg --- src/azure-cli/azure/cli/command_modules/acr/_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_utils.py index 3264cb81ced..e78b48b7db1 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_utils.py @@ -424,7 +424,7 @@ def prepare_source_location(cmd, # NOTE: If docker_file_path is not specified, the default is Dockerfile in source_location. # Otherwise, it's based on current working directory. if docker_file_path: - if docker_file_path.endswith(ALLOWED_TASK_FILE_TYPES) or docker_file_path.startswith('-'): + if docker_file_path.endswith(ALLOWED_TASK_FILE_TYPES) or docker_file_path == "-": docker_file_path = "" else: validate_docker_file_path(os.path.join(source_location, docker_file_path)) From ecde2c2da1996fec5b27228787ae9d6525fe8625 Mon Sep 17 00:00:00 2001 From: oleterno-equinor Date: Tue, 28 Jun 2022 15:00:50 +0200 Subject: [PATCH 14/16] use `FileOperationError` error type instead of `CLIError` --- src/azure-cli/azure/cli/command_modules/acr/_validators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_validators.py b/src/azure-cli/azure/cli/command_modules/acr/_validators.py index 9111f161d20..bb9f8fd3ab4 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_validators.py @@ -6,7 +6,7 @@ import os from knack.util import CLIError from knack.log import get_logger -from azure.cli.core.azclierror import InvalidArgumentValueError +from azure.cli.core.azclierror import FileOperationError, InvalidArgumentValueError BAD_REPO_FQDN = "The positional parameter 'repo_id' must be a fully qualified repository specifier such"\ " as 'MyRegistry.azurecr.io/hello-world'." @@ -144,4 +144,4 @@ def validate_repository(namespace): def validate_docker_file_path(docker_file_path): if not os.path.isfile(docker_file_path): - raise CLIError("Unable to find '{}'.".format(docker_file_path)) + raise FileOperationError("Unable to find '{}'.".format(docker_file_path)) From a395578989a6cfd2bc6c58421425b424ae5c757e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Markus=20Kristiansen=20Tern=C3=B8?= <79976935+oleterno-equinor@users.noreply.github.com> Date: Wed, 29 Jun 2022 12:15:25 +0200 Subject: [PATCH 15/16] add test of local context task --- .../tests/latest/docker_context/.dockerignore | 1 + .../tests/latest/docker_context/Dockerfile | 9 +++++++++ .../acr/tests/latest/docker_context/task.yaml | 2 ++ .../tests/latest/test_acr_task_commands.py | 20 +++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/.dockerignore create mode 100644 src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/Dockerfile create mode 100644 src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/task.yaml diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/.dockerignore b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/.dockerignore new file mode 100644 index 00000000000..94143827ed0 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/.dockerignore @@ -0,0 +1 @@ +Dockerfile diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/Dockerfile b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/Dockerfile new file mode 100644 index 00000000000..2f8358a6712 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/Dockerfile @@ -0,0 +1,9 @@ +FROM busybox + +COPY . /build-context + +WORKDIR /build-context + +CMD find . + +RUN ls -la diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/task.yaml b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/task.yaml new file mode 100644 index 00000000000..795d9a656e1 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/task.yaml @@ -0,0 +1,2 @@ +steps: + - build: -t image:v1 -f Dockerfile . diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_task_commands.py b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_task_commands.py index b42a904cbe8..b51c24c99d7 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_task_commands.py +++ b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_task_commands.py @@ -15,10 +15,13 @@ def test_acr_task(self, resource_group): 'registry_name': self.create_random_name('clireg', 20), 'task_name': 'testTask', 'task_no_context': 'contextlessTask', + 'task_local_context': 'localContextTask', 'rg_loc': 'westus', 'sku': 'Standard', 'no_context': '/dev/null', 'context': 'https://github.com/SteveLasker/node-helloworld', + 'task_yaml': 'src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/task.yaml', + 'local_context': 'src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/', 'file': 'Dockerfile', 'image': 'testtask:v1', 'existing_image': 'bash', @@ -61,6 +64,18 @@ def test_acr_task(self, resource_group): self.check('status', 'Enabled'), self.check('timeout', 3600), self.check('step.type', 'EncodedTask')]) + + # Create a local context docker build task. + self.cmd('acr task create -n {task_local_context} -r {registry_name} --context {no_context} --file {task_yaml}', + checks=[self.check('name', '{task_local_context}'), + self.check('location', '{rg_loc}'), + self.check('platform.os', 'linux'), + self.check('agentConfiguration.cpu', 2), + self.check('provisioningState', 'Succeeded'), + self.check('status', 'Enabled'), + self.check('timeout', 3600), + self.check('step.type', 'EncodedTask')]) + # list tasks self.cmd('acr task list -r {registry_name}', checks=[self.check('[0].name', '{task_name}')]) @@ -70,6 +85,11 @@ def test_acr_task(self, resource_group): checks=[self.check('type', 'Microsoft.ContainerRegistry/registries/runs'), self.check('status', 'Succeeded')]).get_output_in_json() + # trigger a run for the local context task + response = self.cmd('acr task run -n {task_local_context} -r {registry_name} --context {local_context}', + checks=[self.check('type', 'Microsoft.ContainerRegistry/registries/runs'), + self.check('status', 'Succeeded')]).get_output_in_json() + # trigger a run from the task response = self.cmd('acr task run -n {task_name} -r {registry_name} --no-logs', checks=[self.check('type', 'Microsoft.ContainerRegistry/registries/runs'), From b68472b925d7adc39348904bda2d3a24021fa0e1 Mon Sep 17 00:00:00 2001 From: oleterno-equinor Date: Wed, 29 Jun 2022 13:37:22 +0200 Subject: [PATCH 16/16] remove failing test of task with local context --- .../tests/latest/docker_context/.dockerignore | 1 - .../tests/latest/docker_context/Dockerfile | 9 --------- .../acr/tests/latest/docker_context/task.yaml | 2 -- .../tests/latest/test_acr_task_commands.py | 20 ------------------- 4 files changed, 32 deletions(-) delete mode 100644 src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/.dockerignore delete mode 100644 src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/Dockerfile delete mode 100644 src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/task.yaml diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/.dockerignore b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/.dockerignore deleted file mode 100644 index 94143827ed0..00000000000 --- a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -Dockerfile diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/Dockerfile b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/Dockerfile deleted file mode 100644 index 2f8358a6712..00000000000 --- a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM busybox - -COPY . /build-context - -WORKDIR /build-context - -CMD find . - -RUN ls -la diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/task.yaml b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/task.yaml deleted file mode 100644 index 795d9a656e1..00000000000 --- a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/task.yaml +++ /dev/null @@ -1,2 +0,0 @@ -steps: - - build: -t image:v1 -f Dockerfile . diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_task_commands.py b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_task_commands.py index b51c24c99d7..b42a904cbe8 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_task_commands.py +++ b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_task_commands.py @@ -15,13 +15,10 @@ def test_acr_task(self, resource_group): 'registry_name': self.create_random_name('clireg', 20), 'task_name': 'testTask', 'task_no_context': 'contextlessTask', - 'task_local_context': 'localContextTask', 'rg_loc': 'westus', 'sku': 'Standard', 'no_context': '/dev/null', 'context': 'https://github.com/SteveLasker/node-helloworld', - 'task_yaml': 'src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/task.yaml', - 'local_context': 'src/azure-cli/azure/cli/command_modules/acr/tests/latest/docker_context/', 'file': 'Dockerfile', 'image': 'testtask:v1', 'existing_image': 'bash', @@ -64,18 +61,6 @@ def test_acr_task(self, resource_group): self.check('status', 'Enabled'), self.check('timeout', 3600), self.check('step.type', 'EncodedTask')]) - - # Create a local context docker build task. - self.cmd('acr task create -n {task_local_context} -r {registry_name} --context {no_context} --file {task_yaml}', - checks=[self.check('name', '{task_local_context}'), - self.check('location', '{rg_loc}'), - self.check('platform.os', 'linux'), - self.check('agentConfiguration.cpu', 2), - self.check('provisioningState', 'Succeeded'), - self.check('status', 'Enabled'), - self.check('timeout', 3600), - self.check('step.type', 'EncodedTask')]) - # list tasks self.cmd('acr task list -r {registry_name}', checks=[self.check('[0].name', '{task_name}')]) @@ -85,11 +70,6 @@ def test_acr_task(self, resource_group): checks=[self.check('type', 'Microsoft.ContainerRegistry/registries/runs'), self.check('status', 'Succeeded')]).get_output_in_json() - # trigger a run for the local context task - response = self.cmd('acr task run -n {task_local_context} -r {registry_name} --context {local_context}', - checks=[self.check('type', 'Microsoft.ContainerRegistry/registries/runs'), - self.check('status', 'Succeeded')]).get_output_in_json() - # trigger a run from the task response = self.cmd('acr task run -n {task_name} -r {registry_name} --no-logs', checks=[self.check('type', 'Microsoft.ContainerRegistry/registries/runs'),