Skip to content

Commit

Permalink
adding support to generate web.config file for go application in app … (
Browse files Browse the repository at this point in the history
#6515)

* 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
  • Loading branch information
hililh authored Feb 26, 2018
1 parent 5933117 commit 9d43978
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
var applyFileTransformFlag = taskParams.JSONFiles.length != 0 || taskParams.XmlTransformation || taskParams.XmlVariableSubstitution;
if (applyFileTransformFlag || taskParams.GenerateWebConfig) {
Expand All @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions Tasks/AzureRmWebAppDeployment/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"version": {
"Major": 3,
"Minor": 3,
"Patch": 42
"Patch": 43
},
"releaseNotes": "What's new in Version 3.0: <br/>&nbsp;&nbsp;Supports File Transformations (XDT) <br/>&nbsp;&nbsp;Supports Variable Substitutions(XML, JSON) <br/>Click [here](https://aka.ms/azurermwebdeployreadme) for more Information.",
"minimumAgentVersion": "2.104.1",
Expand Down Expand Up @@ -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'.<br />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'.<br />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 <folder_name>.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 <DependentUpon> tag for each config in the csproj file and rebuild. ",
Expand Down Expand Up @@ -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"
}
}
5 changes: 3 additions & 2 deletions Tasks/AzureRmWebAppDeployment/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"version": {
"Major": 3,
"Minor": 3,
"Patch": 42
"Patch": 43
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.104.1",
Expand Down Expand Up @@ -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"
}
}
13 changes: 13 additions & 0 deletions Tasks/Common/webdeployment-common/WebConfigTemplates/go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated web.config for Microsoft Azure. Remove this comment to prevent
modifications being overwritten when publishing the project.
-->
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="{GoExeFilePath}" startupTimeLimit="60">
</httpPlatform>
</system.webServer>
</configuration>
18 changes: 14 additions & 4 deletions Tasks/Common/webdeployment-common/webconfigutil.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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': ''
}
};

Expand All @@ -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']) {
Expand All @@ -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"));
Expand Down

0 comments on commit 9d43978

Please sign in to comment.