Skip to content

Commit b11500c

Browse files
committed
[ACR] add new acrregionalendpoint extension for private preview of ACR Regional Endpoints feature
1 parent 65a33e1 commit b11500c

43 files changed

Lines changed: 35914 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. :changelog:
2+
3+
Release History
4+
===============
5+
6+
1.0.0
7+
++++++
8+
* Initial release.

src/acrregionalendpoint/README.rst

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
Microsoft Azure CLI 'acrregionalendpoint' Extension
2+
==========================================
3+
4+
The 'acrregionalendpoint' extension is for private preview of an Azure Container Registry feature "Regional Endpoint".
5+
6+
Installation
7+
------------
8+
9+
Install the extension using the Azure CLI:
10+
11+
.. code-block:: bash
12+
13+
az extension add --source <path-to-acrregionalendpoint-extension> --allow-preview true
14+
15+
Usage
16+
-----
17+
18+
This extension enhances Azure Container Registry commands with regional endpoint support:
19+
20+
**az acr create**
21+
22+
Create a registry with regional endpoints enabled:
23+
24+
.. code-block:: bash
25+
26+
az acr create --resource-group myResourceGroup --name myRegistry --sku Premium --location westus --enable-regional-endpoints true
27+
28+
**az acr update**
29+
30+
Enable or disable regional endpoints on an existing registry:
31+
32+
.. code-block:: bash
33+
34+
# Enable regional endpoints
35+
az acr update --name myRegistry --enable-regional-endpoints true
36+
37+
# Disable regional endpoints
38+
az acr update --name myRegistry --enable-regional-endpoints false
39+
40+
**az acr login**
41+
42+
Log in to an Azure Container Registry through the Docker CLI:
43+
44+
.. code-block:: bash
45+
46+
# Login to main endpoint (default)
47+
az acr login --name myRegistry
48+
49+
# Login to all endpoints (main + regional endpoints)
50+
az acr login --name myRegistry --all-endpoints
51+
52+
**az acr import**
53+
54+
Import images using regional endpoint URIs:
55+
56+
.. code-block:: bash
57+
58+
# Import from regional endpoint
59+
az acr import --name myTargetRegistry --source mySourceRegistry.eastus.geo.azurecr.io/myimage:latest
60+
61+
# Import using registry parameter with regional endpoint
62+
az acr import --name myTargetRegistry --source myimage:latest --registry mySourceRegistry.eastus.geo.azurecr.io
63+
64+
**az acr show-endpoints**
65+
66+
Display available endpoints for a registry:
67+
68+
.. code-block:: bash
69+
70+
az acr show-endpoints --name myRegistry
71+
72+
Example output when regional endpoints are enabled:
73+
74+
.. code-block:: json
75+
76+
{
77+
"dataEndpoints": [
78+
{
79+
"endpoint": "myregistry.eastus.data.azurecr.io",
80+
"region": "eastus"
81+
}
82+
],
83+
"loginServer": "myregistry.azurecr.io",
84+
"regionalEndpoints": [
85+
{
86+
"endpoint": "myregistry.eastus.geo.azurecr.io",
87+
"region": "eastus"
88+
}
89+
]
90+
}
91+
92+
Requirements
93+
------------
94+
95+
* Regional endpoints require **Premium SKU**
96+
* Regional endpoints cannot be used with Docker Content Trust (DCT)
97+
* Subscription must be registered for the Regional Endpoint feature flag
98+
99+
Notes
100+
-----
101+
102+
* When enabling regional endpoints, it's recommended to also enable data endpoints (``--data-endpoint-enabled``) for optimal performance
103+
* Regional endpoint URIs follow the format: ``registryname.region.geo.azurecr.io``
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
from azure.cli.core import AzCommandsLoader
7+
from azure.cli.core.profiles import ResourceType
8+
9+
10+
class AcrregionalendpointCommandsLoader(AzCommandsLoader):
11+
12+
def __init__(self, cli_ctx=None):
13+
super(AcrregionalendpointCommandsLoader, self).__init__(
14+
cli_ctx=cli_ctx,
15+
resource_type=ResourceType.MGMT_CONTAINERREGISTRY,
16+
operation_group="registries")
17+
18+
def load_command_table(self, args):
19+
# Load commands from Azure CLI command
20+
from azure.cli.command_modules.acr.commands import load_command_table
21+
load_command_table(self, args)
22+
# Load extra commands for Regional Endpoint Feature
23+
from azext_acrregionalendpoint.commands import load_command_table_preview
24+
load_command_table_preview(self, args)
25+
return self.command_table
26+
27+
def load_arguments(self, command):
28+
# Load arguments from Azure CLI command
29+
from azure.cli.command_modules.acr._params import load_arguments
30+
load_arguments(self, command)
31+
# Load extra arguments for Regional Endpoint Feature
32+
from azext_acrregionalendpoint._params import load_arguments_preview
33+
load_arguments_preview(self, command)
34+
35+
36+
COMMAND_LOADER_CLS = AcrregionalendpointCommandsLoader
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
def cf_acrregionalendpoint(cli_ctx, *_):
7+
from azure.cli.core.commands.client_factory import get_mgmt_service_client
8+
from .vendored_sdks.containerregistry import ContainerRegistryManagementClient
9+
return get_mgmt_service_client(cli_ctx, ContainerRegistryManagementClient).registries
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# --------------------------------------------------------------------------------------------
6+
7+
from knack.help_files import helps # pylint: disable=unused-import
8+
9+
helps['acr create'] = """
10+
type: command
11+
short-summary: Create an Azure Container Registry.
12+
examples:
13+
- name: Create a managed container registry with the Standard SKU.
14+
text: >
15+
az acr create -n myregistry -g MyResourceGroup --sku Standard
16+
- name: Create a registry with ABAC-based Repository Permission enabled.
17+
text: >
18+
az acr create -n myregistry -g MyResourceGroup --sku Standard --role-assignment-mode rbac-abac
19+
- name: Create a registry with regional endpoints enabled.
20+
text: >
21+
az acr create -n myregistry -g MyResourceGroup --sku Premium --enable-regional-endpoints true
22+
"""
23+
24+
helps['acr update'] = """
25+
type: command
26+
short-summary: Update an Azure Container Registry.
27+
examples:
28+
- name: Update tags for an Azure Container Registry.
29+
text: >
30+
az acr update -n myregistry --tags key1=value1 key2=value2
31+
- name: Enable the administrator user account for an Azure Container Registry.
32+
text: >
33+
az acr update -n myregistry --admin-enabled true
34+
- name: Turn on ABAC-based Repository Permission on an existing registry.
35+
text: >
36+
az acr update -n myregistry --role-assignment-mode rbac-abac
37+
- name: Enable regional endpoints on an existing registry.
38+
text: >
39+
az acr update -n myregistry --enable-regional-endpoints true
40+
"""
41+
42+
helps['acr login'] = """
43+
type: command
44+
short-summary: Log in to an Azure Container Registry through the Docker CLI.
45+
long-summary: Docker must be installed on your machine. Once done, use `docker logout <registry url>` to log out. (If you only need a refresh token and do not want to install Docker, specify '--expose-token')
46+
examples:
47+
- name: Log in to an Azure Container Registry
48+
text: >
49+
az acr login -n myregistry
50+
- name: Get an Azure Container Registry access token
51+
text: >
52+
az acr login -n myregistry --expose-token
53+
- name: Log in to all endpoints of an Azure Container Registry
54+
text: >
55+
az acr login -n myregistry --all-endpoints
56+
"""
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
# pylint: disable=line-too-long
6+
7+
from azure.cli.core.commands.parameters import get_three_state_flag
8+
9+
10+
def load_arguments_preview(self, _):
11+
with self.argument_context("acr create") as c:
12+
c.argument(
13+
"enable_regional_endpoints",
14+
arg_type=get_three_state_flag(),
15+
is_preview=True,
16+
help="Enable or disable regional endpoints for the registry.",
17+
)
18+
19+
with self.argument_context("acr update") as c:
20+
c.argument(
21+
"enable_regional_endpoints",
22+
arg_type=get_three_state_flag(),
23+
is_preview=True,
24+
help="Enable or disable regional endpoints for the registry.",
25+
)
26+
27+
with self.argument_context("acr login") as c:
28+
c.argument(
29+
"all_endpoints",
30+
action='store_true',
31+
is_preview=True,
32+
help="Enable login to all regional endpoints of the container registry."
33+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"azext.isPreview": true,
3+
"azext.minCliCoreVersion": "2.80.0"
4+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
from azure.cli.core.commands import CliCommandType
7+
from azure.cli.command_modules.acr._client_factory import cf_acr_registries
8+
from azure.cli.command_modules.acr._format import endpoints_output_format, registry_output_format
9+
from azext_acrregionalendpoint._client_factory import cf_acrregionalendpoint
10+
11+
12+
def load_command_table_preview(self, _):
13+
acr_custom_util = CliCommandType(
14+
operations_tmpl='azext_acrregionalendpoint.custom#{}',
15+
table_transformer=registry_output_format,
16+
client_factory=cf_acrregionalendpoint
17+
)
18+
19+
acr_login_util = CliCommandType(
20+
operations_tmpl='azext_acrregionalendpoint.custom#{}'
21+
)
22+
23+
acr_import_util = CliCommandType(
24+
operations_tmpl='azext_acrregionalendpoint.import#{}',
25+
client_factory=cf_acr_registries
26+
)
27+
28+
with self.command_group('acr', acr_custom_util) as g:
29+
g.command('create', 'acr_create_preview')
30+
g.show_command('show', 'acr_show_preview')
31+
g.generic_update_command('update',
32+
getter_name='acr_update_get_preview',
33+
setter_name='acr_update_set_preview',
34+
custom_func_name='acr_update_custom_preview',
35+
custom_func_type=acr_custom_util,
36+
client_factory=cf_acrregionalendpoint)
37+
g.command('show-endpoints', 'acr_show_endpoints_preview', table_transformer=endpoints_output_format)
38+
39+
with self.command_group('acr', acr_login_util) as g:
40+
g.command('login', 'acr_login_preview')
41+
42+
with self.command_group('acr', acr_import_util) as g:
43+
g.command('import', 'acr_import_preview', supports_no_wait=True)

0 commit comments

Comments
 (0)