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
3 changes: 3 additions & 0 deletions deploy/googleDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const BbPromise = require('bluebird');

const validate = require('../shared/validate');
const utils = require('../shared/utils');
const setDeploymentBucketName = require('../shared/setDeploymentBucketName');
const prepareDeployment = require('./lib/prepareDeployment');
const createDeployment = require('./lib/createDeployment');
const monitorDeployment = require('../shared/monitorDeployment');
Expand All @@ -24,6 +25,7 @@ class GoogleDeploy {
this,
validate,
utils,
setDeploymentBucketName,
prepareDeployment,
createDeployment,
monitorDeployment,
Expand All @@ -40,6 +42,7 @@ class GoogleDeploy {
.then(this.setDefaults),

'deploy:initialize': () => BbPromise.bind(this)
.then(this.setDeploymentBucketName)
.then(this.prepareDeployment),

'deploy:setupProviderConfiguration': () => BbPromise.bind(this)
Expand Down
7 changes: 6 additions & 1 deletion deploy/googleDeploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('GoogleDeploy', () => {
describe('hooks', () => {
let validateStub;
let setDefaultsStub;
let setDeploymentBucketNameStub;
let prepareDeploymentStub;
let createDeploymentStub;
let generateArtifactDirectoryNameStub;
Expand All @@ -52,6 +53,8 @@ describe('GoogleDeploy', () => {
.returns(BbPromise.resolve());
setDefaultsStub = sinon.stub(googleDeploy, 'setDefaults')
.returns(BbPromise.resolve());
setDeploymentBucketNameStub = sinon.stub(googleDeploy, 'setDeploymentBucketName')
.returns(BbPromise.resolve());
prepareDeploymentStub = sinon.stub(googleDeploy, 'prepareDeployment')
.returns(BbPromise.resolve());
createDeploymentStub = sinon.stub(googleDeploy, 'createDeployment')
Expand All @@ -74,6 +77,7 @@ describe('GoogleDeploy', () => {
afterEach(() => {
googleDeploy.validate.restore();
googleDeploy.setDefaults.restore();
googleDeploy.setDeploymentBucketName.restore();
googleDeploy.prepareDeployment.restore();
googleDeploy.createDeployment.restore();
googleDeploy.generateArtifactDirectoryName.restore();
Expand All @@ -92,7 +96,8 @@ describe('GoogleDeploy', () => {

it('should run "deploy:initialize" promise chain', () => googleDeploy
.hooks['deploy:initialize']().then(() => {
expect(prepareDeploymentStub.calledOnce).toEqual(true);
expect(setDeploymentBucketNameStub.calledOnce).toEqual(true);
expect(prepareDeploymentStub.calledAfter(setDeploymentBucketNameStub)).toEqual(true);
}));

it('it should run "deploy:setupProviderConfiguration" promise chain', () => googleDeploy
Expand Down
2 changes: 1 addition & 1 deletion deploy/lib/cleanupDeploymentBucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {

getObjectsToRemove() {
const params = {
bucket: `sls-${this.serverless.service.service}-${this.options.stage}`,
bucket: this.serverless.service.provider.deploymentBucketName,
};

return this.provider.request('storage', 'objects', 'list', params)
Expand Down
45 changes: 24 additions & 21 deletions deploy/lib/cleanupDeploymentBucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ describe('CleanupDeploymentBucket', () => {
serverless = new Serverless();
serverless.service = {
service: 'my-service',
provider: {
deploymentBucketName: 'sls-my-service-dev-12345678',
},
};
serverless.setProvider('google', new GoogleProvider(serverless));
const options = {
Expand Down Expand Up @@ -64,27 +67,27 @@ describe('CleanupDeploymentBucket', () => {
const response = {
items: [
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/151224711231-2016-08-18T15:42:00/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/141264711231-2016-08-18T15:43:00/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/141321321541-2016-08-18T11:23:02/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/142003031341-2016-08-18T12:46:04/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/113304333331-2016-08-18T13:40:06/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/903940390431-2016-08-18T23:42:08/artifact.zip`,
},
],
Expand All @@ -94,27 +97,27 @@ describe('CleanupDeploymentBucket', () => {
return googleDeploy.getObjectsToRemove().then((objects) => {
expect(objects.length).toEqual(2);
expect(objects).not.toContainEqual({
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/141321321541-2016-08-18T11:23:02/artifact.zip`,
});
expect(objects).not.toContainEqual({
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/142003031341-2016-08-18T12:46:04/artifact.zip`,
});
expect(objects).not.toContainEqual({
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/151224711231-2016-08-18T15:42:00/artifact.zip`,
});
expect(objects).not.toContainEqual({
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/903940390431-2016-08-18T23:42:08/artifact.zip`,
});
expect(requestStub.calledWithExactly(
'storage',
'objects',
'list',
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
})).toEqual(true);
});
});
Expand All @@ -123,19 +126,19 @@ describe('CleanupDeploymentBucket', () => {
const response = {
items: [
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/151224711231-2016-08-18T15:42:00/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/141264711231-2016-08-18T15:43:00/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/141321321541-2016-08-18T11:23:02/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/142003031341-2016-08-18T12:46:04/artifact.zip`,
},
],
Expand All @@ -150,7 +153,7 @@ describe('CleanupDeploymentBucket', () => {
'objects',
'list',
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
})).toEqual(true);
});
});
Expand All @@ -169,7 +172,7 @@ describe('CleanupDeploymentBucket', () => {
'objects',
'list',
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
})).toEqual(true);
});
});
Expand Down Expand Up @@ -201,19 +204,19 @@ describe('CleanupDeploymentBucket', () => {
it('should remove all given objects', () => {
const objectsToRemove = [
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/151224711231-2016-08-18T15:42:00/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/141264711231-2016-08-18T15:43:00/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/141321321541-2016-08-18T11:23:02/artifact.zip`,
},
{
bucket: 'sls-my-service-dev',
bucket: 'sls-my-service-dev-12345678',
name: `${key}/142003031341-2016-08-18T12:46:04/artifact.zip`,
},
];
Expand Down
6 changes: 3 additions & 3 deletions deploy/lib/compileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ module.exports = {
const funcTemplate = getFunctionTemplate(
funcObject,
this.options.region,
`gs://sls-${
this.serverless.service.service
}-${this.options.stage}/${this.serverless.service.package.artifactFilePath}`);
`gs://${
this.serverless.service.provider.deploymentBucketName
}/${this.serverless.service.package.artifactFilePath}`);

funcTemplate.properties.availableMemoryMb = _.get(funcObject, 'memorySize')
|| _.get(this, 'serverless.service.provider.memorySize')
Expand Down
15 changes: 8 additions & 7 deletions deploy/lib/compileFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('CompileFunctions', () => {
compiledConfigurationTemplate: {
resources: [],
},
deploymentBucketName: 'sls-my-service-dev-12345678',
};
serverless.setProvider('google', new GoogleProvider(serverless));
const options = {
Expand Down Expand Up @@ -115,7 +116,7 @@ describe('CompileFunctions', () => {
function: 'func1',
availableMemoryMb: 1024,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
Expand Down Expand Up @@ -148,7 +149,7 @@ describe('CompileFunctions', () => {
function: 'func1',
availableMemoryMb: 1024,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
Expand Down Expand Up @@ -181,7 +182,7 @@ describe('CompileFunctions', () => {
function: 'func1',
availableMemoryMb: 256,
timeout: '120s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
Expand Down Expand Up @@ -214,7 +215,7 @@ describe('CompileFunctions', () => {
function: 'func1',
availableMemoryMb: 256,
timeout: '120s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
Expand Down Expand Up @@ -246,7 +247,7 @@ describe('CompileFunctions', () => {
function: 'func1',
availableMemoryMb: 256,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
Expand Down Expand Up @@ -296,7 +297,7 @@ describe('CompileFunctions', () => {
function: 'func1',
availableMemoryMb: 256,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
eventTrigger: {
eventType: 'foo',
path: 'some-path',
Expand All @@ -312,7 +313,7 @@ describe('CompileFunctions', () => {
function: 'func2',
availableMemoryMb: 256,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev/some-path/artifact.zip',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
eventTrigger: {
eventType: 'foo',
resource: 'some-resource',
Expand Down
10 changes: 5 additions & 5 deletions deploy/lib/createDeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ module.exports = {

return this.provider.request('deploymentmanager', 'deployments', 'list', params)
.then((response) => {
let found = false;
let foundDeployment;

if (response && response.deployments) {
found = !!response.deployments.find((deployment) => {
foundDeployment = response.deployments.find((deployment) => {
const name = `sls-${this.serverless.service.service}-${this.options.stage}`;
return deployment.name === name;
});
}

return found;
return foundDeployment;
});
},

createIfNotExists(existingDeployment) {
if (existingDeployment) return BbPromise.resolve();
createIfNotExists(foundDeployment) {
if (foundDeployment) return BbPromise.resolve();

this.serverless.cli.log('Creating deployment...');

Expand Down
24 changes: 12 additions & 12 deletions deploy/lib/createDeployment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ describe('CreateDeployment', () => {
});

describe('#checkForExistingDeployment()', () => {
it('should return "false" if no deployments are found', () => {
it('should return "undefined" if no deployments are found', () => {
requestStub.returns(BbPromise.resolve([]));

return googleDeploy.checkForExistingDeployment().then((found) => {
expect(found).toEqual(false);
return googleDeploy.checkForExistingDeployment().then((foundDeployment) => {
expect(foundDeployment).toEqual(undefined);
expect(requestStub.calledWithExactly(
'deploymentmanager',
'deployments',
Expand All @@ -86,16 +86,16 @@ describe('CreateDeployment', () => {
});
});

it('should return "false" if deployments do not contain deployment', () => {
it('should return "undefined" if deployments do not contain deployment', () => {
const response = {
deployments: [
{ name: 'some-other-deployment' },
],
};
requestStub.returns(BbPromise.resolve(response));

return googleDeploy.checkForExistingDeployment().then((found) => {
expect(found).toEqual(false);
return googleDeploy.checkForExistingDeployment().then((foundDeployment) => {
expect(foundDeployment).toEqual(undefined);
expect(requestStub.calledWithExactly(
'deploymentmanager',
'deployments',
Expand All @@ -114,8 +114,8 @@ describe('CreateDeployment', () => {
};
requestStub.returns(BbPromise.resolve(response));

return googleDeploy.checkForExistingDeployment().then((found) => {
expect(found).toEqual(true);
return googleDeploy.checkForExistingDeployment().then((foundDeployment) => {
expect(foundDeployment).toEqual(response.deployments[0]);
expect(requestStub.calledWithExactly(
'deploymentmanager',
'deployments',
Expand Down Expand Up @@ -145,16 +145,16 @@ describe('CreateDeployment', () => {
});

it('should resolve if there is no existing deployment', () => {
const deploymentFound = true;
const foundDeployment = true;

return googleDeploy.createIfNotExists(deploymentFound).then(() => {
return googleDeploy.createIfNotExists(foundDeployment).then(() => {
expect(consoleLogStub.calledOnce).toEqual(false);
expect(readFileSyncStub.called).toEqual(false);
});
});

it('should create and hand over to monitor the deployment if it does not exist', () => {
const deploymentFound = false;
const foundDeployment = false;
const params = {
project: 'my-project',
resource: {
Expand All @@ -168,7 +168,7 @@ describe('CreateDeployment', () => {
};
requestStub.returns(BbPromise.resolve());

return googleDeploy.createIfNotExists(deploymentFound).then(() => {
return googleDeploy.createIfNotExists(foundDeployment).then(() => {
expect(consoleLogStub.calledOnce).toEqual(true);
expect(readFileSyncStub.called).toEqual(true);
expect(requestStub.calledWithExactly(
Expand Down
Loading