Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ContainerApp] Cloud Build Bugfix - 500 Internal Server Error (Wrong env selected to create builder) #7024

Merged
merged 21 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 19 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
1 change: 1 addition & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release History
===============
upcoming
++++++
* 'az containerapp up': Cloud Build Bugfix - 500 Internal Server Error (Wrong env selected to create builder)

0.3.44
++++++
Expand Down
49 changes: 30 additions & 19 deletions src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
containerapp_up_logic,
list_containerapp,
list_managed_environments,
create_or_update_github_action,
create_or_update_github_action
)

from ._cloud_build_utils import (
Expand Down Expand Up @@ -884,22 +884,35 @@ def _get_dockerfile_content(repo, branch, token, source, context_path, dockerfil
def _get_app_env_and_group(
cmd, name, resource_group: "ResourceGroup", env: "ContainerAppEnvironment", location
):
matched_apps = []
# If no resource group is provided, we need to search for the app in all resource groups
if not resource_group.name and not resource_group.exists:
matched_apps = [c for c in list_containerapp(cmd) if c["name"].lower() == name.lower()]
if env.name:
matched_apps = [c for c in matched_apps if parse_resource_id(c["properties"]["environmentId"])["name"].lower() == env.name.lower()]
if location:
matched_apps = [c for c in matched_apps if format_location(c["location"]) == format_location(location)]
if len(matched_apps) == 1:
resource_group.name = parse_resource_id(matched_apps[0]["id"])[
"resource_group"
]
env.set_name(matched_apps[0]["properties"]["environmentId"])
elif len(matched_apps) > 1:
raise ValidationError(
f"There are multiple containerapps with name {name} on the subscription. "
"Please specify which resource group your Containerapp is in."
)

# If a resource group is provided, we need to search for the app in that resource group
if resource_group.name and resource_group.exists:
matched_apps = [c for c in list_containerapp(cmd, resource_group_name=resource_group.name) if c["name"].lower() == name.lower()]

# If env is provided, we need to search for the app in that env
if env.name:
matched_apps = [c for c in matched_apps if parse_resource_id(c["properties"]["environmentId"])["name"].lower() == env.name.lower()]

# If location is provided, we need to search for the app in that location
if location:
matched_apps = [c for c in matched_apps if format_location(c["location"]) == format_location(location)]

# If there is only one app that matches the criteria, we can set the env name and resource group name
if len(matched_apps) == 1:
resource_group.name = parse_resource_id(matched_apps[0]["id"])[
"resource_group"
]
env.set_name(matched_apps[0]["properties"]["environmentId"])
# If there are multiple apps that match the criteria, we need to ask the user to specify the env name and resource group name
elif len(matched_apps) > 1:
raise ValidationError(
f"There are multiple containerapps with name {name} on the subscription. "
"Please specify which resource group your Containerapp is in."
)


def _get_env_and_group_from_log_analytics(
Expand Down Expand Up @@ -1062,10 +1075,8 @@ def _set_up_defaults(
# If no RG passed in and a singular app exists with the same name, get its env and rg
_get_app_env_and_group(cmd, name, resource_group, env, location)

# If no env passed in (and not creating a new RG), then try getting an env by location / log analytics ID
_get_env_and_group_from_log_analytics(
cmd, resource_group_name, env, resource_group, logs_customer_id, location
)
# If no env passed or set in the previous step (and not creating a new RG), then get env by location from log analytics ID
_get_env_and_group_from_log_analytics(cmd, resource_group_name, env, resource_group, logs_customer_id, location)

# try to set RG name by env name
if env.name and not resource_group.name:
Expand Down
Loading
Loading