Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
perf: Skip upload to function app if configured to run from blob (#241)
Browse files Browse the repository at this point in the history
Quick fix for not uploading zipped code to Function App if configured to only run from blob, and vice versa
  • Loading branch information
tbarlow12 committed Sep 13, 2019
1 parent f5cbe45 commit f734f08
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
37 changes: 35 additions & 2 deletions src/services/functionAppService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,52 @@ 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(
app,
"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() => {
Expand All @@ -384,6 +419,4 @@ describe("Function App Service", () => {
expect(FunctionAppService.prototype.updateFunctionAppSetting).not.toBeCalled();
});
});


});
9 changes: 5 additions & 4 deletions src/services/functionAppService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:")
Expand Down

0 comments on commit f734f08

Please sign in to comment.