Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const constants = {
scmCommandApiPath: '/api/command',
scmDomain: '.scm.azurewebsites.net',
scmVfsPath: '/api/vfs/site/wwwroot/',
scmZipApiPath: '/api/zip/site/wwwroot/'
scmZipDeployApiPath: '/api/zipdeploy'
};

export default constants;
13 changes: 1 addition & 12 deletions src/plugins/deploy/azureDeployPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,17 @@ export class AzureDeployPlugin {

constructor(private serverless: Serverless, private options: Serverless.Options) {
this.hooks = {
'before:deploy:deploy': this.beforeDeploy.bind(this),
'deploy:deploy': this.deploy.bind(this)
};
}

private async beforeDeploy() {
const functionAppService = new FunctionAppService(this.serverless, this.options);
const functionApp = await functionAppService.get();

if (functionApp) {
await functionAppService.cleanUp(functionApp);
}
}

private async deploy() {
const resourceService = new ResourceService(this.serverless, this.options);
await resourceService.deployResourceGroup();

const functionAppService = new FunctionAppService(this.serverless, this.options);
const functionApp = await functionAppService.deploy();

const functionApp = await functionAppService.deploy();
await functionAppService.uploadFunctions(functionApp);
await functionAppService.syncTriggers(functionApp);
}
}
4 changes: 4 additions & 0 deletions src/provider/armTemplates/azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "8.11.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just occurred to me that we should probably target the latest Node 8.x LTX, v8.16.0, which comes with NPM v.4.1: https://nodejs.org/en/download/releases/

I would assume this is supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to put this in a different pr and test :D

},
{
"name": "WEBSITE_RUN_FROM_PACKAGE",
"value": "1"
}
]
}
Expand Down
37 changes: 30 additions & 7 deletions src/services/functionAppService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import jsonpath from 'jsonpath';
import _ from 'lodash';
import Serverless from 'serverless';
import { BaseService } from './baseService';
import { constants } from '../config';

export class FunctionAppService extends BaseService {
private resourceClient: ResourceManagementClient;
Expand Down Expand Up @@ -79,27 +80,49 @@ export class FunctionAppService extends BaseService {
return response.data.value || [];
}

public async uploadFunctions(functionApp): Promise<any> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we are using zipDeploy method for the service deployment - but I think we should keep a more generic name as the method name. Later on when we introduce runFromPackage we will have multiple branches within this method. Let's stick with uploadFunctions for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to be clear, I am adding runFromPackage in this PR already, it's the change in the arm template

this.serverless.cli.log('Creating azure functions');
public async uploadFunctions(functionApp) {
await this.zipDeploy(functionApp);
}

const scmDomain = functionApp.enabledHostNames[0];
private async zipDeploy(functionApp) {
const functionAppName = functionApp.name;
this.serverless.cli.log(`Deploying zip file to function app: ${functionAppName}`);

// Upload function artifact if it exists, otherwise the full service is handled in 'uploadFunctions' method
const functionZipFile = this.serverless.service['artifact'];
if (!functionZipFile) {
throw new Error('No zip file found for function app');
}

this.serverless.cli.log(`-> Deploying service package @ ${functionZipFile}`);
this.serverless.cli.log(`-> Uploading ${functionZipFile}`);

const uploadUrl = `https://${functionAppName}${constants.scmDomain}${constants.scmZipDeployApiPath}`;
this.serverless.cli.log(`-> Upload url: ${uploadUrl}`);

// https://github.com/projectkudu/kudu/wiki/Deploying-from-a-zip-file-or-url
const requestOptions = {
method: 'POST',
uri: `https://${scmDomain}/api/zipdeploy/`,
uri: uploadUrl,
json: true,
headers: {
Authorization: `Bearer ${this.credentials.tokenCache._entries[0].accessToken}`,
Accept: '*/*'
Accept: '*/*',
ContentType: 'application/octet-stream',
}
};

await this.sendFile(requestOptions, functionZipFile);
try {
await this.sendFile(requestOptions, functionZipFile);
this.serverless.cli.log('-> Function package uploaded successfully');
} catch (e) {
throw new Error(`Error uploading zip file:\n --> ${e}`);
}
}

/**
* create all necessary resources as defined in src/provider/armTemplates
* resource-group, storage account, app service plan, and app service at the minimum
*/
public async deploy() {
this.serverless.cli.log(`Creating function app: ${this.serviceName}`);
let parameters: any = { functionAppName: { value: this.serviceName } };
Expand Down