-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for .NETCORE #61
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
NODE_VERSION_DEFAULT = "8.1" | ||
NETCORE_VERSION_DEFAULT = "2.0" | ||
# 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'] | ||
NODE_RUNTIME_NAME = "node" | ||
NETCORE_RUNTIME_NAME = "dotnetcore" | ||
OS_DEFAULT = "Windows" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,13 @@ | |
import zipfile | ||
from azure.cli.core.commands.client_factory import get_mgmt_service_client | ||
from azure.mgmt.resource.resources.models import ResourceGroup | ||
from ._constants import ( | ||
NETCORE_VERSION_DEFAULT, | ||
NETCORE_VERSIONS, | ||
NODE_VERSION_DEFAULT, | ||
NODE_VERSIONS, | ||
NETCORE_RUNTIME_NAME, | ||
NODE_RUNTIME_NAME) | ||
|
||
|
||
def _resource_client_factory(cli_ctx, **_): | ||
|
@@ -19,7 +26,7 @@ def web_client_factory(cli_ctx, **_): | |
return get_mgmt_service_client(cli_ctx, WebSiteManagementClient) | ||
|
||
|
||
def zip_contents_from_dir(dirPath): | ||
def zip_contents_from_dir(dirPath, lang): | ||
relroot = os.path.abspath(os.path.join(dirPath, os.pardir)) | ||
path_and_file = os.path.splitdrive(dirPath)[1] | ||
file_val = os.path.split(path_and_file)[1] | ||
|
@@ -29,29 +36,31 @@ def zip_contents_from_dir(dirPath): | |
for dirname, subdirs, files in os.walk(dirPath): | ||
# skip node_modules folder for Node apps, | ||
# since zip_deployment will perfom the build operation | ||
if 'node_modules' in subdirs: | ||
if lang.lower() == NODE_RUNTIME_NAME and 'node_modules' in subdirs: | ||
subdirs.remove('node_modules') | ||
elif lang.lower() == NETCORE_RUNTIME_NAME: | ||
if 'bin' in subdirs: | ||
subdirs.remove('bin') | ||
elif 'obj' in subdirs: | ||
subdirs.remove('obj') | ||
for filename in files: | ||
absname = os.path.abspath(os.path.join(dirname, filename)) | ||
arcname = absname[len(abs_src) + 1:] | ||
zf.write(absname, arcname) | ||
return zip_file_path | ||
|
||
|
||
def is_node_application(path): | ||
# for node application, package.json should exisit in the application root dir | ||
# if this exists we pass the path of the file to read it contents & get version | ||
package_json_file = os.path.join(path, 'package.json') | ||
if os.path.isfile(package_json_file): | ||
return package_json_file | ||
return '' | ||
|
||
|
||
def get_node_runtime_version_toSet(): | ||
version_val = "8.0" | ||
# trunc_version = float(node_version[:3]) | ||
# TODO: call the list_runtimes once there is an API that returns the supported versions | ||
return version_val | ||
def get_runtime_version_details(file_path, lang_name): | ||
version_detected = None | ||
version_to_create = None | ||
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() == NODE_RUNTIME_NAME: | ||
version_detected = parse_node_version(file_path)[0] | ||
version_to_create = detect_node_version_tocreate(version_detected) | ||
return {'detected': version_detected, 'to_create': version_to_create} | ||
|
||
|
||
def create_resource_group(cmd, rg_name, location): | ||
|
@@ -65,13 +74,15 @@ def check_resource_group_exists(cmd, rg_name): | |
return rcf.resource_groups.check_existence(rg_name) | ||
|
||
|
||
def check_resource_group_supports_linux(cmd, rg_name, location): | ||
def check_resource_group_supports_os(cmd, rg_name, location, is_linux): | ||
# get all appservice plans from RG | ||
client = web_client_factory(cmd.cli_ctx) | ||
plans = list(client.app_service_plans.list_by_resource_group(rg_name)) | ||
# filter by location & reserverd=false | ||
for item in plans: | ||
if item.location == location and not item.reserved: | ||
# for Linux if an app with reserved==False exists, ASP doesn't support Linux | ||
if is_linux and item.location == location and not item.reserved: | ||
return False | ||
elif not is_linux and item.location == location and item.reserved: | ||
return False | ||
return True | ||
|
||
|
@@ -91,3 +102,78 @@ def check_app_exists(cmd, rg_name, app_name): | |
if item.name == app_name: | ||
return True | ||
return False | ||
|
||
|
||
def get_lang_from_content(src_path): | ||
# NODE: package.json should exisit in the application root dir | ||
# NETCORE: NETCORE.csproj should exist in the root dir | ||
runtime_details_dict = dict.fromkeys(['language', 'file_loc', 'default_sku']) | ||
package_json_file = os.path.join(src_path, 'package.json') | ||
package_netcore_file = os.path.join(src_path, 'netcore.csproj') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hang on. This only works if the project is NAME netcore.csproj. It will be *.csproj, not a specific name! This can't ever work, I'm sorry. When you type "dotnet new razor" you will get a new project file named after the current folder. @panchagnula There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try:
|
||
if os.path.isfile(package_json_file): | ||
runtime_details_dict['language'] = NODE_RUNTIME_NAME | ||
runtime_details_dict['file_loc'] = package_json_file | ||
runtime_details_dict['default_sku'] = 'S1' | ||
elif os.path.isfile(package_netcore_file): | ||
runtime_details_dict['language'] = NETCORE_RUNTIME_NAME | ||
runtime_details_dict['file_loc'] = package_netcore_file | ||
runtime_details_dict['default_sku'] = 'F1' | ||
return runtime_details_dict | ||
|
||
|
||
def parse_netcore_version(file_path): | ||
import xml.etree.ElementTree as ET | ||
import re | ||
version_detected = ['0.0'] | ||
parsed_file = ET.parse(file_path) | ||
root = parsed_file.getroot() | ||
for target_ver in root.iter('TargetFramework'): | ||
version_detected = re.findall(r"\d+\.\d+", target_ver.text) | ||
# incase of multiple versions detected, return list in descending order | ||
version_detected = sorted(version_detected, key=float, reverse=True) | ||
return version_detected | ||
|
||
|
||
def parse_node_version(file_path): | ||
import json | ||
import re | ||
version_detected = ['0.0'] | ||
with open(file_path) as data_file: | ||
data = [] | ||
for d in find_key_in_json(json.load(data_file), 'node'): | ||
non_decimal = re.compile(r'[^\d.]+') | ||
# remove the string ~ or > that sometimes exists in version value | ||
c = non_decimal.sub('', d) | ||
# reduce the version to '6.0' from '6.0.0' | ||
data.append(c[:3]) | ||
version_detected = sorted(data, key=float, reverse=True) | ||
return version_detected | ||
|
||
|
||
def detect_netcore_version_tocreate(detected_ver): | ||
if detected_ver in NETCORE_VERSIONS: | ||
return detected_ver | ||
return NETCORE_VERSION_DEFAULT | ||
|
||
|
||
def detect_node_version_tocreate(detected_ver): | ||
if detected_ver in NODE_VERSIONS: | ||
return detected_ver | ||
# get major version & get the closest version from supported list | ||
major_ver = float(detected_ver.split('.')[0]) | ||
if major_ver < 4: | ||
return NODE_VERSION_DEFAULT | ||
elif major_ver >= 4 and major_ver < 6: | ||
return '4.5' | ||
elif major_ver >= 6 and major_ver < 8: | ||
return '6.9' | ||
return NODE_VERSION_DEFAULT | ||
|
||
|
||
def find_key_in_json(json_data, key): | ||
for k, v in json_data.items(): | ||
if key in k: | ||
yield v | ||
elif isinstance(v, dict): | ||
for id_val in find_key_in_json(v, key): | ||
yield id_val |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: exisit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) thanks @derekbekoe . i will have this fixed in my next PR