Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/acrregionalendpoint/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. :changelog:

Release History
===============

1.0.0b1
+++++++
* Initial preview release for Azure Container Registry regional endpoints support.
* Add: `--regional-endpoints` parameter to `az acr create` and `az acr update` commands to enable regional endpoint functionality.
* Add: `--endpoint` parameter to `az acr login` command to authenticate against a specific regional endpoint.
* Add: Enhanced `az acr show` command to display `regionalEndpoints` and `regionalEndpointHostNames` properties in registry information.
* Add: Enhanced `az acr show-endpoints` command to display comprehensive endpoint information including registry login server, data endpoints, and regional endpoints.
* Add: Enhanced `az acr import` command to automatically detect and handle regional endpoint URIs in source image specifications.
103 changes: 103 additions & 0 deletions src/acrregionalendpoint/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
Microsoft Azure CLI 'acrregionalendpoint' Extension
==========================================

The 'acrregionalendpoint' extension is for private preview of an Azure Container Registry feature "Regional Endpoint".

Installation
------------

Install the extension using the Azure CLI:

.. code-block:: bash

az extension add --source <path-to-acrregionalendpoint-extension> --allow-preview true

Usage
-----

This extension enhances Azure Container Registry commands with regional endpoint support:

**az acr create**

Create a registry with regional endpoints enabled:

.. code-block:: bash

az acr create --resource-group myResourceGroup --name myRegistry --sku Premium --location westus --regional-endpoints enabled

**az acr update**

Enable or disable regional endpoints on an existing registry:

.. code-block:: bash

# Enable regional endpoints
az acr update --name myRegistry --regional-endpoints enabled

# Disable regional endpoints
az acr update --name myRegistry --regional-endpoints disabled

**az acr login**

Log in to an Azure Container Registry through the Docker CLI:

.. code-block:: bash

# Login to main endpoint (default)
az acr login --name myRegistry

# Login to the specific regional endpoint
az acr login --name myRegistry --endpoint eastus

**az acr import**

Import images using regional endpoint URIs:

.. code-block:: bash

# Import from regional endpoint
az acr import --name myTargetRegistry --source mySourceRegistry.eastus.geo.azurecr.io/myimage:latest

# Import using registry parameter with regional endpoint
az acr import --name myTargetRegistry --source myimage:latest --registry mySourceRegistry.eastus.geo.azurecr.io

**az acr show-endpoints**

Display available endpoints for a registry:

.. code-block:: bash

az acr show-endpoints --name myRegistry

Example output when regional endpoints are enabled:

.. code-block:: json

{
"dataEndpoints": [
{
"endpoint": "myregistry.eastus.data.azurecr.io",
"region": "eastus"
}
],
"loginServer": "myregistry.azurecr.io",
"regionalEndpoints": [
{
"endpoint": "myregistry.eastus.geo.azurecr.io",
"region": "eastus"
}
]
}

Requirements
------------

* Regional endpoints require **Premium SKU**
* Regional endpoints cannot be used with Docker Content Trust (DCT)
* Subscription must be registered for the **RegionalEndpoints** feature flag

Notes
-----

* When enabling regional endpoints, it's recommended to also enable data endpoints (``--data-endpoint-enabled``) for optimal performance
* Regional endpoint URIs follow the format: ``registryname.region.geo.azurecr.io``
38 changes: 38 additions & 0 deletions src/acrregionalendpoint/azext_acrregionalendpoint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from azure.cli.core.profiles import ResourceType


class AcrregionalendpointCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
super(AcrregionalendpointCommandsLoader, self).__init__(
cli_ctx=cli_ctx,
resource_type=ResourceType.MGMT_CONTAINERREGISTRY,
operation_group="registries")

def load_command_table(self, args):
# Load commands from Azure CLI command
from azure.cli.command_modules.acr.commands import load_command_table
load_command_table(self, args)
# Load extra commands for Regional Endpoint Feature
from azext_acrregionalendpoint.commands import load_command_table_preview
load_command_table_preview(self, args)
# Load help entries for Regional Endpoint Feature (must be after core module load to override)
import azext_acrregionalendpoint._help # pylint: disable=unused-import
return self.command_table

def load_arguments(self, command):
# Load arguments from Azure CLI command
from azure.cli.command_modules.acr._params import load_arguments
load_arguments(self, command)
# Load extra arguments for Regional Endpoint Feature
from azext_acrregionalendpoint._params import load_arguments_preview
load_arguments_preview(self, command)


COMMAND_LOADER_CLS = AcrregionalendpointCommandsLoader
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

def cf_acrregionalendpoint(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from .vendored_sdks.containerregistry import ContainerRegistryManagementClient
return get_mgmt_service_client(cli_ctx, ContainerRegistryManagementClient).registries
90 changes: 90 additions & 0 deletions src/acrregionalendpoint/azext_acrregionalendpoint/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# coding=utf-8
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.help_files import helps # pylint: disable=unused-import

helps['acr create'] = """
type: command
short-summary: Create an Azure Container Registry.
examples:
- name: Create a managed container registry with the Standard SKU.
Comment thread
lizMSFT marked this conversation as resolved.
text: >
az acr create -n myregistry -g MyResourceGroup --sku Standard
- name: Create a registry with ABAC-based Repository Permission enabled.
text: >
az acr create -n myregistry -g MyResourceGroup --sku Standard --role-assignment-mode rbac-abac
- name: Create a managed container registry with the Premium SKU and regional endpoints enabled.
text: >
az acr create -n myregistry -g MyResourceGroup --sku Premium --regional-endpoints enabled
"""

helps['acr update'] = """
type: command
short-summary: Update an Azure Container Registry.
examples:
- name: Update tags for an Azure Container Registry.
text: >
az acr update -n myregistry --tags key1=value1 key2=value2
- name: Enable the administrator user account for an Azure Container Registry.
text: >
az acr update -n myregistry --admin-enabled true
- name: Turn on ABAC-based Repository Permission on an existing registry.
text: >
az acr update -n myregistry --role-assignment-mode rbac-abac
- name: Enable regional endpoints on an existing registry.
text: >
az acr update -n myregistry --regional-endpoints enabled
"""

helps['acr login'] = """
type: command
short-summary: Log in to an Azure Container Registry through the Docker CLI.
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')
examples:
- name: Log in to an Azure Container Registry
text: >
az acr login -n myregistry
- name: Get an Azure Container Registry access token
text: >
az acr login -n myregistry --expose-token
- name: Log in to a specific regional endpoint of an Azure Container Registry
text: >
az acr login -n myregistry --endpoint eastus
"""
Comment thread
lizMSFT marked this conversation as resolved.

helps['acr show-endpoints'] = """
type: command
short-summary: Display registry endpoints including data endpoints and regional endpoints if configured.
examples:
- name: Show the endpoints for a registry.
text: >
az acr show-endpoints -n myregistry
"""
Comment thread
lizMSFT marked this conversation as resolved.

helps['acr import'] = """
type: command
short-summary: Imports an image to an Azure Container Registry from another Container Registry. Import removes the need to docker pull, docker tag, docker push. For larger images consider using `--no-wait`.
examples:
- name: Import an image from 'sourceregistry' to 'myregistry'. The image inherits its source repository and tag names.
text: >
az acr import -n myregistry --source sourceregistry.azurecr.io/sourcerepository:sourcetag
- name: Import an image from a public repository on Docker Hub. The image uses the specified repository and tag names.
text: >
az acr import -n myregistry --source docker.io/library/hello-world:latest -t targetrepository:targettag
- name: Import an image from a private repository using its username and password. This also applies to registries outside Azure.
text: >
az acr import -n myregistry --source myprivateregistry.azurecr.io/hello-world:latest -u username -p password
- name: Import an image from an Azure container registry in a different subscription.
text: |
az acr import -n myregistry --source sourcerepository:sourcetag -t targetrepository:targettag \\
-r /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/sourceResourceGroup/providers/Microsoft.ContainerRegistry/registries/sourceRegistry
- name: Import an image without waiting for successful completion. Failures during import will not be reflected. Run `az acr repository show-tags` to confirm that import succeeded.
text: >
az acr import -n myregistry --source sourceregistry.azurecr.io/sourcerepository:sourcetag --no-wait
- name: Import an image using a regional endpoint URI as the source.
text: >
az acr import -n myregistry --source sourceregistry.eastus.geo.azurecr.io/sourcerepository:sourcetag
"""
38 changes: 38 additions & 0 deletions src/acrregionalendpoint/azext_acrregionalendpoint/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long

from azure.cli.core.commands.parameters import (
get_enum_type, get_location_completion_list, get_location_name_type
)
from .vendored_sdks.containerregistry.models import RegionalEndpoints


def load_arguments_preview(self, _):
with self.argument_context("acr create") as c:
c.argument(
"regional_endpoints",
arg_type=get_enum_type(RegionalEndpoints),
is_preview=True,
help="Indicates whether or not regional endpoints should be enabled for the registry. If not specified, this is set to disabled by default.",
)

with self.argument_context("acr update") as c:
c.argument(
"regional_endpoints",
arg_type=get_enum_type(RegionalEndpoints),
is_preview=True,
help="Indicates whether or not regional endpoints should be enabled for the registry. If not specified, this is set to disabled by default.",
)
Comment thread
lizMSFT marked this conversation as resolved.

with self.argument_context("acr login") as c:
c.argument(
"endpoint",
completer=get_location_completion_list,
type=get_location_name_type(self.cli_ctx),
is_preview=True,
help="Log in to a specific regional endpoint of the container registry. Specify the region name "
Comment thread
lizMSFT marked this conversation as resolved.
"(e.g., eastus, westus2). Only applicable when regional endpoints are enabled."
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.74.0"
}
43 changes: 43 additions & 0 deletions src/acrregionalendpoint/azext_acrregionalendpoint/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands import CliCommandType
from azure.cli.command_modules.acr._client_factory import cf_acr_registries
from azure.cli.command_modules.acr._format import endpoints_output_format, registry_output_format
from azext_acrregionalendpoint._client_factory import cf_acrregionalendpoint


def load_command_table_preview(self, _):
acr_custom_util = CliCommandType(
operations_tmpl='azext_acrregionalendpoint.custom#{}',
table_transformer=registry_output_format,
client_factory=cf_acrregionalendpoint
)

acr_login_util = CliCommandType(
operations_tmpl='azext_acrregionalendpoint.custom#{}'
)

acr_import_util = CliCommandType(
operations_tmpl='azext_acrregionalendpoint.import#{}',
client_factory=cf_acr_registries
)

with self.command_group('acr', acr_custom_util) as g:
g.command('create', 'acr_create_preview')
g.show_command('show', 'acr_show_preview')
g.generic_update_command('update',
getter_name='acr_update_get_preview',
setter_name='acr_update_set_preview',
custom_func_name='acr_update_custom_preview',
custom_func_type=acr_custom_util,
client_factory=cf_acrregionalendpoint)
g.command('show-endpoints', 'acr_show_endpoints_preview', table_transformer=endpoints_output_format)

with self.command_group('acr', acr_login_util) as g:
g.command('login', 'acr_login_preview')

with self.command_group('acr', acr_import_util) as g:
g.command('import', 'acr_import_preview', supports_no_wait=True)
Loading
Loading