-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathsetDeploymentBucketName.js
37 lines (30 loc) · 1.26 KB
/
setDeploymentBucketName.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const BbPromise = require('bluebird');
const _ = require('lodash');
module.exports = {
setDeploymentBucketName() {
// set a default name for the deployment bucket
const service = this.serverless.service.service;
const stage = this.options.stage;
const timestamp = +new Date();
const name = `sls-${service}-${stage}-${timestamp}`;
this.serverless.service.provider.deploymentBucketName = name;
// check if there's already a deployment and update if available
const params = {
project: this.serverless.service.provider.project,
deployment: `sls-${this.serverless.service.service}-${this.options.stage}`,
};
return this.provider
.request('deploymentmanager', 'resources', 'list', params)
.then((response) => {
if (!_.isEmpty(response) && response.resources) {
const regex = new RegExp(`sls-${service}-${stage}-.+`);
const deploymentBucket = response.resources.find(
(resource) => resource.type === 'storage.v1.bucket' && resource.name.match(regex)
);
this.serverless.service.provider.deploymentBucketName = deploymentBucket.name;
}
})
.catch(() => BbPromise.resolve()); // if it cannot be found (e.g. on initial deployment)
},
};