From 20f15798e3623fe551d9c1160b955f1981e43e96 Mon Sep 17 00:00:00 2001 From: Tanner Barlow Date: Fri, 16 Aug 2019 09:52:56 -0700 Subject: [PATCH] perf: Skip upload to function app if configured to run from blob (#241) Quick fix for not uploading zipped code to Function App if configured to only run from blob, and vice versa --- src/services/functionAppService.test.ts | 37 +++++++++++++++++++++++-- src/services/functionAppService.ts | 9 +++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/services/functionAppService.test.ts b/src/services/functionAppService.test.ts index bf607730..b7cc9c87 100644 --- a/src/services/functionAppService.test.ts +++ b/src/services/functionAppService.test.ts @@ -364,10 +364,27 @@ describe("Function App Service", () => { newSlsService.provider["deployment"] = { runFromBlobUrl: true, } + const service = createService(MockFactory.createTestServerless({ + service: newSlsService, + })); + await service.uploadFunctions(app); + expect(AzureBlobStorageService.prototype.generateBlobSasTokenUrl).toBeCalled(); + expect(FunctionAppService.prototype.updateFunctionAppSetting).toBeCalledWith( + app, + "WEBSITE_RUN_FROM_PACKAGE", + sasUrl + ); + }); + it("does not upload directly to function app if configured to run from blob", async () => { + const newSlsService = MockFactory.createTestService(); + newSlsService.provider["deployment"] = { + runFromBlobUrl: true, + } const service = createService(MockFactory.createTestServerless({ service: newSlsService, })); + FunctionAppService.prototype.uploadZippedArfifactToFunctionApp = jest.fn(); await service.uploadFunctions(app); expect(AzureBlobStorageService.prototype.generateBlobSasTokenUrl).toBeCalled(); expect(FunctionAppService.prototype.updateFunctionAppSetting).toBeCalledWith( @@ -375,6 +392,24 @@ describe("Function App Service", () => { "WEBSITE_RUN_FROM_PACKAGE", sasUrl ); + expect(FunctionAppService.prototype.uploadZippedArfifactToFunctionApp).not.toBeCalled(); + (FunctionAppService.prototype.uploadZippedArfifactToFunctionApp as any).mockRestore(); + }); + + it("uploads directly to function app if not configured to run from blob", async () => { + const newSlsService = MockFactory.createTestService(); + newSlsService.provider["deployment"] = { + runFromBlobUrl: false, + } + const sls = MockFactory.createTestServerless({ + service: newSlsService, + }); + const service = createService(sls); + FunctionAppService.prototype.uploadZippedArfifactToFunctionApp = jest.fn(); + await service.uploadFunctions(app); + expect(AzureBlobStorageService.prototype.generateBlobSasTokenUrl).not.toBeCalled(); + expect(FunctionAppService.prototype.uploadZippedArfifactToFunctionApp).toBeCalled(); + (FunctionAppService.prototype.uploadZippedArfifactToFunctionApp as any).mockRestore(); }); it("does not generate SAS URL or update WEBSITE_RUN_FROM_PACKAGE if not configured to run from blob", async() => { @@ -384,6 +419,4 @@ describe("Function App Service", () => { expect(FunctionAppService.prototype.updateFunctionAppSetting).not.toBeCalled(); }); }); - - }); diff --git a/src/services/functionAppService.ts b/src/services/functionAppService.ts index bd57a503..353a6582 100644 --- a/src/services/functionAppService.ts +++ b/src/services/functionAppService.ts @@ -149,13 +149,11 @@ export class FunctionAppService extends BaseService { this.log("Deploying serverless functions..."); const functionZipFile = this.getFunctionZipFile(); - const uploadFunctionApp = this.uploadZippedArfifactToFunctionApp(functionApp, functionZipFile); - const uploadBlobStorage = this.uploadZippedArtifactToBlobStorage(functionZipFile); - - await Promise.all([uploadFunctionApp, uploadBlobStorage]); + const blobUpload = this.uploadZippedArtifactToBlobStorage(functionZipFile); if (this.deploymentConfig.runFromBlobUrl) { this.log("Updating function app setting to run from external package..."); + await blobUpload; const sasUrl = await this.blobService.generateBlobSasTokenUrl( this.deploymentConfig.container, this.artifactName @@ -165,6 +163,9 @@ export class FunctionAppService extends BaseService { configConstants.runFromPackageSetting, sasUrl ) + } else { + const functionAppUpload = this.uploadZippedArfifactToFunctionApp(functionApp, functionZipFile); + Promise.all([blobUpload, functionAppUpload]); } this.log("Deployed serverless functions:")