Skip to content

Commit edb6b8d

Browse files
authored
Users/hiyada/war deployment (#6579) (#6610)
* resolving msdeploy for war files * retrying three times for war files while calling the web app in between. * resolving comments * resolving comments * removing duplicate file * initializing variables only once insted of in retry.
1 parent 55959a0 commit edb6b8d

File tree

5 files changed

+90
-12
lines changed

5 files changed

+90
-12
lines changed

Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson

+2-1
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,6 @@
210210
"loc.messages.UpdatedAppServiceConfigurationSettings": "Updated App Service Configuration settings.",
211211
"loc.messages.UpdatingAppServiceApplicationSettings": "Updating App Service Application settings. Data: %s",
212212
"loc.messages.UpdatedAppServiceApplicationSettings": "Updated App Service Application settings and Kudu Application settings.",
213-
"loc.messages.MultipleResourceGroupFoundForAppService": "Multiple resource group found for App Service '%s'."
213+
"loc.messages.MultipleResourceGroupFoundForAppService": "Multiple resource group found for App Service '%s'.",
214+
"loc.messages.WarDeploymentRetry": "Retrying war file deployment as it did not expand successfully earlier."
214215
}

Tasks/AzureRmWebAppDeployment/azurermwebappdeployment.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TaskParameters, TaskParametersUtility } from './operations/TaskParamete
1313
import { FileTransformsUtility } from './operations/FileTransformsUtility';
1414
import * as ParameterParser from './parameterparser'
1515
import { addReleaseAnnotation } from './operations/ReleaseAnnotationUtility';
16+
import { DeployWar } from './operations/WarDeploymentUtilities';
1617

1718
var packageUtility = require('webdeployment-common/packageUtility.js');
1819

@@ -87,9 +88,14 @@ async function main() {
8788
}
8889

8990
var msDeployPublishingProfile = await appServiceUtility.getWebDeployPublishingProfile();
90-
await msDeploy.DeployUsingMSDeploy(webPackage, taskParams.WebAppName, msDeployPublishingProfile, taskParams.RemoveAdditionalFilesFlag,
91+
if (webPackage.toString().toLowerCase().endsWith('.war')) {
92+
await DeployWar(webPackage, taskParams, msDeployPublishingProfile, kuduService, appServiceUtility);
93+
}
94+
else {
95+
await msDeploy.DeployUsingMSDeploy(webPackage, taskParams.WebAppName, msDeployPublishingProfile, taskParams.RemoveAdditionalFilesFlag,
9196
taskParams.ExcludeFilesFromAppDataFlag, taskParams.TakeAppOfflineFlag, taskParams.VirtualApplication, taskParams.SetParametersFile,
9297
taskParams.AdditionalArguments, isFolderBasedDeployment, taskParams.UseWebDeploy);
98+
}
9399
}
94100
else {
95101
tl.debug("Initiated deployment via kudu service for webapp package : ");
@@ -102,7 +108,7 @@ async function main() {
102108
var customApplicationSettings = ParameterParser.parse(taskParams.AppSettings);
103109
await appServiceUtility.updateAndMonitorAppSettings(customApplicationSettings);
104110
}
105-
111+
106112
if(taskParams.ConfigurationSettings) {
107113
var customApplicationSettings = ParameterParser.parse(taskParams.ConfigurationSettings);
108114
await appServiceUtility.updateConfigurationSettings(customApplicationSettings);
@@ -113,7 +119,7 @@ async function main() {
113119
}
114120

115121
if(taskParams.ScriptType) {
116-
await kuduServiceUtility.runPostDeploymentScript(taskParams, virtualApplicationPath);
122+
await kuduServiceUtility.runPostDeploymentScript(taskParams, virtualApplicationPath);
117123
}
118124

119125
await appServiceUtility.updateScmTypeAndConfigurationDetails();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import tl = require('vsts-task-lib/task');
2+
import fs = require('fs');
3+
import path = require('path');
4+
import { Kudu } from 'azure-arm-rest/azure-arm-app-service-kudu';
5+
import { AzureAppServiceUtility } from './AzureAppServiceUtility';
6+
import { TaskParameters } from './TaskParameters';
7+
import { sleepFor } from 'azure-arm-rest/webClient';
8+
9+
var msDeploy = require('webdeployment-common/deployusingmsdeploy.js');
10+
11+
export async function DeployWar(webPackage, taskParams: TaskParameters, msDeployPublishingProfile, kuduService: Kudu, appServiceUtility: AzureAppServiceUtility): Promise<void> {
12+
// get list of files before deploying to the web app.
13+
var listOfFilesBeforeDeployment: any = await kuduService.listDir('/site/wwwroot/webapps/');
14+
tl.debug("Listing file structure of webapps folder before deployment starts => " + JSON.stringify(listOfFilesBeforeDeployment));
15+
16+
// Strip package path and only keep the package name.
17+
var warFileName = path.basename(webPackage).split('.war')[0];
18+
19+
// Find if directory with same name as war file, existed before deployment
20+
var directoryWithSameNameBeforeDeployment;
21+
if (listOfFilesBeforeDeployment) {
22+
listOfFilesBeforeDeployment.some(item => {
23+
if (item.name == warFileName && item.mime == "inode/directory") {
24+
directoryWithSameNameBeforeDeployment = item;
25+
return true;
26+
}
27+
return false;
28+
});
29+
}
30+
31+
var retryCount = 3;
32+
while (retryCount > 0) {
33+
await msDeploy.DeployUsingMSDeploy(webPackage, taskParams.WebAppName, msDeployPublishingProfile, taskParams.RemoveAdditionalFilesFlag,
34+
taskParams.ExcludeFilesFromAppDataFlag, taskParams.TakeAppOfflineFlag, taskParams.VirtualApplication, taskParams.SetParametersFile,
35+
taskParams.AdditionalArguments, false, taskParams.UseWebDeploy);
36+
37+
// verify if the war file has expanded
38+
// if not expanded, deploy using msdeploy once more, to make it work.
39+
var hasWarExpandedSuccessfully: boolean = await HasWarExpandedSuccessfully(kuduService, directoryWithSameNameBeforeDeployment, warFileName, appServiceUtility);
40+
if (!hasWarExpandedSuccessfully) {
41+
console.log(tl.loc("WarDeploymentRetry"));
42+
// If the war file is exactly same, MSDeploy doesn't update the war file in webapp.
43+
// So by changing ModifiedTime, we ensure it will be updated.
44+
var currentTime = new Date(Date.now());
45+
var modifiedTime = new Date(Date.now());
46+
fs.utimesSync(webPackage, currentTime, modifiedTime);
47+
}
48+
else {
49+
break;
50+
}
51+
52+
retryCount--;
53+
}
54+
}
55+
56+
export async function HasWarExpandedSuccessfully(kuduService: Kudu, directoryWithSameNameBeforeDeployment: any, warFileName: string, appServiceUtility: AzureAppServiceUtility): Promise<boolean> {
57+
// Waiting for war to expand
58+
await sleepFor(10);
59+
60+
// do a get call on the target web app.
61+
await appServiceUtility.pingApplication();
62+
var filesAfterDeployment: any = await kuduService.listDir('/site/wwwroot/webapps/');
63+
tl.debug("Listing file structure of webapps folder after deployment has completed => " + JSON.stringify(filesAfterDeployment));
64+
65+
// Verify if the content of that war file has successfully expanded. This is can be concluded if
66+
// directory with same name as war file exists after deployment and if it existed before deployment, then the directory should contain content of new war file
67+
// which can be concluded if the modified time of the directory has changed.
68+
return filesAfterDeployment.some(item => { return item.name == warFileName && item.mime == "inode/directory" && (!directoryWithSameNameBeforeDeployment || item.mtime != directoryWithSameNameBeforeDeployment.mtime) });
69+
}

Tasks/AzureRmWebAppDeployment/task.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"version": {
1717
"Major": 3,
1818
"Minor": 3,
19-
"Patch": 41
19+
"Patch": 42
2020
},
2121
"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.",
2222
"minimumAgentVersion": "2.104.1",
@@ -138,7 +138,7 @@
138138
"EditableOptions": "false",
139139
"PopulateDefaultValue": "true"
140140
},
141-
"helpMarkDown": "App Service on Linux offers two different options to publish your application <br/> Custom image deployment or App deployment with a built-in platform image. [Learn More](https://go.microsoft.com/fwlink/?linkid=862490)",
141+
"helpMarkDown": "App Service on Linux offers two different options to publish your application <br/> Custom image deployment or App deployment with a built-in platform image. [Learn More](https://go.microsoft.com/fwlink/?linkid=862490)",
142142
"visibleRule": "WebAppKind = applinux || WebAppKind = linux"
143143
},
144144
{
@@ -570,7 +570,7 @@
570570
"endpointId": "$(ConnectedServiceName)",
571571
"dataSourceName": "AzureContainerRegistryTags",
572572
"parameters": {
573-
"AzureContainerRegistryLoginServer": "$(AzureContainerRegistryLoginServer)",
573+
"AzureContainerRegistryLoginServer": "$(AzureContainerRegistryLoginServer)",
574574
"AzureContainerRegistryImage": "$(AzureContainerRegistryImage)"
575575
}
576576
},
@@ -601,14 +601,14 @@
601601
"endpointId": "$(RegistryConnectedServiceName)",
602602
"endpointUrl": "{{endpoint.url}}v2/_catalog",
603603
"resultSelector": "jsonpath:$.repositories[*]",
604-
"authorizationHeader": "Basic {{ #base64 endpoint.username \":\" endpoint.password }}"
604+
"authorizationHeader": "Basic {{ #base64 endpoint.username \":\" endpoint.password }}"
605605
},
606606
{
607607
"target": "PrivateRegistryTag",
608608
"endpointId": "$(RegistryConnectedServiceName)",
609609
"endpointUrl": "{{endpoint.url}}v2/$(PrivateRegistryImage)/tags/list",
610610
"resultSelector": "jsonpath:$.tags[*]",
611-
"authorizationHeader": "Basic {{ #base64 endpoint.username \":\" endpoint.password }}"
611+
"authorizationHeader": "Basic {{ #base64 endpoint.username \":\" endpoint.password }}"
612612
}
613613
],
614614
"instanceNameFormat": "Azure App Service Deploy: $(WebAppName)",
@@ -739,6 +739,7 @@
739739
"UpdatedAppServiceConfigurationSettings": "Updated App Service Configuration settings.",
740740
"UpdatingAppServiceApplicationSettings": "Updating App Service Application settings. Data: %s",
741741
"UpdatedAppServiceApplicationSettings": "Updated App Service Application settings and Kudu Application settings.",
742-
"MultipleResourceGroupFoundForAppService": "Multiple resource group found for App Service '%s'."
742+
"MultipleResourceGroupFoundForAppService": "Multiple resource group found for App Service '%s'.",
743+
"WarDeploymentRetry": "Retrying war file deployment as it did not expand successfully earlier."
743744
}
744745
}

Tasks/AzureRmWebAppDeployment/task.loc.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"version": {
1717
"Major": 3,
1818
"Minor": 3,
19-
"Patch": 41
19+
"Patch": 42
2020
},
2121
"releaseNotes": "ms-resource:loc.releaseNotes",
2222
"minimumAgentVersion": "2.104.1",
@@ -751,6 +751,7 @@
751751
"UpdatedAppServiceConfigurationSettings": "ms-resource:loc.messages.UpdatedAppServiceConfigurationSettings",
752752
"UpdatingAppServiceApplicationSettings": "ms-resource:loc.messages.UpdatingAppServiceApplicationSettings",
753753
"UpdatedAppServiceApplicationSettings": "ms-resource:loc.messages.UpdatedAppServiceApplicationSettings",
754-
"MultipleResourceGroupFoundForAppService": "ms-resource:loc.messages.MultipleResourceGroupFoundForAppService"
754+
"MultipleResourceGroupFoundForAppService": "ms-resource:loc.messages.MultipleResourceGroupFoundForAppService",
755+
"WarDeploymentRetry": "ms-resource:loc.messages.WarDeploymentRetry"
755756
}
756757
}

0 commit comments

Comments
 (0)