Skip to content

Commit

Permalink
Migrate deployments to OneDeploy
Browse files Browse the repository at this point in the history
  • Loading branch information
dannysongg committed Sep 1, 2023
1 parent 99c0cca commit 0f57d77
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 14 deletions.
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
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
32 changes: 19 additions & 13 deletions src/DeploymentProvider/Providers/WebAppDeploymentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { addAnnotation } from 'azure-actions-appservice-rest/Utilities/Annotatio
export class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider {

public async DeployWebAppStep() {
var deploymentType;
let appPackage: Package = this.actionParams.package;
let webPackage = appPackage.getPath();

Expand All @@ -20,37 +21,42 @@ export class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider {

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);
core.debug("Initiated deployment via kudu service for webapp war package : "+ webPackage);
deploymentType = "war";
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 });
deploymentType = "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.deploymentID = await this.kuduServiceUtility.deployUsingZipDeploy(webPackage, { slotName: this.actionParams.slotName, commitMessage: this.actionParams.commitMessage });
core.debug("Initiated deployment via kudu service for webapp package : "+ webPackage);
deploymentType = "zip";
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});
core.debug("Initiated deployment via kudu service for webapp zip package : "+ webPackage);
deploymentType = "zip";
break;

default:
throw new Error('Invalid App Service package or folder path provided: ' + webPackage);
if (!this.actionParams.type) {
throw new Error('Invalid App Service package or folder path provided: ' + webPackage);
}
break;
}

if (!this.actionParams.type){
this.actionParams.type = deploymentType;
}

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
35 changes: 34 additions & 1 deletion src/actionparameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ 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 +57,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 +156,24 @@ 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 0f57d77

Please sign in to comment.