From 9d43978927e99ac3a363bb72435b8b39252a409c Mon Sep 17 00:00:00 2001 From: hililh Date: Mon, 26 Feb 2018 16:30:16 +0530 Subject: [PATCH] =?UTF-8?q?adding=20support=20to=20generate=20web.config?= =?UTF-8?q?=20file=20for=20go=20application=20in=20app=20=E2=80=A6=20(#651?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adding support to generate web.config file for go application in app service deploy task * removing Azure Web app specific file path from the web.config and accept this as a process parameter * fixing review comments * moving rootDirectoryPath to AzureWebAppDeployment task instead of common * adding the check to validate GoExeFileName --- .../resources.resjson/en-US/resources.resjson | 3 ++- .../operations/FileTransformsUtility.ts | 5 ++++- Tasks/AzureRmWebAppDeployment/task.json | 7 ++++--- Tasks/AzureRmWebAppDeployment/task.loc.json | 5 +++-- .../webdeployment-common/WebConfigTemplates/go | 13 +++++++++++++ .../webdeployment-common/webconfigutil.ts | 18 ++++++++++++++---- 6 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 Tasks/Common/webdeployment-common/WebConfigTemplates/go diff --git a/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson b/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson index fa0a8634d727..ac9de37f28d5 100644 --- a/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson @@ -213,5 +213,6 @@ "loc.messages.MultipleResourceGroupFoundForAppService": "Multiple resource group found for App Service '%s'.", "loc.messages.PackageDeploymentUsingZipDeployFailed": "Package deployment using ZIP Deploy failed. Refer logs for more details.", "loc.messages.PackageDeploymentInitiated": "Package deployment using ZIP Deploy initiated.", - "loc.messages.FailedToGetDeploymentLogs": "Failed to get deployment logs. Error: %s" + "loc.messages.FailedToGetDeploymentLogs": "Failed to get deployment logs. Error: %s", + "loc.messages.GoExeNameNotPresent": "Go exe name is not present" } \ No newline at end of file diff --git a/Tasks/AzureRmWebAppDeployment/operations/FileTransformsUtility.ts b/Tasks/AzureRmWebAppDeployment/operations/FileTransformsUtility.ts index 886b3b794239..d13b8ce88700 100644 --- a/Tasks/AzureRmWebAppDeployment/operations/FileTransformsUtility.ts +++ b/Tasks/AzureRmWebAppDeployment/operations/FileTransformsUtility.ts @@ -7,6 +7,9 @@ var fileTransformationsUtility = require('webdeployment-common/fileTransformatio var generateWebConfigUtil = require('webdeployment-common/webconfigutil.js'); export class FileTransformsUtility { + + private static rootDirectoryPath: string = "D:\\home\\site\\wwwroot"; + public static async applyTransformations(webPackage: string, taskParams: TaskParameters): Promise { var applyFileTransformFlag = taskParams.JSONFiles.length != 0 || taskParams.XmlTransformation || taskParams.XmlVariableSubstitution; if (applyFileTransformFlag || taskParams.GenerateWebConfig) { @@ -15,7 +18,7 @@ export class FileTransformsUtility { if (taskParams.GenerateWebConfig) { tl.debug('parsing web.config parameters'); var webConfigParameters = parse(taskParams.WebConfigParameters); - generateWebConfigUtil.addWebConfigFile(folderPath, webConfigParameters); + generateWebConfigUtil.addWebConfigFile(folderPath, webConfigParameters, this.rootDirectoryPath); } if (applyFileTransformFlag) { diff --git a/Tasks/AzureRmWebAppDeployment/task.json b/Tasks/AzureRmWebAppDeployment/task.json index 1e3571772524..2bb9f4e151b6 100644 --- a/Tasks/AzureRmWebAppDeployment/task.json +++ b/Tasks/AzureRmWebAppDeployment/task.json @@ -16,7 +16,7 @@ "version": { "Major": 3, "Minor": 3, - "Patch": 42 + "Patch": 43 }, "releaseNotes": "What's new in Version 3.0:
  Supports File Transformations (XDT)
  Supports Variable Substitutions(XML, JSON)
Click [here](https://aka.ms/azurermwebdeployreadme) for more Information.", "minimumAgentVersion": "2.104.1", @@ -694,7 +694,7 @@ "ScriptStatusTimeout": "Unable to fetch script status due to timeout.", "PollingForFileTimeOut": "Unable to fetch script status due to timeout. You can increase the timeout limit by setting 'appservicedeploy.retrytimeout' variable to number of minutes required.", "InvalidPollOption": "Invalid polling option provided: %s.", - "MissingAppTypeWebConfigParameters": "Attribute '-appType' is missing in the Web.config parameters. Valid values for '-appType' are: 'python_Bottle', 'python_Django', 'python_Flask' and 'node'.
For example, '-appType python_Bottle' (sans-quotes) in case of Python Bottle framework..", + "MissingAppTypeWebConfigParameters": "Attribute '-appType' is missing in the Web.config parameters. Valid values for '-appType' are: 'python_Bottle', 'python_Django', 'python_Flask', 'node' and 'Go'.
For example, '-appType python_Bottle' (sans-quotes) in case of Python Bottle framework..", "AutoDetectDjangoSettingsFailed": "Unable to detect DJANGO_SETTINGS_MODULE 'settings.py' file path. Ensure that the 'settings.py' file exists or provide the correct path in Web.config parameter input in the following format '-DJANGO_SETTINGS_MODULE .settings'", "FailedToApplyTransformation": "Unable to apply transformation for the given package. Verify the following.", "FailedToApplyTransformationReason1": "1. Whether the Transformation is already applied for the MSBuild generated package during build. If yes, remove the tag for each config in the csproj file and rebuild. ", @@ -742,6 +742,7 @@ "MultipleResourceGroupFoundForAppService": "Multiple resource group found for App Service '%s'.", "PackageDeploymentUsingZipDeployFailed": "Package deployment using ZIP Deploy failed. Refer logs for more details.", "PackageDeploymentInitiated": "Package deployment using ZIP Deploy initiated.", - "FailedToGetDeploymentLogs": "Failed to get deployment logs. Error: %s" + "FailedToGetDeploymentLogs": "Failed to get deployment logs. Error: %s", + "GoExeNameNotPresent": "Go exe name is not present" } } diff --git a/Tasks/AzureRmWebAppDeployment/task.loc.json b/Tasks/AzureRmWebAppDeployment/task.loc.json index 4728b3bf7718..3960d684e84e 100644 --- a/Tasks/AzureRmWebAppDeployment/task.loc.json +++ b/Tasks/AzureRmWebAppDeployment/task.loc.json @@ -16,7 +16,7 @@ "version": { "Major": 3, "Minor": 3, - "Patch": 42 + "Patch": 43 }, "releaseNotes": "ms-resource:loc.releaseNotes", "minimumAgentVersion": "2.104.1", @@ -754,6 +754,7 @@ "MultipleResourceGroupFoundForAppService": "ms-resource:loc.messages.MultipleResourceGroupFoundForAppService", "PackageDeploymentUsingZipDeployFailed": "ms-resource:loc.messages.PackageDeploymentUsingZipDeployFailed", "PackageDeploymentInitiated": "ms-resource:loc.messages.PackageDeploymentInitiated", - "FailedToGetDeploymentLogs": "ms-resource:loc.messages.FailedToGetDeploymentLogs" + "FailedToGetDeploymentLogs": "ms-resource:loc.messages.FailedToGetDeploymentLogs", + "GoExeNameNotPresent": "ms-resource:loc.messages.GoExeNameNotPresent" } } \ No newline at end of file diff --git a/Tasks/Common/webdeployment-common/WebConfigTemplates/go b/Tasks/Common/webdeployment-common/WebConfigTemplates/go new file mode 100644 index 000000000000..9aaaf22b5302 --- /dev/null +++ b/Tasks/Common/webdeployment-common/WebConfigTemplates/go @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/Tasks/Common/webdeployment-common/webconfigutil.ts b/Tasks/Common/webdeployment-common/webconfigutil.ts index 478d0bee525a..fd06fdef70e0 100644 --- a/Tasks/Common/webdeployment-common/webconfigutil.ts +++ b/Tasks/Common/webdeployment-common/webconfigutil.ts @@ -1,6 +1,7 @@ import tl = require('vsts-task-lib/task'); import fs = require('fs'); import path = require('path'); +import util = require('util'); export function generateWebConfigFile(webConfigTargetPath: string, appType: string, substitutionParameters: any) { // Get the template path for the given appType @@ -40,6 +41,9 @@ function addMissingParametersValue(appType: string, webConfigParameters) { 'PYTHON_PATH': 'D:\\home\\python353x86\\python.exe', 'PYTHON_WFASTCGI_PATH': 'D:\\home\\python353x86\\wfastcgi.py', 'STATIC_FOLDER_PATH': 'static' + }, + 'Go': { + 'GoExeFilePath': '' } }; @@ -57,12 +61,12 @@ function addMissingParametersValue(appType: string, webConfigParameters) { } return resultAppTypeParams; } -export function addWebConfigFile(folderPath: any, webConfigParameters, rootDirectoryPath?: string) { +export function addWebConfigFile(folderPath: any, webConfigParameters, rootDirectoryPath: string) { //Generate the web.config file if it does not already exist. var webConfigPath = path.join(folderPath, "web.config"); if (!tl.exist(webConfigPath)) { try { - var supportedAppTypes = ['node', 'python_Bottle', 'python_Django', 'python_Flask'] + var supportedAppTypes = ['node', 'python_Bottle', 'python_Django', 'python_Flask', 'Go'] // Create web.config tl.debug('web.config file does not exist. Generating.'); if(!webConfigParameters['appType']) { @@ -77,14 +81,20 @@ export function addWebConfigFile(folderPath: any, webConfigParameters, rootDirec delete webConfigParameters['appType']; var selectedAppTypeParams = addMissingParametersValue(appType, webConfigParameters); - if(appType != "node") { - rootDirectoryPath = "D:\\home\\" + (rootDirectoryPath ? rootDirectoryPath : "site\\wwwroot"); + if(appType.startsWith("python")) { tl.debug('Root Directory path to be set on web.config: ' + rootDirectoryPath); selectedAppTypeParams['KUDU_WORKING_DIRECTORY'] = rootDirectoryPath; if(appType === 'python_Django' && webConfigParameters['DJANGO_SETTINGS_MODULE'].value === '') { tl.debug('Auto detecting settings.py to set DJANGO_SETTINGS_MODULE...'); selectedAppTypeParams['DJANGO_SETTINGS_MODULE'] = getDjangoSettingsFile(folderPath); } + } else if(appType == 'Go') { + if (util.isNullOrUndefined(webConfigParameters['GoExeFileName']) + || util.isNullOrUndefined(webConfigParameters['GoExeFileName'].value) + || webConfigParameters['GoExeFileName'].value.length <=0) { + throw Error(tl.loc('GoExeNameNotPresent')); + } + selectedAppTypeParams['GoExeFilePath'] = rootDirectoryPath + "\\" + webConfigParameters['GoExeFileName'].value; } generateWebConfigFile(webConfigPath, appType, selectedAppTypeParams); console.log(tl.loc("SuccessfullyGeneratedWebConfig"));