Skip to content

Commit

Permalink
Finished API change, added helloworld image auto ingress, checked pro…
Browse files Browse the repository at this point in the history
…visioning state beforehand.
  • Loading branch information
Haroon Feisal committed Apr 21, 2022
1 parent e886ea4 commit bfcace8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
24 changes: 10 additions & 14 deletions src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ def create_acr(self):

self.registry_user, self.registry_pass, _ = _get_acr_cred(self.cmd.cli_ctx, registry_name)

def run_acr_build(self, dockerfile, source):
def run_acr_build(self, dockerfile, source, quiet=False):
image_name = self.image if self.image is not None else self.name
from datetime import datetime
now = datetime.now()
# Add version tag for acr image
image_name += ":{}".format(str(now).replace(' ', '').replace('-', '').replace('.', '').replace(':', ''))

self.image = self.registry_server + '/' + image_name
queue_acr_build(self.cmd, self.acr.resource_group.name, self.acr.name, image_name, source, dockerfile, quiet=True)
queue_acr_build(self.cmd, self.acr.resource_group.name, self.acr.name, image_name, source, dockerfile, quiet)

def _create_service_principal(cmd, resource_group_name, env_resource_group_name):
logger.warning("No valid service principal provided. Creating a new service principal...")
Expand Down Expand Up @@ -417,8 +417,9 @@ def _get_registry_details(cmd, app: 'ContainerApp'):
else:
registry_rg = app.resource_group.name
user = get_profile_username()
registry_name = "{}acr".format(app.name).replace('-','')
registry_name = registry_name + str(hash((registry_rg, user, app.name))).replace("-", "")
registry_name = app.name.replace('-','')
registry_name = registry_name + str(hash((registry_rg, user, app.name))).replace("-", "")[:10]
registry_name = f"ca{registry_name}acr"
app.registry_server = registry_name + ".azurecr.io"
app.should_create_acr = True
app.acr = AzureContainerRegistry(registry_name, ResourceGroup(cmd, registry_rg, None, None))
Expand Down Expand Up @@ -474,13 +475,8 @@ def up_output(app):
"ingress", "fqdn")
if url and not url.startswith("http"):
url = f"http://{url}"
if url:
output = (f"\nYour container app ({app.name}) has been created a deployed! Congrats! \n\n"
f"Browse to your container app at: {url} \n\n"
f"Stream logs for your container with: az containerapp logs -n {app.name} -g {app.resource_group.name} \n\n"
f"See full output using: az containerapp show -n {app.name} -g {app.resource_group.name} \n")
else:
output = (f"\nYour container app ({app.name}) has been created a deployed! Congrats! \n\n"
f"Stream logs for your container with: az containerapp logs -n {app.name} -g {app.resource_group.name} \n\n"
f"See full output using: az containerapp show -n {app.name} -g {app.resource_group.name} \n")
return output

logger.warning(f"\nYour container app ({app.name}) has been created a deployed! Congrats! \n")
url and logger.warning(f"Browse to your container app at: {url} \n")
logger.warning(f"Stream logs for your container with: az containerapp logs -n {app.name} -g {app.resource_group.name} \n")
logger.warning(f"See full output using: az containerapp show -n {app.name} -g {app.resource_group.name} \n")
14 changes: 11 additions & 3 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,10 @@ def containerapp_up(cmd,
image = _reformat_image(source, repo, image)
token = None if not repo else get_github_access_token(cmd, ["admin:repo_hook", "repo", "workflow"], token)

if image and "mcr.microsoft.com/azuredocs/containerapps-helloworld:latest" in image.lower():
ingress = "external" if not ingress else ingress
target_port = 80 if not target_port else target_port

dockerfile_content = _get_dockerfile_content(repo, branch, token, source, context_path, dockerfile)
ingress, target_port = _get_ingress_and_target_port(ingress, target_port, dockerfile_content)

Expand All @@ -2026,6 +2030,10 @@ def containerapp_up(cmd,

_set_up_defaults(cmd, name, resource_group_name, logs_customer_id, location, resource_group, env, app)

if app.check_exists():
if app.get()["properties"]["provisioningState"] == "InProgress":
raise ValidationError("Containerapp has an existing provisioning in progress. Please wait until provisioning has completed and rerun the command.")

if source or repo:
registry_server = _get_registry_from_app(app) # if the app exists, get the registry
_get_registry_details(cmd, app) # fetch ACR creds from arguments registry arguments
Expand All @@ -2035,7 +2043,7 @@ def containerapp_up(cmd,
app.create_acr_if_needed()

if source:
app.run_acr_build(dockerfile, source)
app.run_acr_build(dockerfile, source, False)

app.create(no_registry=bool(repo))
if repo:
Expand All @@ -2045,7 +2053,7 @@ def containerapp_up(cmd,
if browse:
open_containerapp_in_browser(cmd, app.name, app.resource_group.name)

print(up_output(app))
up_output(app)


def containerapp_up_logic(cmd, resource_group_name, name, managed_env, image, env_vars, ingress, target_port, registry_server, registry_user, registry_pass):
Expand Down Expand Up @@ -2169,6 +2177,6 @@ def containerapp_up_logic(cmd, resource_group_name, name, managed_env, image, en
registries_def.append(registry)

if ca_exists:
return ContainerAppClient.patch_update(cmd, resource_group_name, name, containerapp_def)
return ContainerAppClient.update(cmd, resource_group_name, name, containerapp_def)
else:
return ContainerAppClient.create_or_update(cmd, resource_group_name, name, containerapp_def)

0 comments on commit bfcace8

Please sign in to comment.