Skip to content

Commit

Permalink
Merge pull request #360 from dannysongg/enable-onedeploy
Browse files Browse the repository at this point in the history
Migrate webapps-deploy to OneDeploy
  • Loading branch information
sgollapudi77 committed Oct 9, 2023
2 parents 99c0cca + d3a151f commit 3dc06f7
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 44 deletions.
12 changes: 12 additions & 0 deletions action.yml
Expand Up @@ -28,6 +28,18 @@ inputs:
resource-group-name:
description: 'Enter the resource group name of the web app'
required: false
type:
description: 'Enter deployment type (JAR, WAR, EAR, ZIP, Static)'
required: false
target-path:
description: "Target path in the web app. For ex. '/home/site/wwwroot'"
required: false
clean:
description: 'Delete existing files target directory before deploying'
required: false
restart:
description: 'Restart the app service after deployment'
required: false

outputs:
webapp-url:
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "webapps-deploy",
"version": "2.0.0",
"version": "3.0.0",
"description": "Deploy web apps and containerized web apps to Azure",
"main": "lib/main.js",
"scripts": {
Expand Down Expand Up @@ -34,7 +34,7 @@
"@actions/core": "^1.10.0",
"@actions/github": "^4.0.0",
"actions-secret-parser": "^1.0.4",
"azure-actions-appservice-rest": "^1.3.10",
"azure-actions-appservice-rest": "^1.3.13",
"azure-actions-utility": "^1.0.3",
"azure-actions-webclient": "^1.1.1"
}
Expand Down
71 changes: 39 additions & 32 deletions src/DeploymentProvider/Providers/WebAppDeploymentProvider.ts
Expand Up @@ -13,44 +13,51 @@ export class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider {
let appPackage: Package = this.actionParams.package;
let webPackage = appPackage.getPath();

const validTypes = ["war", "jar", "ear", "zip", "static"];

// kudu warm up
await this.kuduServiceUtility.warmpUp();

let packageType = appPackage.getPackageType();

switch(packageType){
case PackageType.war:
core.debug("Initiated deployment via kudu service for webapp war package : "+ webPackage);
var warName = utility.getFileNameFromPath(webPackage, ".war");
this.deploymentID = await this.kuduServiceUtility.deployUsingWarDeploy(webPackage,
{ slotName: this.actionParams.slotName , commitMessage: this.actionParams.commitMessage }, warName);
break;

case PackageType.jar:
core.debug("Initiated deployment via kudu service for webapp jar package : "+ webPackage);
let folderPath = await utility.generateTemporaryFolderForDeployment(false, webPackage, PackageType.jar);
let output = await utility.archiveFolderForDeployment(false, folderPath);
webPackage = output.webDeployPkg;
this.deploymentID = await this.kuduServiceUtility.deployUsingZipDeploy(webPackage, { slotName: this.actionParams.slotName , commitMessage:this.actionParams.commitMessage });
break;

case PackageType.folder:
let tempPackagePath = utility.generateTemporaryFolderOrZipPath(`${process.env.RUNNER_TEMP}`, false);
webPackage = await zipUtility.archiveFolder(webPackage, "", tempPackagePath) as string;
core.debug("Compressed folder into zip " + webPackage);
core.debug("Initiated deployment via kudu service for webapp package : "+ webPackage);
this.deploymentID = await this.kuduServiceUtility.deployUsingZipDeploy(webPackage, { slotName: this.actionParams.slotName, commitMessage: this.actionParams.commitMessage });
break;

case PackageType.zip:
core.debug("Initiated deployment via kudu service for webapp package : "+ webPackage);
this.deploymentID = await this.kuduServiceUtility.deployUsingZipDeploy(webPackage, { slotName: this.actionParams.slotName , commitMessage: this.actionParams.commitMessage});
break;
// If provided, type paramater takes precidence over file package type
if (this.actionParams.type != null && validTypes.includes(this.actionParams.type.toLowerCase())) {
core.debug("Initiated deployment via kudu service for webapp" + this.actionParams.type + "package : "+ webPackage);
}

default:
throw new Error('Invalid App Service package or folder path provided: ' + webPackage);
else {
// Retains the old behavior of determining the package type from the file extension if valid type is not defined
let packageType = appPackage.getPackageType();
switch(packageType){
case PackageType.war:
core.debug("Initiated deployment via kudu service for webapp war package : "+ webPackage);
this.actionParams.type = "war";
break;

case PackageType.jar:
core.debug("Initiated deployment via kudu service for webapp jar package : "+ webPackage);
this.actionParams.type = "jar";
break;

case PackageType.folder:
let tempPackagePath = utility.generateTemporaryFolderOrZipPath(`${process.env.RUNNER_TEMP}`, false);
webPackage = await zipUtility.archiveFolder(webPackage, "", tempPackagePath) as string;
core.debug("Compressed folder into zip " + webPackage);
core.debug("Initiated deployment via kudu service for webapp package : "+ webPackage);
this.actionParams.type = "zip";
break;

case PackageType.zip:
core.debug("Initiated deployment via kudu service for webapp zip package : "+ webPackage);
this.actionParams.type = "zip";
break;

default:
throw new Error('Invalid App Service package: ' + webPackage + ' or type provided: ' + this.actionParams.type);
}
}

this.deploymentID = await this.kuduServiceUtility.deployUsingOneDeploy(webPackage, { slotName: this.actionParams.slotName, commitMessage:this.actionParams.commitMessage },
this.actionParams.targetPath, this.actionParams.type, this.actionParams.clean, this.actionParams.restart);

// updating startup command
if(!!this.actionParams.startupCommand) {
await this.updateStartupCommand();
Expand Down
33 changes: 32 additions & 1 deletion src/actionparameters.ts
Expand Up @@ -36,6 +36,12 @@ export class ActionParameters {
private _isLinux: boolean;
private _commitMessage: string;

// Used only for OneDeploy
private _type: string;
private _targetPath: string;
private _clean: string;
private _restart: string;

private constructor(endpoint: IAuthorizer) {
this._publishProfileContent = core.getInput('publish-profile');
this._appName = core.getInput('app-name');
Expand All @@ -50,6 +56,12 @@ export class ActionParameters {
*/
this._commitMessage = github.context.eventName === 'push' ? github.context.payload.head_commit.message.slice(0, 1000) : "";
this._endpoint = endpoint;

// Used only for OneDeploy
this._type = core.getInput('type');
this._targetPath = core.getInput('target-path');
this._clean = core.getInput('clean');
this._restart = core.getInput('restart');
}

public static getActionParams(endpoint?: IAuthorizer) {
Expand Down Expand Up @@ -143,4 +155,23 @@ export class ActionParameters {
return this._multiContainerConfigFile;
}

}
public get type() {
return this._type;
}

public set type(type:string) {
this._type = type;
}

public get targetPath() {
return this._targetPath;
}

public get clean() {
return this._clean;
}

public get restart() {
return this._restart;
}
}

0 comments on commit 3dc06f7

Please sign in to comment.