-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 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.
- Loading branch information
Showing
5 changed files
with
90 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Tasks/AzureRmWebAppDeployment/operations/WarDeploymentUtilities.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import tl = require('vsts-task-lib/task'); | ||
import fs = require('fs'); | ||
import path = require('path'); | ||
import { Kudu } from 'azure-arm-rest/azure-arm-app-service-kudu'; | ||
import { AzureAppServiceUtility } from './AzureAppServiceUtility'; | ||
import { TaskParameters } from './TaskParameters'; | ||
import { sleepFor } from 'azure-arm-rest/webClient'; | ||
|
||
var msDeploy = require('webdeployment-common/deployusingmsdeploy.js'); | ||
|
||
export async function DeployWar(webPackage, taskParams: TaskParameters, msDeployPublishingProfile, kuduService: Kudu, appServiceUtility: AzureAppServiceUtility): Promise<void> { | ||
// get list of files before deploying to the web app. | ||
var listOfFilesBeforeDeployment: any = await kuduService.listDir('/site/wwwroot/webapps/'); | ||
tl.debug("Listing file structure of webapps folder before deployment starts => " + JSON.stringify(listOfFilesBeforeDeployment)); | ||
|
||
// Strip package path and only keep the package name. | ||
var warFileName = path.basename(webPackage).split('.war')[0]; | ||
|
||
// Find if directory with same name as war file, existed before deployment | ||
var directoryWithSameNameBeforeDeployment; | ||
if (listOfFilesBeforeDeployment) { | ||
listOfFilesBeforeDeployment.some(item => { | ||
if (item.name == warFileName && item.mime == "inode/directory") { | ||
directoryWithSameNameBeforeDeployment = item; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} | ||
|
||
var retryCount = 3; | ||
while (retryCount > 0) { | ||
await msDeploy.DeployUsingMSDeploy(webPackage, taskParams.WebAppName, msDeployPublishingProfile, taskParams.RemoveAdditionalFilesFlag, | ||
taskParams.ExcludeFilesFromAppDataFlag, taskParams.TakeAppOfflineFlag, taskParams.VirtualApplication, taskParams.SetParametersFile, | ||
taskParams.AdditionalArguments, false, taskParams.UseWebDeploy); | ||
|
||
// verify if the war file has expanded | ||
// if not expanded, deploy using msdeploy once more, to make it work. | ||
var hasWarExpandedSuccessfully: boolean = await HasWarExpandedSuccessfully(kuduService, directoryWithSameNameBeforeDeployment, warFileName, appServiceUtility); | ||
if (!hasWarExpandedSuccessfully) { | ||
console.log(tl.loc("WarDeploymentRetry")); | ||
// If the war file is exactly same, MSDeploy doesn't update the war file in webapp. | ||
// So by changing ModifiedTime, we ensure it will be updated. | ||
var currentTime = new Date(Date.now()); | ||
var modifiedTime = new Date(Date.now()); | ||
fs.utimesSync(webPackage, currentTime, modifiedTime); | ||
} | ||
else { | ||
break; | ||
} | ||
|
||
retryCount--; | ||
} | ||
} | ||
|
||
export async function HasWarExpandedSuccessfully(kuduService: Kudu, directoryWithSameNameBeforeDeployment: any, warFileName: string, appServiceUtility: AzureAppServiceUtility): Promise<boolean> { | ||
// Waiting for war to expand | ||
await sleepFor(10); | ||
|
||
// do a get call on the target web app. | ||
await appServiceUtility.pingApplication(); | ||
var filesAfterDeployment: any = await kuduService.listDir('/site/wwwroot/webapps/'); | ||
tl.debug("Listing file structure of webapps folder after deployment has completed => " + JSON.stringify(filesAfterDeployment)); | ||
|
||
// Verify if the content of that war file has successfully expanded. This is can be concluded if | ||
// 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 | ||
// which can be concluded if the modified time of the directory has changed. | ||
return filesAfterDeployment.some(item => { return item.name == warFileName && item.mime == "inode/directory" && (!directoryWithSameNameBeforeDeployment || item.mtime != directoryWithSameNameBeforeDeployment.mtime) }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters