Skip to content

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 authored Aug 16, 2019
1 parent c79e27f commit 20f1579
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 20f1579

Please sign in to comment.