Skip to content

Commit d121af6

Browse files
authored
[ACR] Add OCI Artifact Source Context (#14576)
1 parent 442bef5 commit d121af6

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/azure-cli/azure/cli/command_modules/acr/_archive_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,8 @@ def check_remote_source_code(source_location):
218218
if requests.head(source_location).status_code < 400:
219219
return source_location
220220
raise CLIError("'{}' doesn't exist.".format(source_location))
221+
222+
# oci
223+
if lower_source_location.startswith("oci://"):
224+
return source_location
221225
raise CLIError("'{}' doesn't exist.".format(source_location))

src/azure-cli/azure/cli/command_modules/acr/_help.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
- name: Queue a remote GitHub context as a Windows build, tag it, and push it to the registry.
3232
text: >
3333
az acr build -r MyRegistry https://github.com/Azure/acr-builder.git -f Windows.Dockerfile --platform windows
34+
- name: Queue a remote OCI Artifact context build.
35+
text: >
36+
az acr build -r MyRegistry oci://myregistry.azurecr.io/myartifact:mytag
3437
- name: Queue a local context as a Linux build on arm/v7 architecture, tag it, and push it to the registry.
3538
text: >
3639
az acr build -t sample/hello-world:{{.Run.ID}} -r MyRegistry . --platform linux/arm/v7
@@ -508,6 +511,9 @@
508511
- name: Queue a remote git context with streaming logs and runs the task on Linux platform.
509512
text: >
510513
az acr run -r MyRegistry https://github.com/Azure-Samples/acr-tasks.git -f build-hello-world.yaml --platform linux
514+
- name: Queue a remote OCI Artifact context and runs the task.
515+
text: >
516+
az acr run -r MyRegistry oci://myregistry.azurecr.io/myartifact:mytag -f hello-world.yaml
511517
"""
512518

513519
helps['acr scope-map'] = """

src/azure-cli/azure/cli/command_modules/acr/_params.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
166166

167167
with self.argument_context('acr run') as c:
168168
c.argument('registry_name', options_list=['--registry', '-r'])
169-
c.positional('source_location', help="The local source code directory path (e.g., './src') or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz'). If '/dev/null' is specified, the value will be set to None and ignored.", completer=FilesCompleter())
169+
c.positional('source_location', help="The local source code directory path (e.g., './src'), or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git'), or a remote tarball (e.g., 'http://server/context.tar.gz'), or the repository of an OCI artifact in an Azure container registry (e.g., 'oci://myregistry.azurecr.io/myartifact:mytag'). If '/dev/null' is specified, the value will be set to None and ignored.", completer=FilesCompleter())
170170
c.argument('file', options_list=['--file', '-f'], help="The task template/definition file path relative to the source context. It can be '-' to pipe a file from the standard input.")
171171
c.argument('values', help="The task values file path relative to the source context.")
172172
c.argument('set_value', options_list=['--set'], help="Value in 'name[=value]' format. Multiples supported by passing --set multiple times.", action='append', validator=validate_set)
@@ -179,12 +179,12 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
179179
c.argument('builder', options_list=['--builder', '-b'], help="The name and tag of a Buildpack builder image.")
180180
c.argument('pack_image_tag', options_list=['--pack-image-tag'], help="The tag of the 'pack' runner image ('mcr.microsoft.com/oryx/pack').", is_preview=True)
181181
c.argument('pull', options_list=['--pull'], help="Pull the latest builder and run images before use.", action='store_true')
182-
c.positional('source_location', help="The local source code directory path (e.g., './src') or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz').", completer=FilesCompleter())
182+
c.positional('source_location', help="The local source code directory path (e.g., './src'), or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz'), or the repository of an OCI artifact in an Azure container registry (e.g., 'oci://myregistry.azurecr.io/myartifact:mytag').", completer=FilesCompleter())
183183
c.argument('agent_pool_name', options_list=['--agent-pool'], help='The name of the agent pool.', is_preview=True)
184184

185185
with self.argument_context('acr build') as c:
186186
c.argument('registry_name', options_list=['--registry', '-r'])
187-
c.positional('source_location', help="The local source code directory path (e.g., './src') or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz').", completer=FilesCompleter())
187+
c.positional('source_location', help="The local source code directory path (e.g., './src'), or the URL to a git repository (e.g., 'https://github.com/Azure-Samples/acr-build-helloworld-node.git') or a remote tarball (e.g., 'http://server/context.tar.gz'), or the repository of an OCI artifact in an Azure container registry (e.g., 'oci://myregistry.azurecr.io/myartifact:mytag').", completer=FilesCompleter())
188188
c.argument('no_push', help="Indicates whether the image built should be pushed to the registry.", action='store_true')
189189
c.argument('no_wait', help="Do not wait for the build to complete and return immediately after queuing the build.", action='store_true')
190190
c.argument('arg', options_list=['--build-arg'], help="Build argument in '--build-arg name[=value]' format. Multiples supported by passing --build-arg multiple times.", action='append', validator=validate_arg)
@@ -205,7 +205,7 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
205205
c.argument('values', help="The task values/parameters file path relative to the source context.")
206206

207207
# common to DockerBuildStep, FileTaskStep and RunTaskStep
208-
c.argument('context_path', options_list=['--context', '-c'], help="The full URL to the source code repository (Requires '.git' suffix for a github repo). If '/dev/null' is specified, the value will be set to None and ignored.")
208+
c.argument('context_path', options_list=['--context', '-c'], help="The full URL to the source code repository (Requires '.git' suffix for a github repo) or the repository of an OCI artifact in an Azure container registry (e.g., 'oci://myregistry.azurecr.io/myartifact:mytag'). If '/dev/null' is specified, the value will be set to None and ignored.")
209209
c.argument('arg', help="Build argument in '--arg name[=value]' format. Multiples supported by passing '--arg` multiple times.", action='append', validator=validate_arg)
210210
c.argument('secret_arg', help="Secret build argument in '--secret-arg name[=value]' format. Multiples supported by passing --secret-arg multiple times.", action='append', validator=validate_secret_arg)
211211
c.argument('set_value', options_list=['--set'], help="Task value in '--set name[=value]' format. Multiples supported by passing --set multiple times.", action='append', validator=validate_set)

src/azure-cli/azure/cli/command_modules/acr/task.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ def acr_task_create(cmd, # pylint: disable=too-many-locals
8282
commit_trigger_enabled = False
8383
pull_request_trigger_enabled = False
8484

85+
if context_path is not None and context_path.lower().startswith("oci://"):
86+
commit_trigger_enabled = False
87+
pull_request_trigger_enabled = False
88+
8589
if (commit_trigger_enabled or pull_request_trigger_enabled) and not git_access_token:
8690
raise CLIError("If source control trigger is enabled [--commit-trigger-enabled] or "
8791
"[--pull-request-trigger-enabled] --git-access-token must be provided.")

0 commit comments

Comments
 (0)