Skip to content

Commit b314ccd

Browse files
committed
Add --image and --entrypoint params to containerapp debug command
Allow customers to specify a custom container image and entrypoint for the debug ephemeral container via 'az containerapp debug'. - Add --image and --entrypoint optional parameters - Append customDebugImageName and customDebugImageEntrypointCommand query params to the debug URL when provided - Client-side validation: --entrypoint requires --image - Add help examples for the new parameters
1 parent 2e7ddd0 commit b314ccd

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/containerapp/azext_containerapp/_help.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,12 @@
24472447
- name: Debug by executing a command inside a container app and exit
24482448
text: |
24492449
az containerapp debug -n MyContainerapp -g MyResourceGroup --revision MyRevision --replica MyReplica --container MyContainer --command "echo Hello World"
2450+
- name: Debug with a custom container image
2451+
text: |
2452+
az containerapp debug -n MyContainerapp -g MyResourceGroup --container MyContainer --image mcr.microsoft.com/dotnet/sdk:8.0
2453+
- name: Debug with a custom container image and entrypoint
2454+
text: |
2455+
az containerapp debug -n MyContainerapp -g MyResourceGroup --container MyContainer --image mcr.microsoft.com/dotnet/sdk:8.0 --entrypoint /bin/bash
24502456
"""
24512457

24522458
helps['containerapp label-history'] = """

src/containerapp/azext_containerapp/_params.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,10 @@ def load_arguments(self, _):
515515
help="The name of the container app revision. Default to the latest revision.")
516516
c.argument('name', name_type, id_part=None, help="The name of the Containerapp.")
517517
c.argument('resource_group_name', arg_type=resource_group_name_type, id_part=None)
518+
c.argument('custom_debug_image_name', options_list=['--image'], is_preview=True,
519+
help="Custom container image for the debug ephemeral container (e.g., 'mcr.microsoft.com/dotnet/sdk:8.0'). If not specified, the platform default debug image is used.")
520+
c.argument('custom_debug_image_entrypoint_command', options_list=['--entrypoint'], is_preview=True,
521+
help="Custom entrypoint command for the debug container (e.g., '/bin/bash'). Requires --image to also be specified.")
518522

519523
with self.argument_context('containerapp label-history') as c:
520524
c.argument('resource_group_name', arg_type=resource_group_name_type, id_part=None)

src/containerapp/azext_containerapp/containerapp_debug_command_decorator.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def get_argument_container_name(self):
3939
def get_argument_command(self):
4040
return self.get_param("command")
4141

42+
def get_argument_custom_debug_image_name(self):
43+
return self.get_param("custom_debug_image_name")
44+
45+
def get_argument_custom_debug_image_entrypoint_command(self):
46+
return self.get_param("custom_debug_image_entrypoint_command")
47+
4248
def validate_arguments(self):
4349
validate_basic_arguments(
4450
resource_group_name=self.get_argument_resource_group_name(),
@@ -59,7 +65,7 @@ def _get_logstream_endpoint(self, cmd, resource_group_name, container_app_name,
5965
raise ValidationError(f"Error retrieving container in revision '{revision_name}' in the container app '{container_app_name}'.")
6066
return container_info[0]["logStreamEndpoint"]
6167

62-
def _get_url(self, cmd, resource_group_name, container_app_name, revision_name, replica_name, container_name, command):
68+
def _get_url(self, cmd, resource_group_name, container_app_name, revision_name, replica_name, container_name, command, custom_debug_image_name=None, custom_debug_image_entrypoint_command=None):
6369
"""Get the debug url for the specified container in the replica"""
6470
base_url = self._get_logstream_endpoint(cmd, resource_group_name, container_app_name, revision_name, replica_name, container_name)
6571
proxy_api_url = base_url[:base_url.index("/subscriptions/")]
@@ -68,6 +74,10 @@ def _get_url(self, cmd, resource_group_name, container_app_name, revision_name,
6874
debug_url = (f"{proxy_api_url}/subscriptions/{sub}/resourceGroups/{resource_group_name}/containerApps/{container_app_name}"
6975
f"/revisions/{revision_name}/replicas/{replica_name}/debug"
7076
f"?targetContainer={container_name}&command={encoded_cmd}")
77+
if custom_debug_image_name:
78+
debug_url += f"&customDebugImageName={urllib.parse.quote_plus(custom_debug_image_name)}"
79+
if custom_debug_image_entrypoint_command:
80+
debug_url += f"&customDebugImageEntrypointCommand={urllib.parse.quote_plus(custom_debug_image_entrypoint_command)}"
7181
return debug_url
7282

7383
def _get_auth_token(self, cmd, resource_group_name, container_app_name):
@@ -82,7 +92,11 @@ def execute_Command(self, cmd):
8292
replica_name = self.get_argument_replica_name()
8393
container_name = self.get_argument_container_name()
8494
command = self.get_argument_command()
85-
url = self._get_url(cmd, resource_group_name, container_app_name, revision_name, replica_name, container_name, command)
95+
custom_debug_image_name = self.get_argument_custom_debug_image_name()
96+
custom_debug_image_entrypoint_command = self.get_argument_custom_debug_image_entrypoint_command()
97+
if custom_debug_image_entrypoint_command and not custom_debug_image_name:
98+
raise ValidationError("--entrypoint requires --image to also be specified.")
99+
url = self._get_url(cmd, resource_group_name, container_app_name, revision_name, replica_name, container_name, command, custom_debug_image_name, custom_debug_image_entrypoint_command)
86100
token = self._get_auth_token(cmd, resource_group_name, container_app_name)
87101
headers = [f"Authorization=Bearer {token}"]
88102
r = send_raw_request(cmd.cli_ctx, "GET", url, headers=headers)

0 commit comments

Comments
 (0)