Skip to content

Commit

Permalink
Updating Zip deploy to using async api & display status of deployment (
Browse files Browse the repository at this point in the history
  • Loading branch information
panchagnula authored and yugangw-msft committed May 17, 2018
1 parent 72cb0a5 commit 80c3db9
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 96 deletions.
1 change: 1 addition & 0 deletions src/command_modules/azure-cli-appservice/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release History
0.1.33
++++++
* webapp/functionapp: improve generic update commands
* webapp/functionapp: webapp deployment source config-zip supports async operation with status updates for long running operation

0.1.32
++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
short-summary: Perform deployment using the kudu zip push deployment for a webapp.
long-summary: >
By default Kudu assumes that zip deployments do not require any build-related actions like
npm install or dotnet publish. This can be overridden by including a .deployment file on your
npm install or dotnet publish. This can be overridden by including a .deployment file in your
zip file with the following content '[config] SCM_DO_BUILD_DURING_DEPLOYMENT = true',
to enable Kudu detection logic and build script generation process.
See https://github.com/projectkudu/kudu/wiki/Configurable-settings#enabledisable-build-actions-preview.
Expand Down Expand Up @@ -762,7 +762,7 @@
short-summary: Perform deployment using the kudu zip push deployment for a function app.
long-summary: >
By default Kudu assumes that zip deployments do not require any build-related actions like
npm install or dotnet publish. This can be overridden by including an .deployment file on your
npm install or dotnet publish. This can be overridden by including an .deployment file in your
zip file with the following content '[config] SCM_DO_BUILD_DURING_DEPLOYMENT = true',
to enable Kudu detection logic and build script generation process.
See https://github.com/projectkudu/kudu/wiki/Configurable-settings#enabledisable-build-actions-preview.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def update_app_settings(cmd, resource_group_name, name, settings=None, slot=None
def enable_zip_deploy(cmd, resource_group_name, name, src, slot=None):
user_name, password = _get_site_credential(cmd.cli_ctx, resource_group_name, name, slot)
scm_url = _get_scm_url(cmd, resource_group_name, name, slot)
zip_url = scm_url + '/api/zipdeploy'
zip_url = scm_url + '/api/zipdeploy?isAsync=true'
deployment_status_url = scm_url + '/api/deployments/latest'

import urllib3
authorization = urllib3.util.make_headers(basic_auth='{0}:{1}'.format(user_name, password))
Expand All @@ -179,14 +180,13 @@ def enable_zip_deploy(cmd, resource_group_name, name, src, slot=None):
# Read file content
with open(os.path.realpath(os.path.expanduser(src)), 'rb') as fs:
zip_content = fs.read()
r = requests.post(zip_url, data=zip_content, headers=headers)
if r.status_code != 200:
raise CLIError("Zip deployment {} failed with status code '{}' and reason '{}'".format(
zip_url, r.status_code, r.text))

# on successful deployment navigate to the app, display the latest deployment json response
response = requests.get(scm_url + '/api/deployments/latest', headers=authorization)
return response.json()
requests.post(zip_url, data=zip_content, headers=headers)
# check the status of async deployment
response = requests.get(deployment_status_url, headers=authorization)
if response.json()['status'] != 4:
logger.warning(response.json()['progress'])
response = _check_zip_deployment_status(deployment_status_url, authorization)
return response


def get_sku_name(tier):
Expand All @@ -207,12 +207,6 @@ def get_sku_name(tier):
raise CLIError("Invalid sku(pricing tier), please refer to command help for valid values")


# deprecated, do not use
def _get_sku_name(tier):
return get_sku_name(tier)
# endregion


def _generic_settings_operation(cli_ctx, resource_group_name, name, operation_name,
setting_properties, slot=None, client=None):
client = client or web_client_factory(cli_ctx)
Expand Down Expand Up @@ -1766,3 +1760,25 @@ def list_locations(cmd, sku, linux_workers_enabled=None):
client = web_client_factory(cmd.cli_ctx)
full_sku = get_sku_name(sku)
return client.list_geo_regions(full_sku, linux_workers_enabled)


def _check_zip_deployment_status(deployment_status_url, authorization):
import requests
import time
num_trials = 1
while num_trials < 200:
time.sleep(15)
response = requests.get(deployment_status_url, headers=authorization)
res_dict = response.json()
num_trials = num_trials + 1
if res_dict['status'] == 5:
logger.warning("Zip deployment failed status %s", res_dict['status_text'])
break
elif res_dict['status'] == 4:
break
logger.warning(res_dict['progress'])
# if the deployment is taking longer than expected
if res_dict['status'] != 4:
logger.warning("""Deployment is taking longer than expected. Please verify status at '%s'
beforing launching the app""", deployment_status_url)
return res_dict
Loading

0 comments on commit 80c3db9

Please sign in to comment.