Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Release History

* Fix issue #7154: Updating documentation for command <> to use back ticks instead of single quotes
* Fix issue #11287: webapp up: By default make the app created using up 'should be 'SSL enabled'
* Fix issue #11592: Add az webapp up flag for html static sites

**ARM**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,39 @@ def get_num_apps_in_asp(cmd, rg_name, asp_name):


# pylint:disable=unexpected-keyword-arg
def get_lang_from_content(src_path):
def get_lang_from_content(src_path, html=False):
# NODE: package.json should exist in the application root dir
# NETCORE & DOTNET: *.csproj should exist in the application dir
# NETCORE: <TargetFramework>netcoreapp2.0</TargetFramework>
# DOTNET: <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
runtime_details_dict = dict.fromkeys(['language', 'file_loc', 'default_sku'])
package_json_file = os.path.join(src_path, 'package.json')
package_python_file = os.path.join(src_path, 'requirements.txt')
static_html_file = ""
package_netcore_file = ""
runtime_details_dict['language'] = ''
runtime_details_dict['file_loc'] = ''
runtime_details_dict['default_sku'] = 'F1'
import fnmatch
for _dirpath, _dirnames, files in os.walk(src_path):
for file in files:
if fnmatch.fnmatch(file, "*.csproj"):
if html and (fnmatch.fnmatch(file, "*.html") or fnmatch.fnmatch(file, "*.htm") or
fnmatch.fnmatch(file, "*shtml.")):
static_html_file = os.path.join(src_path, file)
break
elif fnmatch.fnmatch(file, "*.csproj"):
package_netcore_file = os.path.join(src_path, file)
break

if os.path.isfile(package_python_file):
if html:
if static_html_file:
runtime_details_dict['language'] = STATIC_RUNTIME_NAME
runtime_details_dict['file_loc'] = static_html_file
runtime_details_dict['default_sku'] = 'F1'
else:
raise CLIError("The html flag was passed, but could not find HTML files, "
"see 'https://go.microsoft.com/fwlink/?linkid=2109470' for more information")
elif os.path.isfile(package_python_file):
runtime_details_dict['language'] = PYTHON_RUNTIME_NAME
runtime_details_dict['file_loc'] = package_python_file
runtime_details_dict['default_sku'] = LINUX_SKU_DEFAULT
Expand Down Expand Up @@ -318,21 +331,21 @@ def get_profile_username():
return user


def get_sku_to_use(src_dir, sku=None):
def get_sku_to_use(src_dir, html=False, sku=None):
if sku is None:
lang_details = get_lang_from_content(src_dir)
lang_details = get_lang_from_content(src_dir, html)
return lang_details.get("default_sku")
logger.info("Found sku argument, skipping use default sku")
return sku


def set_language(src_dir):
lang_details = get_lang_from_content(src_dir)
def set_language(src_dir, html=False):
lang_details = get_lang_from_content(src_dir, html)
return lang_details.get('language')


def detect_os_form_src(src_dir):
lang_details = get_lang_from_content(src_dir)
def detect_os_form_src(src_dir, html=False):
lang_details = get_lang_from_content(src_dir, html)
language = lang_details.get('language')
return "Linux" if language is not None and language.lower() == NODE_RUNTIME_NAME \
or language.lower() == PYTHON_RUNTIME_NAME else OS_DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,8 @@
short-summary: >
Create a webapp and deploy code from a local workspace to the app. The command is required to run from the folder
where the code is present. Current support includes Node, Python, .NET Core and ASP.NET. Node,
Python apps are created as Linux apps. .Net Core, ASP.NET apps are created as Windows apps.
Python apps are created as Linux apps. .Net Core, ASP.NET, and static HTML apps are created as Windows apps.
Append the html flag to deploy as a static HTML app.
examples:
- name: View the details of the app that will be created, without actually running the operation
text: >
Expand All @@ -1738,6 +1739,9 @@
- name: Create a web app and enable log streaming after the deployment operation is complete. This will enable the default configuration required to enable log streaming.
text: >
az webapp up -n MyUniqueAppName --logs
- name: Create a web app and deploy as a static HTML app.
text: >
az webapp up -n MyUniqueAppName --html
"""

helps['webapp update'] = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def load_arguments(self, _):
c.argument('location', arg_type=get_location_type(self.cli_ctx))
c.argument('launch_browser', help="Launch the created app using the default browser", default=False, action='store_true', options_list=['--launch-browser', '-b'])
c.argument('logs', help="Configure default logging required to enable viewing log stream immediately after launching the webapp", default=False, action='store_true')
c.argument('html', help="Ignore app detection and deploy as an html app", default=False, action='store_true')

with self.argument_context('webapp ssh') as c:
c.argument('port', options_list=['--port', '-p'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2967,16 +2967,16 @@ def get_history_triggered_webjob(cmd, resource_group_name, name, webjob_name, sl


def webapp_up(cmd, name, resource_group_name=None, plan=None, location=None, sku=None, dryrun=False, logs=False, # pylint: disable=too-many-statements,
launch_browser=False):
launch_browser=False, html=False):
import os
src_dir = os.getcwd()
_src_path_escaped = "{}".format(src_dir.replace(os.sep, os.sep + os.sep))
client = web_client_factory(cmd.cli_ctx)
user = get_profile_username()
_create_new_rg = False
_create_new_app = does_app_already_exist(cmd, name)
os_name = detect_os_form_src(src_dir)
lang_details = get_lang_from_content(src_dir)
os_name = detect_os_form_src(src_dir, html)
lang_details = get_lang_from_content(src_dir, html)
language = lang_details.get('language')

# detect the version
Expand Down Expand Up @@ -3023,7 +3023,7 @@ def webapp_up(cmd, name, resource_group_name=None, plan=None, location=None, sku
site_config = client.web_apps.get_configuration(rg_name, name)
else: # need to create new app, check if we need to use default RG or use user entered values
logger.warning("webapp %s doesn't exist", name)
sku = get_sku_to_use(src_dir, sku)
sku = get_sku_to_use(src_dir, html, sku)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid using positional arguments for each function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to pass these in case of the flag being set

Copy link
Contributor

@Juliehzl Juliehzl Jan 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. I will prefer something like get_sku_to_use(src_dir=src_dir, html=html, sku=sku) to avoid positional arguments. in this way it will not cause error when argument positions change.

loc = set_location(cmd, sku, location)
rg_name = get_rg_to_use(cmd, user, loc, os_name, resource_group_name)
_is_linux = os_name.lower() == 'linux'
Expand Down
Loading