Skip to content

Commit db4cc3c

Browse files
authored
[App Service] az webapp deploy: Warm-up kudu before making ARM deployment (#31083)
1 parent 41128e6 commit db4cc3c

38 files changed

Lines changed: 13577 additions & 29946 deletions

File tree

src/azure-cli/azure/cli/command_modules/appservice/custom.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ def enable_zip_deploy(cmd, resource_group_name, name, src, timeout=None, slot=No
814814

815815
if app_is_linux_webapp and not app_is_function_app and enable_kudu_warmup:
816816
try:
817-
logger.info("Warming up Kudu before deployment.")
817+
logger.warning("Warming up Kudu before deployment.")
818818
cookies = _warmup_kudu_and_get_cookie_internal(cmd, resource_group_name, name, slot)
819819
if cookies is None:
820820
logger.info("Failed to fetch affinity cookie. Deployment "
@@ -7379,9 +7379,9 @@ def __init__(self):
73797379
# pylint: enable=too-many-instance-attributes,too-few-public-methods
73807380

73817381

7382-
def _build_onedeploy_url(params):
7382+
def _build_onedeploy_url(params, instance_id=None):
73837383
if params.src_url:
7384-
return _build_onedeploy_arm_url(params)
7384+
return _build_onedeploy_arm_url(params, instance_id)
73857385
return _build_onedeploy_scm_url(params)
73867386

73877387

@@ -7407,19 +7407,20 @@ def _build_onedeploy_scm_url(params):
74077407
return deploy_url
74087408

74097409

7410-
def _build_onedeploy_arm_url(params):
7410+
def _build_onedeploy_arm_url(params, instance_id):
74117411
from azure.cli.core.commands.client_factory import get_subscription_id
74127412
client = web_client_factory(params.cmd.cli_ctx)
74137413
sub_id = get_subscription_id(params.cmd.cli_ctx)
7414+
instances_param = f"/instances/{instance_id}" if instance_id is not None else ""
74147415
if not params.slot:
74157416
base_url = (
74167417
f"subscriptions/{sub_id}/resourceGroups/{params.resource_group_name}/providers/Microsoft.Web/sites/"
7417-
f"{params.webapp_name}/extensions/onedeploy?api-version={client.DEFAULT_API_VERSION}"
7418+
f"{params.webapp_name}{instances_param}/extensions/onedeploy?api-version={client.DEFAULT_API_VERSION}"
74187419
)
74197420
else:
74207421
base_url = (
74217422
f"subscriptions/{sub_id}/resourceGroups/{params.resource_group_name}/providers/Microsoft.Web/sites/"
7422-
f"{params.webapp_name}/slots/{params.slot}/extensions/onedeploy"
7423+
f"{params.webapp_name}/slots/{params.slot}{instances_param}/extensions/onedeploy"
74237424
f"?api-version={client.DEFAULT_API_VERSION}"
74247425
)
74257426
return params.cmd.cli_ctx.cloud.endpoints.resource_manager + base_url
@@ -7618,7 +7619,24 @@ def _make_onedeploy_request(params):
76187619
verify=not should_disable_connection_verify())
76197620
poll_async_deployment_for_debugging = True
76207621
else:
7621-
response = send_raw_request(params.cmd.cli_ctx, "PUT", deploy_url, body=body)
7622+
if params.is_linux_webapp and not params.is_functionapp and params.enable_kudu_warmup:
7623+
try:
7624+
logger.warning("Warming up Kudu before deployment.")
7625+
cookies = _warmup_kudu_and_get_cookie_internal(params.cmd, params.resource_group_name,
7626+
params.webapp_name, params.slot)
7627+
if cookies is None:
7628+
logger.info("Failed to fetch affinity cookie for Kudu. "
7629+
"Deployment will proceed without pre-warming a Kudu instance.")
7630+
response = send_raw_request(params.cmd.cli_ctx, "PUT", deploy_url, body=body)
7631+
else:
7632+
deploy_arm_url = _build_onedeploy_url(params, cookies.get("ARRAffinity"))
7633+
response = send_raw_request(params.cmd.cli_ctx, "PUT", deploy_arm_url, body=body)
7634+
except Exception as ex: # pylint: disable=broad-except
7635+
logger.info("Failed to deploy using instances endpoint. "
7636+
"Deployment will proceed without pre-warming a Kudu instance. Ex: %s", ex)
7637+
response = send_raw_request(params.cmd.cli_ctx, "PUT", deploy_url, body=body)
7638+
else:
7639+
response = send_raw_request(params.cmd.cli_ctx, "PUT", deploy_url, body=body)
76227640
poll_async_deployment_for_debugging = False
76237641

76247642
# check the status of deployment

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/recordings/test_acr_create_function_app.yaml

Lines changed: 549 additions & 534 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/recordings/test_acr_deployment_function_app.yaml

Lines changed: 388 additions & 906 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/recordings/test_acr_integration_function_app.yaml

Lines changed: 546 additions & 582 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/recordings/test_domain_create.yaml

Lines changed: 11 additions & 1639 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/recordings/test_functionapp_access_restriction_add.yaml

Lines changed: 145 additions & 509 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/recordings/test_functionapp_access_restriction_add_ip_address_validation.yaml

Lines changed: 161 additions & 523 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/recordings/test_functionapp_access_restriction_add_scm.yaml

Lines changed: 152 additions & 635 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/recordings/test_functionapp_access_restriction_remove.yaml

Lines changed: 155 additions & 517 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/recordings/test_functionapp_access_restriction_remove_scm.yaml

Lines changed: 153 additions & 515 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)