diff --git a/src/containerapp/azext_containerapp/_up_utils.py b/src/containerapp/azext_containerapp/_up_utils.py index da5b69b8cd4..487e5f40fbf 100644 --- a/src/containerapp/azext_containerapp/_up_utils.py +++ b/src/containerapp/azext_containerapp/_up_utils.py @@ -670,6 +670,18 @@ def _get_registry_details(cmd, app: "ContainerApp", source): ) +def _validate_containerapp_name(name): + is_valid = True + is_valid = is_valid and name.lower() == name + is_valid = is_valid and len(name) <= 32 + is_valid = is_valid and '--' not in name + name = name.replace('-', '') + is_valid = is_valid and name.isalnum() + is_valid = is_valid and name[0].isalpha() + if not is_valid: + raise ValidationError(f"Invalid Container App name {name}. A name must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character and cannot have '--'. The length must not be more than 32 characters.") + + # attempt to populate defaults for managed env, RG, ACR, etc def _set_up_defaults( cmd, diff --git a/src/containerapp/azext_containerapp/custom.py b/src/containerapp/azext_containerapp/custom.py index 4156ac049f8..641c2685d60 100644 --- a/src/containerapp/azext_containerapp/custom.py +++ b/src/containerapp/azext_containerapp/custom.py @@ -2288,11 +2288,13 @@ def containerapp_up(cmd, from ._up_utils import (_validate_up_args, _reformat_image, _get_dockerfile_content, _get_ingress_and_target_port, ResourceGroup, ContainerAppEnvironment, ContainerApp, _get_registry_from_app, _get_registry_details, _create_github_action, _set_up_defaults, up_output, - check_env_name_on_rg, get_token) + check_env_name_on_rg, get_token, _validate_containerapp_name) from ._github_oauth import cache_github_token HELLOWORLD = "mcr.microsoft.com/azuredocs/containerapps-helloworld" dockerfile = "Dockerfile" # for now the dockerfile name must be "Dockerfile" (until GH actions API is updated) + _validate_containerapp_name(name) + register_provider_if_needed(cmd, CONTAINER_APPS_RP) _validate_up_args(cmd, source, image, repo, registry_server) validate_container_app_name(name)