Skip to content
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
10 changes: 10 additions & 0 deletions deploy/lib/compileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const path = require('path');

const _ = require('lodash');
const BbPromise = require('bluebird');

module.exports = {
Expand All @@ -30,6 +31,13 @@ module.exports = {
this.serverless.service.service
}-${this.options.stage}/${this.serverless.service.package.artifactFilePath}`);

funcTemplate.properties.availableMemoryMb = _.get(funcObject, 'memorySize')
|| _.get(this, 'serverless.service.provider.memorySize')
|| 256;
funcTemplate.properties.timeout = _.get(funcObject, 'timeout')
|| _.get(this, 'serverless.service.provider.timeout')
|| '60s';

const eventType = Object.keys(funcObject.events[0])[0];

if (eventType === 'http') {
Expand Down Expand Up @@ -103,6 +111,8 @@ const getFunctionTemplate = (funcObject, region, sourceArchiveUrl) => { //eslint
name: funcObject.name,
properties: {
location: region,
availableMemoryMb: 256,
timeout: '60s',
function: funcObject.handler,
sourceArchiveUrl,
},
Expand Down
138 changes: 138 additions & 0 deletions deploy/lib/compileFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,138 @@ describe('CompileFunctions', () => {
expect(() => googleDeploy.compileFunctions()).toThrow(Error);
});

it('should set the memory size based on the functions configuration', () => {
googleDeploy.serverless.service.functions = {
func1: {
handler: 'func1',
memorySize: 1024,
events: [
{ http: 'foo' },
],
},
};

const compiledResources = [{
type: 'cloudfunctions.v1beta2.function',
name: 'my-service-dev-func1',
properties: {
location: 'us-central1',
function: 'func1',
availableMemoryMb: 1024,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
},
}];

return googleDeploy.compileFunctions().then(() => {
expect(consoleLogStub.calledOnce).toEqual(true);
expect(googleDeploy.serverless.service.provider.compiledConfigurationTemplate.resources)
.toEqual(compiledResources);
});
});

it('should set the memory size based on the provider configuration', () => {
googleDeploy.serverless.service.functions = {
func1: {
handler: 'func1',
events: [
{ http: 'foo' },
],
},
};
googleDeploy.serverless.service.provider.memorySize = 1024;

const compiledResources = [{
type: 'cloudfunctions.v1beta2.function',
name: 'my-service-dev-func1',
properties: {
location: 'us-central1',
function: 'func1',
availableMemoryMb: 1024,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
},
}];

return googleDeploy.compileFunctions().then(() => {
expect(consoleLogStub.calledOnce).toEqual(true);
expect(googleDeploy.serverless.service.provider.compiledConfigurationTemplate.resources)
.toEqual(compiledResources);
});
});

it('should set the timout based on the functions configuration', () => {
googleDeploy.serverless.service.functions = {
func1: {
handler: 'func1',
timeout: '120s',
events: [
{ http: 'foo' },
],
},
};

const compiledResources = [{
type: 'cloudfunctions.v1beta2.function',
name: 'my-service-dev-func1',
properties: {
location: 'us-central1',
function: 'func1',
availableMemoryMb: 256,
timeout: '120s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
},
}];

return googleDeploy.compileFunctions().then(() => {
expect(consoleLogStub.calledOnce).toEqual(true);
expect(googleDeploy.serverless.service.provider.compiledConfigurationTemplate.resources)
.toEqual(compiledResources);
});
});

it('should set the timeout based on the provider configuration', () => {
googleDeploy.serverless.service.functions = {
func1: {
handler: 'func1',
events: [
{ http: 'foo' },
],
},
};
googleDeploy.serverless.service.provider.timeout = '120s';

const compiledResources = [{
type: 'cloudfunctions.v1beta2.function',
name: 'my-service-dev-func1',
properties: {
location: 'us-central1',
function: 'func1',
availableMemoryMb: 256,
timeout: '120s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
},
}];

return googleDeploy.compileFunctions().then(() => {
expect(consoleLogStub.calledOnce).toEqual(true);
expect(googleDeploy.serverless.service.provider.compiledConfigurationTemplate.resources)
.toEqual(compiledResources);
});
});

it('should compile "http" events properly', () => {
googleDeploy.serverless.service.functions = {
func1: {
Expand All @@ -112,6 +244,8 @@ describe('CompileFunctions', () => {
properties: {
location: 'us-central1',
function: 'func1',
availableMemoryMb: 256,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -160,6 +294,8 @@ describe('CompileFunctions', () => {
properties: {
location: 'us-central1',
function: 'func1',
availableMemoryMb: 256,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
eventTrigger: {
eventType: 'foo',
Expand All @@ -174,6 +310,8 @@ describe('CompileFunctions', () => {
properties: {
location: 'us-central1',
function: 'func2',
availableMemoryMb: 256,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
eventTrigger: {
eventType: 'foo',
Expand Down