Skip to content

Commit

Permalink
Support for Static HTML file deployment
Browse files Browse the repository at this point in the history
Check the default_RG exists in the current subscription and minor string updates

Updating version

Pylint fixes

Minor  fixes
  • Loading branch information
panchagnula committed May 3, 2018
1 parent b69a217 commit 05f7e23
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@
],
"webapp": [
{
"filename": "webapp-0.2.3-py2.py3-none-any.whl",
"sha256Digest": "c6e2c8fff7f3d88f9b7eb77327d67ab525ad9c8b8b27b3b004b565fac391c241",
"downloadUrl": "https://github.com/panchagnula/azure-cli-extensions/raw/sisirap-extensions-whl/dist/webapp-0.2.3-py2.py3-none-any.whl",
"filename": "webapp-0.2.4-py2.py3-none-any.whl",
"sha256Digest": "28736466d2602516394d3ed3cd784f318013be7624db8f3fe09012927e7e9de7",
"downloadUrl": "https://github.com/panchagnula/azure-cli-extensions/raw/sisirap-extensions-whl/dist/webapp-0.2.4-py2.py3-none-any.whl",
"metadata": {
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.0.24",
Expand Down Expand Up @@ -366,7 +366,7 @@
"metadata_version": "2.0",
"name": "webapp",
"summary": "An Azure CLI Extension to manage appservice resources",
"version": "0.2.3"
"version": "0.2.4"
}
}
],
Expand Down
9 changes: 5 additions & 4 deletions src/webapp/azext_webapp/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
NODE_VERSION_DEFAULT = "8.9"
NETCORE_VERSION_DEFAULT = "2.0"
DOTNET_VERSION_DEFAULT = "4.7"
NETCORE_RUNTIME_NAME = "dotnetcore"
DOTNET_RUNTIME_NAME = "aspnet"
JAVA_RUNTIME_NAME = "java"
OS_DEFAULT = "Windows"
STATIC_RUNTIME_NAME = "static" # not an oficial supported runtime but used for CLI logic
# TODO: Remove this once we have the api returning the versions
NODE_VERSIONS = ['4.4', '4.5', '6.2', '6.6', '6.9', '6.11', '8.0', '8.1']
NETCORE_VERSIONS = ['1.0', '1.1', '2.0']
DOTNET_VERSIONS = ['3.5', '4.7']
NODE_RUNTIME_NAME = "node"
NETCORE_RUNTIME_NAME = "dotnetcore"
DOTNET_RUNTIME_NAME = "aspnet"
JAVA_RUNTIME_NAME = "java"
OS_DEFAULT = "Windows"
18 changes: 13 additions & 5 deletions src/webapp/azext_webapp/create_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
DOTNET_RUNTIME_NAME,
DOTNET_VERSION_DEFAULT,
DOTNET_VERSIONS,
JAVA_RUNTIME_NAME)
JAVA_RUNTIME_NAME,
STATIC_RUNTIME_NAME)


def _resource_client_factory(cli_ctx, **_):
Expand Down Expand Up @@ -57,18 +58,20 @@ def zip_contents_from_dir(dirPath, lang):
def get_runtime_version_details(file_path, lang_name):
version_detected = None
version_to_create = None
print(lang_name.lower())
if lang_name.lower() == NETCORE_RUNTIME_NAME:
# method returns list in DESC, pick the first
version_detected = parse_netcore_version(file_path)[0]
version_to_create = detect_netcore_version_tocreate(version_detected)
elif lang_name.lower() == DOTNET_RUNTIME_NAME:
# method returns list in DESC, pick the first
# method returns list in DESC, pick the first
version_detected = parse_dotnet_version(file_path)
version_to_create = detect_dotnet_version_tocreate(version_detected)
elif lang_name.lower() == NODE_RUNTIME_NAME:
version_detected = parse_node_version(file_path)[0]
version_to_create = detect_node_version_tocreate(version_detected)
elif lang_name.lower() == STATIC_RUNTIME_NAME:
version_detected = "-"
version_to_create = "-"
return {'detected': version_detected, 'to_create': version_to_create}


Expand Down Expand Up @@ -123,6 +126,7 @@ def get_lang_from_content(src_path):
package_json_file = os.path.join(src_path, 'package.json')
package_netlang_glob = glob.glob("**/*.csproj", recursive=True)
runtime_java_file = glob.glob("**/*.war", recursive=True)
static_html_file = glob.glob("**/*.html", recursive=True)
if os.path.isfile(package_json_file):
runtime_details_dict['language'] = NODE_RUNTIME_NAME
runtime_details_dict['file_loc'] = package_json_file
Expand All @@ -137,6 +141,10 @@ def get_lang_from_content(src_path):
runtime_details_dict['language'] = JAVA_RUNTIME_NAME
runtime_details_dict['file_loc'] = runtime_java_file
runtime_details_dict['default_sku'] = 'S1'
elif static_html_file:
runtime_details_dict['language'] = STATIC_RUNTIME_NAME
runtime_details_dict['file_loc'] = static_html_file[0]
runtime_details_dict['default_sku'] = 'F1'
return runtime_details_dict


Expand All @@ -158,8 +166,8 @@ def parse_dotnet_version(file_path):
from xml.dom import minidom
import re
xmldoc = minidom.parse(file_path)
framework_ver= xmldoc.getElementsByTagName('TargetFrameworkVersion')
version_detected= ['4.7']
framework_ver = xmldoc.getElementsByTagName('TargetFrameworkVersion')
version_detected = ['4.7']
target_ver = framework_ver[0].firstChild.data
non_decimal = re.compile(r'[^\d.]+')
# reduce the version to '5.7.4' from '5.7'
Expand Down
33 changes: 20 additions & 13 deletions src/webapp/azext_webapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
_get_scm_url,
get_sku_name,
list_publish_profiles,
get_site_configs)
get_site_configs,
config_diagnostics)

from azure.cli.command_modules.appservice._appservice_utils import _generic_site_operation

from .create_util import (
zip_contents_from_dir,
Expand All @@ -33,7 +36,7 @@
web_client_factory
)

from ._constants import (NODE_RUNTIME_NAME, OS_DEFAULT, JAVA_RUNTIME_NAME)
from ._constants import (NODE_RUNTIME_NAME, OS_DEFAULT, JAVA_RUNTIME_NAME, STATIC_RUNTIME_NAME)

logger = get_logger(__name__)

Expand Down Expand Up @@ -65,12 +68,13 @@ def create_deploy_webapp(cmd, name, location=None, dryrun=False):
sku = lang_details.get("default_sku")
language = lang_details.get("language")
is_java = language.lower() == JAVA_RUNTIME_NAME
is_skip_build = is_java or language.lower() == STATIC_RUNTIME_NAME
os_val = "Linux" if language.lower() == NODE_RUNTIME_NAME or is_java else OS_DEFAULT
# detect the version
data = get_runtime_version_details(lang_details.get('file_loc'), language)
version_used_create = data.get('to_create')
detected_version = data.get('detected')
runtime_version = "{}|{}".format(language, version_used_create)
runtime_version = "{}|{}".format(language, version_used_create) if version_used_create != "-" else version_used_create

if location is None:
locs = client.list_geo_regions(sku, True)
Expand All @@ -93,7 +97,7 @@ def create_deploy_webapp(cmd, name, location=None, dryrun=False):

# Resource group: check if default RG is set
default_rg = cmd.cli_ctx.config.get('defaults', 'group', fallback=None)
if default_rg and check_resource_group_supports_os(cmd, default_rg, location, is_linux):
if default_rg and check_resource_group_exists(cmd, default_rg) and check_resource_group_supports_os(cmd, default_rg, location, is_linux):
rg_name = default_rg
rg_mssg = "[Using default Resource group]"
else:
Expand Down Expand Up @@ -143,16 +147,15 @@ def create_deploy_webapp(cmd, name, location=None, dryrun=False):
# create the app
if not check_app_exists(cmd, rg_name, name):
logger.warning("Creating app '%s' ....", name)
app_created = create_webapp(cmd, rg_name, name, asp, runtime_version if is_linux else None)
# update create_json to include the app_url
url = app_created.enabled_host_names[0] # picks the custom domain URL incase a domain is assigned
url = 'https://' + url
create_webapp(cmd, rg_name, name, asp, runtime_version if is_linux else None)
logger.warning("Webapp creation complete")
else:
logger.warning("App '%s' already exists", name)
# update create_json to include the app_url
url = _get_app_url(cmd, rg_name, name) # picks the custom domain URL incase a domain is assigned

if do_deployment:
if not is_java:
if not is_skip_build:
# 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"])
Expand All @@ -175,8 +178,8 @@ def create_deploy_webapp(cmd, name, location=None, dryrun=False):
# zip contents & deploy
zip_file_path = zip_contents_from_dir(src_dir, language)

logger.warning("Deploying and building contents to app."
"This operation can take some time to finish...")
logger.warning("Deploying %s contents to app."
"This operation can take some time to finish...", '' if is_skip_build else 'and building')
enable_zip_deploy(cmd, rg_name, name, zip_file_path)
if not is_java:
# Remove the file afer deployment, handling exception if user removed the file manually
Expand All @@ -185,7 +188,7 @@ def create_deploy_webapp(cmd, name, location=None, dryrun=False):
except OSError:
pass
else:
logger.warning("No 'NODE' or 'DOTNETCORE' package detected, skipping zip and deploy process")
logger.warning("No known package (Node, ASP.NET, .NETCORE, Java or Static Html) found skipping zip and deploy process")
create_json.update({'app_url': url})
logger.warning("All done.")
return create_json
Expand Down Expand Up @@ -253,4 +256,8 @@ def create_tunnel(cmd, resource_group_name, name, port, slot=None):
break
logger.warning('Tunnel is ready! Creating on port %s', port)
tunnel_server.start_server()



def _get_app_url(cmd, rg_name, app_name):
site = _generic_site_operation(cmd.cli_ctx, rg_name, app_name, 'get')
return "https://" + site.enabled_host_names[0]
2 changes: 1 addition & 1 deletion src/webapp/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from codecs import open
from setuptools import setup, find_packages

VERSION = "0.2.3"
VERSION = "0.2.4"

CLASSIFIERS = [
'Development Status :: 4 - Beta',
Expand Down

0 comments on commit 05f7e23

Please sign in to comment.