Skip to content

Commit b360ed2

Browse files
authored
add onedeploy endpoint (#294)
1 parent 5de4b9b commit b360ed2

File tree

5 files changed

+114
-4
lines changed

5 files changed

+114
-4
lines changed

common-npm-packages/azure-arm-rest/azure-arm-app-service-kudu.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,41 @@ export class Kudu {
528528
}
529529
}
530530

531+
public async oneDeploy(webPackage: string, queryParameters?: Array<string>): Promise<any> {
532+
let httpRequest = new webClient.WebRequest();
533+
httpRequest.method = 'POST';
534+
httpRequest.uri = this.client.getRequestUri(`/api/publish`, queryParameters);
535+
httpRequest.body = fs.createReadStream(webPackage);
536+
let requestOptions = new webClient.WebRequestOptions();
537+
//Bydefault webclient.sendRequest retries for [500, 502, 503, 504]
538+
requestOptions.retriableStatusCodes = [500, 502, 503, 504];
539+
requestOptions.retryIntervalInSeconds = 5;
540+
try {
541+
let response = await this.client.beginRequest(httpRequest, requestOptions, 'application/octet-stream');
542+
tl.debug(`OneDeploy response: ${JSON.stringify(response)}`);
543+
if (response.statusCode == 200) {
544+
tl.debug('Deployment passed');
545+
return null;
546+
}
547+
else if (response.statusCode == 202) {
548+
let pollableURL: string = response.headers.location;
549+
if (!!pollableURL) {
550+
tl.debug(`Polling for OneDeploy URL: ${pollableURL}`);
551+
return await this._getDeploymentDetailsFromPollURL(pollableURL);
552+
}
553+
else {
554+
tl.debug('OneDeploy returned 202 without pollable URL.');
555+
return null;
556+
}
557+
}
558+
else {
559+
throw response;
560+
}
561+
}
562+
catch (error) {
563+
throw new Error(tl.loc('PackageDeploymentFailed', this._getFormattedError(error)));
564+
}
565+
}
531566

532567
public async getDeploymentDetails(deploymentID: string): Promise<any> {
533568
try {

common-npm-packages/azurermdeploycommon/azure-arm-rest/azure-arm-app-service-kudu.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,41 @@ export class Kudu {
522522
}
523523
}
524524

525+
public async oneDeploy(webPackage: string, queryParameters?: Array<string>): Promise<any> {
526+
let httpRequest = new webClient.WebRequest();
527+
httpRequest.method = 'POST';
528+
httpRequest.uri = this._client.getRequestUri(`/api/publish`, queryParameters);
529+
httpRequest.body = fs.createReadStream(webPackage);
530+
let requestOptions = new webClient.WebRequestOptions();
531+
//Bydefault webclient.sendRequest retries for [500, 502, 503, 504]
532+
requestOptions.retriableStatusCodes = [500, 502, 503, 504];
533+
requestOptions.retryIntervalInSeconds = 5;
534+
try {
535+
let response = await this._client.beginRequest(httpRequest, requestOptions, 'application/octet-stream');
536+
tl.debug(`OneDeploy response: ${JSON.stringify(response)}`);
537+
if (response.statusCode == 200) {
538+
tl.debug('Deployment passed');
539+
return null;
540+
}
541+
else if (response.statusCode == 202) {
542+
let pollableURL: string = response.headers.location;
543+
if (!!pollableURL) {
544+
tl.debug(`Polling for OneDeploy URL: ${pollableURL}`);
545+
return await this._getDeploymentDetailsFromPollURL(pollableURL);
546+
}
547+
else {
548+
tl.debug('OneDeploy returned 202 without pollable URL.');
549+
return null;
550+
}
551+
}
552+
else {
553+
throw response;
554+
}
555+
}
556+
catch (error) {
557+
throw new Error(tl.loc('PackageDeploymentFailed', this._getFormattedError(error)));
558+
}
559+
}
525560

526561
public async getDeploymentDetails(deploymentID: string): Promise<any> {
527562
try {
@@ -648,4 +683,4 @@ export class Kudu {
648683
}
649684
return error;
650685
}
651-
}
686+
}

common-npm-packages/azurermdeploycommon/operations/KuduServiceUtility.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const physicalRootPath: string = '/site/wwwroot';
1414
const deploymentFolder: string = 'site/deployments';
1515
const manifestFileName: string = 'manifest';
1616
const VSTS_ZIP_DEPLOY: string = 'VSTS_ZIP_DEPLOY';
17+
const VSTS_ONE_DEPLOY: string = 'VSTS_ONE_DEPLOY';
1718
const VSTS_DEPLOY: string = 'VSTS';
1819

1920
export class KuduServiceUtility {
@@ -196,6 +197,45 @@ export class KuduServiceUtility {
196197
}
197198
}
198199

200+
public async deployUsingOneDeploy(packagePath: string, customMessage?: any, targetPath?: any, type?: any, clean?: any, restart?: any): Promise<string> {
201+
try {
202+
console.log(tl.loc('Package deployment using OneDeploy initiated.'));
203+
let queryParameters: Array<string> = [
204+
'async=true',
205+
'deployer=' + VSTS_ONE_DEPLOY
206+
];
207+
208+
if (type) {
209+
queryParameters.push('type=' + encodeURIComponent(type));
210+
}
211+
212+
if (targetPath) {
213+
queryParameters.push('path=' + encodeURIComponent(targetPath));
214+
}
215+
216+
if (clean) {
217+
queryParameters.push('clean=' + encodeURIComponent(clean));
218+
}
219+
220+
if (restart) {
221+
queryParameters.push('restart=' + encodeURIComponent(restart));
222+
}
223+
224+
var deploymentMessage = this._getUpdateHistoryRequest(null, null, customMessage).message;
225+
queryParameters.push('message=' + encodeURIComponent(deploymentMessage));
226+
let deploymentDetails = await this._appServiceKuduService.oneDeploy(packagePath, queryParameters);
227+
console.log(tl.loc(deploymentDetails));
228+
await this._processDeploymentResponse(deploymentDetails);
229+
console.log(tl.loc('Successfully deployed web package to App Service.'));
230+
231+
return deploymentDetails.id;
232+
}
233+
catch (error) {
234+
tl.error(tl.loc('PackageDeploymentFailed'));
235+
throw error;
236+
}
237+
}
238+
199239
private async _processDeploymentResponse(deploymentDetails: any): Promise<void> {
200240
try {
201241
var kuduDeploymentDetails = await this._appServiceKuduService.getDeploymentDetails(deploymentDetails.id);
@@ -456,4 +496,4 @@ export class KuduServiceUtility {
456496
deployer : 'VSTS'
457497
};
458498
}
459-
}
499+
}

common-npm-packages/azurermdeploycommon/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common-npm-packages/azurermdeploycommon/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-pipelines-tasks-azurermdeploycommon",
3-
"version": "3.236.0",
3+
"version": "3.237.0",
44
"description": "Common Lib for Azure ARM REST apis",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)