Skip to content

Commit

Permalink
[App Service] BREAKING CHANGE: az webapp list-runtimes: Use new sta…
Browse files Browse the repository at this point in the history
…cks APIs (#21057)

* WIP

* WIP

* WIP

* WIP

* finish list runtimes impl and switch to new argument usage -- webapp create/up still WIP

* fix az webapp create

* WIP

* WIP

* WIP

* WIP

* fix tests

* fix tests

* fix tests

* fix tests

* fix test_webapp_up_python_e2e

* fix test_webapp_up_statichtml_e2e

* use runtime objects over dicts and include ease of use runtime name resolution

* mark flaky tests to skip them

* bug fix

* bug fix

* bug fix

* fix style

* rerecord webapp tests

* rectify webapp up tests

* rectify webapp up tests again

* remove erroneous import

* update webapp up test

* update webapp up test

* rerecord webapp access restriction tests

* fix credscan fail

* fix windows java SE configs

* return both windows and linux stacks by default

* use --os argument over --windows

* implement 'az functionapp list-runtimes'

* change '(WIP) az functionapp create' to use new runtimes API ; still need to rerecord tests

* rerecord 'test_functionapp_commands' tests

* rerecord more tests

* fix GH actions

* remove function app stacks JSON file

* add back hardcoded function; use colon delimiter; fix deprecation

* remove creds from recordings

* add back appservice package data

* dummy commit to rerun CI
  • Loading branch information
StrawnSC authored Feb 11, 2022
1 parent c3b42e7 commit 45ef11f
Show file tree
Hide file tree
Showing 170 changed files with 86,408 additions and 82,901 deletions.
21 changes: 2 additions & 19 deletions src/azure-cli/azure/cli/command_modules/appservice/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,18 @@
# --------------------------------------------------------------------------------------------
import os

NODE_VERSION_DEFAULT = "10.14"
NODE_VERSION_NEWER = "12-lts"
NODE_EXACT_VERSION_DEFAULT = "10.14.1"
NETCORE_VERSION_DEFAULT = "3.1"
ASPDOTNET_VERSION_DEFAULT = "4.8"
DOTNET_VERSION_DEFAULT = "5.0"
DOTNET_TARGET_FRAMEWORK_REGEX = r"^net\d+\.\d+$"
PYTHON_VERSION_DEFAULT = "3.7"
NETCORE_RUNTIME_NAME = "dotnetcore"
ASPDOTNET_RUNTIME_NAME = "aspnet"
DOTNET_RUNTIME_NAME = "dotnet"
NODE_RUNTIME_NAME = "node"
PYTHON_RUNTIME_NAME = "python"
OS_DEFAULT = "Windows"
LINUX_OS_NAME = "linux"
WINDOWS_OS_NAME = "windows"
STATIC_RUNTIME_NAME = "static" # not an official supported runtime but used for CLI logic
NODE_VERSIONS = ['10.6', '10.14']
PYTHON_VERSIONS = ['3.9', '3.8', '3.7', '3.6']
NETCORE_VERSIONS = ['2.1', '3.1']
DOTNET_VERSIONS = ['5.0', '6.0']
ASPDOTNET_VERSIONS = ['3.5', '4.8']
LINUX_SKU_DEFAULT = "P1V2"
FUNCTIONS_VERSIONS = ['2', '3', '4']
FUNCTIONS_STACKS_API_JSON_PATHS = {
'windows': os.path.abspath(os.path.join(os.path.abspath(__file__), '../resources/WindowsFunctionsStacks.json')),
'linux': os.path.abspath(os.path.join(os.path.abspath(__file__), '../resources/LinuxFunctionsStacks.json'))
}
FUNCTIONS_LINUX_RUNTIME_VERSION_REGEX = r"^.*\|(.*)$"
FUNCTIONS_WINDOWS_RUNTIME_VERSION_REGEX = r"^~(.*)$"
FUNCTIONS_NO_V2_REGIONS = {
Expand Down Expand Up @@ -69,9 +55,6 @@ def __init__(self):
self.FUNCTIONS_WORKER_RUNTIME = 'FUNCTIONS_WORKER_RUNTIME'


RUNTIME_STACKS = os.path.abspath(os.path.join(os.path.abspath(__file__),
'../resources/WebappRuntimeStacks.json'))

GENERATE_RANDOM_APP_NAMES = os.path.abspath(os.path.join(os.path.abspath(__file__),
'../resources/GenerateRandomAppNames.json'))

Expand Down
64 changes: 26 additions & 38 deletions src/azure-cli/azure/cli/command_modules/appservice/_create_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
from azure.cli.core.util import get_file_json
from azure.mgmt.web.models import SkuDescription

from ._constants import (NETCORE_VERSION_DEFAULT, NETCORE_VERSIONS, NODE_VERSION_DEFAULT,
NODE_VERSIONS, NETCORE_RUNTIME_NAME, NODE_RUNTIME_NAME, ASPDOTNET_RUNTIME_NAME,
ASPDOTNET_VERSION_DEFAULT, DOTNET_VERSIONS, STATIC_RUNTIME_NAME,
PYTHON_RUNTIME_NAME, PYTHON_VERSION_DEFAULT, LINUX_SKU_DEFAULT, OS_DEFAULT,
NODE_VERSION_NEWER, DOTNET_RUNTIME_NAME, DOTNET_VERSION_DEFAULT, ASPDOTNET_VERSIONS,
from ._constants import (NETCORE_RUNTIME_NAME, NODE_RUNTIME_NAME, ASPDOTNET_RUNTIME_NAME, STATIC_RUNTIME_NAME,
PYTHON_RUNTIME_NAME, LINUX_SKU_DEFAULT, OS_DEFAULT, DOTNET_RUNTIME_NAME,
DOTNET_TARGET_FRAMEWORK_REGEX, GENERATE_RANDOM_APP_NAMES)
from .utils import get_resource_if_exists

Expand Down Expand Up @@ -75,31 +72,31 @@ def zip_contents_from_dir(dirPath, lang):
return zip_file_path


def get_runtime_version_details(file_path, lang_name):
def get_runtime_version_details(file_path, lang_name, stack_helper, is_linux=False):
version_detected = None
version_to_create = None
if lang_name.lower() == DOTNET_RUNTIME_NAME:
version_detected = parse_dotnet_version(file_path, DOTNET_VERSION_DEFAULT)
version_to_create = detect_dotnet_version_tocreate(version_detected, DOTNET_VERSION_DEFAULT, DOTNET_VERSIONS)

if lang_name.lower() != STATIC_RUNTIME_NAME:
versions = stack_helper.get_version_list(lang_name, is_linux)
default_version = stack_helper.get_default_version(lang_name, is_linux)
version_to_create = default_version
if lang_name.lower() in [DOTNET_RUNTIME_NAME, ASPDOTNET_RUNTIME_NAME]:
version_detected = parse_dotnet_version(file_path, default_version)
version_to_create = detect_dotnet_version_tocreate(version_detected, default_version, versions)
elif 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() == ASPDOTNET_RUNTIME_NAME:
# method returns list in DESC, pick the first
version_detected = parse_dotnet_version(file_path, ASPDOTNET_VERSION_DEFAULT)
version_to_create = detect_dotnet_version_tocreate(version_detected,
ASPDOTNET_VERSION_DEFAULT, ASPDOTNET_VERSIONS)
version_to_create = detect_dotnet_version_tocreate(version_detected, default_version, versions)
elif lang_name.lower() == NODE_RUNTIME_NAME:
if file_path == '':
version_detected = "-"
version_to_create = NODE_VERSION_DEFAULT
version_to_create = default_version
else:
version_detected = parse_node_version(file_path)[0]
version_to_create = detect_node_version_tocreate(version_detected)
version_to_create = detect_node_version_tocreate(version_detected, versions, default_version)
elif lang_name.lower() == PYTHON_RUNTIME_NAME:
version_detected = "-"
version_to_create = PYTHON_VERSION_DEFAULT
version_to_create = default_version
elif lang_name.lower() == STATIC_RUNTIME_NAME:
version_detected = "-"
version_to_create = "-"
Expand Down Expand Up @@ -138,7 +135,7 @@ def get_num_apps_in_asp(cmd, rg_name, asp_name):


# pylint:disable=unexpected-keyword-arg
def get_lang_from_content(src_path, html=False):
def get_lang_from_content(src_path, html=False, is_linux=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>
Expand Down Expand Up @@ -181,7 +178,7 @@ def get_lang_from_content(src_path, html=False):
runtime_details_dict['file_loc'] = package_json_file if os.path.isfile(package_json_file) else ''
runtime_details_dict['default_sku'] = LINUX_SKU_DEFAULT
elif package_netcore_file:
runtime_lang = detect_dotnet_lang(package_netcore_file)
runtime_lang = detect_dotnet_lang(package_netcore_file, is_linux=is_linux)
runtime_details_dict['language'] = runtime_lang
runtime_details_dict['file_loc'] = package_netcore_file
runtime_details_dict['default_sku'] = 'F1'
Expand All @@ -192,9 +189,13 @@ def get_lang_from_content(src_path, html=False):
return runtime_details_dict


def detect_dotnet_lang(csproj_path):
def detect_dotnet_lang(csproj_path, is_linux=False):
import xml.etree.ElementTree as ET
import re

if is_linux:
return NETCORE_RUNTIME_NAME

parsed_file = ET.parse(csproj_path)
root = parsed_file.getroot()
version_lang = ''
Expand Down Expand Up @@ -269,12 +270,6 @@ def parse_node_version(file_path):
return version_detected or ['0.0']


def detect_netcore_version_tocreate(detected_ver):
if detected_ver in NETCORE_VERSIONS:
return detected_ver
return NETCORE_VERSION_DEFAULT


def detect_dotnet_version_tocreate(detected_ver, default_version, versions_list):
min_ver = versions_list[0]
if detected_ver in versions_list:
Expand All @@ -284,18 +279,11 @@ def detect_dotnet_version_tocreate(detected_ver, default_version, versions_list)
return default_version


def detect_node_version_tocreate(detected_ver):
if detected_ver in NODE_VERSIONS:
# TODO include better detections logic here
def detect_node_version_tocreate(detected_ver, node_versions, default_node_version):
if detected_ver in node_versions:
return detected_ver
# get major version & get the closest version from supported list
major_ver = int(detected_ver.split('.')[0])
node_ver = NODE_VERSION_DEFAULT
# TODO: Handle checking for minor versions if node major version is 10
if major_ver <= 11:
node_ver = NODE_VERSION_DEFAULT
else:
node_ver = NODE_VERSION_NEWER
return node_ver
return default_node_version


def find_key_in_json(json_data, key):
Expand Down
13 changes: 9 additions & 4 deletions src/azure-cli/azure/cli/command_modules/appservice/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@

helps['functionapp config access-restriction add'] = """
type: command
short-summary: Adds an Access Restriction to the functionapp
short-summary: Adds an Access Restriction to the function app
examples:
- name: Add Access Restriction opening (Allow) named developers for IPv4 address 130.220.0.0/27 with priority 200 to main site.
text: az functionapp config access-restriction add -g ResourceGroup -n AppName --rule-name developers --action Allow --ip-address 130.220.0.0/27 --priority 200
Expand Down Expand Up @@ -1441,15 +1441,15 @@
- name: Create a web app with the default configuration.
text: >
az webapp create -g MyResourceGroup -p MyPlan -n MyUniqueAppName
- name: Create a web app with a Java 11 runtime using '|' delimiter.
- name: Create a web app with a Java 11 runtime using '|' delimiter. (not recommended for powershell; use the ":" delimiter instead)
text: >
az webapp create -g MyResourceGroup -p MyPlan -n MyUniqueAppName --runtime "java|11|Java SE|11"
- name: Create a web app with a Java 11 runtime using ':' delimiter.
text: >
az webapp create -g MyResourceGroup -p MyPlan -n MyUniqueAppName --runtime "java:11:Java SE:11"
- name: Create a web app with a NodeJS 10.14 runtime and deployed from a local git repository.
text: >
az webapp create -g MyResourceGroup -p MyPlan -n MyUniqueAppName --runtime "node|10.14" --deployment-local-git
az webapp create -g MyResourceGroup -p MyPlan -n MyUniqueAppName --runtime "node|12LTS" --deployment-local-git
- name: Create a web app with an image from DockerHub.
text: >
az webapp create -g MyResourceGroup -p MyPlan -n MyUniqueAppName -i nginx
Expand Down Expand Up @@ -1821,6 +1821,11 @@
short-summary: List available built-in stacks which can be used for web apps.
"""

helps['functionapp list-runtimes'] = """
type: command
short-summary: List available built-in stacks which can be used for function apps.
"""

helps['webapp log'] = """
type: group
short-summary: Manage web app logs.
Expand Down Expand Up @@ -2010,7 +2015,7 @@
- name: Create a web app with a specified name
text: >
az webapp up -n MyUniqueAppName
- name: Create a web app with a specified name and a Java 11 runtime using '|' delimiter
- name: Create a web app with a specified name and a Java 11 runtime using '|' delimiter (not recommended for powershell; use the ":" delimiter instead)
text: >
az webapp up -n MyUniqueAppName --runtime "java|11|Java SE|11"
- name: Create a web app with a specified name and a Java 11 runtime using ':' delimiter
Expand Down
Loading

0 comments on commit 45ef11f

Please sign in to comment.