Skip to content

Instantly share code, notes, and snippets.

@rsp9u
Created October 2, 2024 04:05
Show Gist options
  • Select an option

  • Save rsp9u/a652c9262c4f1720fe386d52b93bcd54 to your computer and use it in GitHub Desktop.

Select an option

Save rsp9u/a652c9262c4f1720fe386d52b93bcd54 to your computer and use it in GitHub Desktop.
Updating Azure Container Apps by Python SDK
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.appcontainers import ContainerAppsAPIClient
sub_id = os.environ.get("SUBSCRIPTION_ID")
rg_id = os.environ.get("RESOURCE_GROUP_ID")
app_name = os.environ.get("APP_NAME")
client = ContainerAppsAPIClient(credential=DefaultAzureCredential(), subscription_id=sub_id)
app = client.container_apps.get(rg_id, app_name)
secrets = client.container_apps.list_secrets(rg_id, app_name)
old_revision_num = int(app.template.revision_suffix.replace('rev', ''))
new_revision = app.template.as_dict()
new_revision["revision_suffix"] = f"rev{old_revision_num + 1}"
app.template = app.template.from_dict(new_revision)
new_config = app.configuration.as_dict()
new_config["secrets"] = secrets.as_dict()["value"]
app.configuration = app.configuration.from_dict(new_config)
poll = client.container_apps.begin_create_or_update(rg_id, app_name, app)
ret = poll.wait()
if ret is None:
print("ok")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment