From 3bb73ab5dada25e75c73f1be3ba24edeed825bc0 Mon Sep 17 00:00:00 2001 From: Sisira Panchagnula Date: Wed, 7 Feb 2018 10:11:08 -0800 Subject: [PATCH] [webapp] Adding a work around for calling kudu to warm up (#48) * Adding a call to scm to warm up kudu for zipdeploy updating index.json * Adding a fix to skip zip & deploy if we detect the contents are not node app * index.json update * style fixes plus index update * bug fix --- src/index.json | 8 +++--- src/webapp/azext_webapp/create_util.py | 8 ++++++ src/webapp/azext_webapp/custom.py | 40 +++++++++++++++++++------- src/webapp/setup.py | 2 +- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/index.json b/src/index.json index 9796a381ace..2aaaea0c6e9 100644 --- a/src/index.json +++ b/src/index.json @@ -370,9 +370,9 @@ ], "webapp": [ { - "filename": "webapp-0.0.6-py2.py3-none-any.whl", - "sha256Digest": "65ffc1f0c34bb4b7b3fa0e3d3b3c49b745d8b46d04c2653ae0e0a22d01329669", - "downloadUrl": "https://github.com/panchagnula/azure-cli-extensions/raw/sisirap-extensions-whl/dist/webapp-0.0.6-py2.py3-none-any.whl", + "filename": "webapp-0.0.7-py2.py3-none-any.whl", + "sha256Digest": "11090b2d19d2082f86249bbf06566bd3924e4c976ac47c95e34ecd82541944c8", + "downloadUrl": "https://github.com/panchagnula/azure-cli-extensions/raw/sisirap-extensions-whl/dist/webapp-0.0.7-py2.py3-none-any.whl", "metadata": { "classifiers": [ "Development Status :: 4 - Beta", @@ -409,7 +409,7 @@ "metadata_version": "2.0", "name": "webapp", "summary": "An Azure CLI Extension to manage appservice resources", - "version": "0.0.6" + "version": "0.0.7" } } ] diff --git a/src/webapp/azext_webapp/create_util.py b/src/webapp/azext_webapp/create_util.py index fdb85a4af39..df5ed2b89c9 100644 --- a/src/webapp/azext_webapp/create_util.py +++ b/src/webapp/azext_webapp/create_util.py @@ -83,3 +83,11 @@ def check_if_asp_exists(cmd, rg_name, asp_name): if item.name == asp_name: return True return False + + +def check_app_exists(cmd, rg_name, app_name): + client = web_client_factory(cmd.cli_ctx) + for item in list(client.web_apps.list_by_resource_group(rg_name)): + if item.name == app_name: + return True + return False diff --git a/src/webapp/azext_webapp/custom.py b/src/webapp/azext_webapp/custom.py index 1665994e07b..08a2c74afb1 100644 --- a/src/webapp/azext_webapp/custom.py +++ b/src/webapp/azext_webapp/custom.py @@ -12,6 +12,8 @@ enable_zip_deploy, create_webapp, update_app_settings, + _get_site_credential, + _get_scm_url, _get_sku_name) from .create_util import ( @@ -22,6 +24,7 @@ check_resource_group_exists, check_resource_group_supports_linux, check_if_asp_exists, + check_app_exists, web_client_factory ) @@ -126,20 +129,37 @@ def create_deploy_webapp(cmd, name, location=None, dryrun=False): logger.warning("App service plan '%s' already exists.", asp) # create the Linux app - logger.warning("Creating app '%s' ....", name) - create_webapp(cmd, rg_name, name, asp, runtime_version) - logger.warning("Webapp creation complete") + if not check_app_exists(cmd, rg_name, name): + logger.warning("Creating app '%s' ....", name) + create_webapp(cmd, rg_name, name, asp, runtime_version) + logger.warning("Webapp creation complete") + else: + logger.warning("App '%s' already exists", name) # setting to build after deployment logger.warning("Updating app settings to enable build after deployment") update_app_settings(cmd, rg_name, name, ["SCM_DO_BUILD_DURING_DEPLOYMENT=true"]) + # work around until the timeout limits issue for linux is investigated & fixed + # wakeup kudu, by making an SCM call + + import requests + # work around until the timeout limits issue for linux is investigated & fixed + user_name, password = _get_site_credential(cmd.cli_ctx, rg_name, name) + scm_url = _get_scm_url(cmd, rg_name, name) + import urllib3 + authorization = urllib3.util.make_headers(basic_auth='{0}:{1}'.format(user_name, password)) + requests.get(scm_url + '/api/settings', headers=authorization) + + if package_json_path != '': + logger.warning("Creating zip with contents of dir %s ...", src_dir) + # zip contents & deploy + zip_file_path = zip_contents_from_dir(src_dir) + + logger.warning("Deploying and building contents to app." + "This operation can take some time to finish...") + enable_zip_deploy(cmd, rg_name, name, zip_file_path) + else: + logger.warning("No package.json found, skipping zip and deploy process") - # zip contents & deploy - logger.warning("Creating zip with contents of dir %s ...", src_dir) - zip_file_path = zip_contents_from_dir(src_dir) - - logger.warning("Deploying and building contents to app." - "This operation can take some time to finish...") - enable_zip_deploy(cmd, rg_name, name, zip_file_path) logger.warning("All done. %s", create_json) return None diff --git a/src/webapp/setup.py b/src/webapp/setup.py index c2cdff2b61c..bedccd9e4da 100644 --- a/src/webapp/setup.py +++ b/src/webapp/setup.py @@ -8,7 +8,7 @@ from codecs import open from setuptools import setup, find_packages -VERSION = "0.0.6" +VERSION = "0.0.7" CLASSIFIERS = [ 'Development Status :: 4 - Beta',