mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
FunctionDeploy: break into small functions
This commit is contained in:
parent
f39dd17686
commit
a514dd33f2
@ -255,7 +255,7 @@ class Jaws {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Load Plugins
|
||||
* @param relDir string path to start from when rel paths are specified
|
||||
* @param pluginMetadata [{path:'path (re or loadable npm mod',config{}}]
|
||||
* @private
|
||||
|
||||
@ -64,6 +64,8 @@ class FunctionDeploy extends JawsPlugin {
|
||||
],
|
||||
});
|
||||
|
||||
// TODO: Add "all" option
|
||||
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
@ -100,8 +102,6 @@ class FunctionDeploy extends JawsPlugin {
|
||||
* - If CLI, maps CLI input to event object
|
||||
*/
|
||||
|
||||
// TODO: Loop through each function, check runtime and separate accordingly
|
||||
|
||||
_validateAndPrepare() {
|
||||
|
||||
let _this = this;
|
||||
@ -208,15 +208,13 @@ class FunctionDeploy extends JawsPlugin {
|
||||
* Deploy Regions
|
||||
*/
|
||||
|
||||
// TODO: multi-language support?
|
||||
|
||||
_deployRegions() {
|
||||
|
||||
let _this = this;
|
||||
|
||||
return BbPromise.try(function() {
|
||||
return _this.evt.queued.regions;
|
||||
})
|
||||
.bind(_this)
|
||||
.each(function(region) {
|
||||
|
||||
// Deploy Type
|
||||
@ -224,92 +222,114 @@ class FunctionDeploy extends JawsPlugin {
|
||||
|
||||
// Deploy Endpoint only
|
||||
case "endpoint":
|
||||
|
||||
// TODO: Move to re-usable function ("all" needs this too)
|
||||
// TODO: No concurrency, instead process w/ error handling for API Gateway throttling
|
||||
return _this.Jaws.actions.endpointPackageApiGateway(evtClone)
|
||||
.bind(_this)
|
||||
.then(_this.Jaws.actions.endpointProvisionApiGateway);
|
||||
|
||||
// Deploy Code only (lambda)
|
||||
return _this._deployEndpointByRegion(region);
|
||||
break;
|
||||
// Deploy Code only
|
||||
case "code":
|
||||
|
||||
// TODO: Move to re-usable function ("all" needs this too)
|
||||
|
||||
// Package Lambdas
|
||||
return new BbPromise(function(resolve, reject) {
|
||||
|
||||
// Create uploaded array for this region
|
||||
_this.evt.uploaded[region] = [];
|
||||
|
||||
// Package & Upload functions' code concurrently
|
||||
// Package must be redone for each region because ENV vars are set for each region
|
||||
async.eachLimit(_this.evt.queued.functions, 5, function(func, cb) {
|
||||
|
||||
// Create new evt object for concurrent operations
|
||||
let newEvent = {
|
||||
stage: _this.evt.queued.stage,
|
||||
region: JawsUtils.getProjRegionConfigForStage(
|
||||
_this.Jaws._projectJson,
|
||||
_this.evt.queued.stage,
|
||||
region),
|
||||
function: func,
|
||||
};
|
||||
|
||||
// Process sub-Actions
|
||||
return _this.Jaws.actions.codePackageLambdaNodejs(newEvent)
|
||||
.bind(_this)
|
||||
.then(_this.Jaws.actions.codeCompressLambdaNodejs)
|
||||
.then(_this.Jaws.actions.codeUploadLambdaNodejs)
|
||||
.then(function(evt) {
|
||||
// Add Function and Region
|
||||
_this.evt.uploaded[region].push(evt.function);
|
||||
return cb();
|
||||
});
|
||||
|
||||
}, resolve);
|
||||
});
|
||||
|
||||
return _this._processCodeByRegion(region);
|
||||
break;
|
||||
|
||||
// Deploy Code then Endpoint
|
||||
case "all":
|
||||
break;
|
||||
|
||||
// Default
|
||||
default:
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
})
|
||||
.then(function() {
|
||||
.then(_this._provisionCodeAllRegions);
|
||||
}
|
||||
|
||||
return new BbPromise(function(resolve, reject) {
|
||||
/**
|
||||
* Deploy Code By Region
|
||||
* @region
|
||||
*/
|
||||
|
||||
// If type is "endpoint", skip
|
||||
if (_this.evt.queued.type === 'endpoint') return _this.evt;
|
||||
_processCodeByRegion(region) {
|
||||
|
||||
// If type is "code" or "all", do concurrent, multi-region, CF update
|
||||
async.eachLimit(Object.keys(_this.evt.uploaded), 5, function(region, cb) {
|
||||
let _this = this;
|
||||
|
||||
let newEvent = {
|
||||
stage: _this.evt.queued.stage,
|
||||
region: JawsUtils.getProjRegionConfigForStage(
|
||||
_this.Jaws._projectJson,
|
||||
_this.evt.queued.stage,
|
||||
region),
|
||||
functions: _this.evt.uploaded[region],
|
||||
};
|
||||
return new BbPromise(function(resolve, reject) {
|
||||
|
||||
return _this.Jaws.actions.codeProvisionLambdaNodejs(newEvent)
|
||||
.then(function() {
|
||||
return cb();
|
||||
});
|
||||
// Create uploaded array for this region
|
||||
_this.evt.uploaded[region] = [];
|
||||
|
||||
}, function() {
|
||||
return resolve(_this.evt);
|
||||
// Package & Upload functions' code concurrently
|
||||
// Package must be redone for each region because ENV vars are set for each region
|
||||
async.eachLimit(_this.evt.queued.functions, 5, function(func, cb) {
|
||||
|
||||
// Create new evt object for concurrent operations
|
||||
let newEvent = {
|
||||
stage: _this.evt.queued.stage,
|
||||
region: JawsUtils.getProjRegionConfigForStage(
|
||||
_this.Jaws._projectJson,
|
||||
_this.evt.queued.stage,
|
||||
region),
|
||||
function: func,
|
||||
};
|
||||
|
||||
// TODO: Read runtime of func
|
||||
// TODO: Deploy by runtime
|
||||
|
||||
// Process sub-Actions
|
||||
return _this.Jaws.actions.codePackageLambdaNodejs(newEvent)
|
||||
.bind(_this)
|
||||
.then(_this.Jaws.actions.codeCompressLambdaNodejs)
|
||||
.then(_this.Jaws.actions.codeUploadLambdaNodejs)
|
||||
.then(function(evt) {
|
||||
// Add Function and Region
|
||||
_this.evt.uploaded[region].push(evt.function);
|
||||
return cb();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Provision Code All Regions
|
||||
* - Initiates CloudFormation Stack Create/Update in all Regions Concurrently
|
||||
*/
|
||||
|
||||
_provisionCodeAllRegions() {
|
||||
|
||||
let _this = this;
|
||||
|
||||
return new BbPromise(function(resolve, reject) {
|
||||
|
||||
// If type is "endpoint", skip
|
||||
if (_this.evt.queued.type === 'endpoint') return resolve();
|
||||
|
||||
// If type is "code" or "all", do concurrent, multi-region, CF update
|
||||
async.eachLimit(Object.keys(_this.evt.uploaded), 5, function(region, cb) {
|
||||
|
||||
let newEvent = {
|
||||
stage: _this.evt.queued.stage,
|
||||
region: JawsUtils.getProjRegionConfigForStage(
|
||||
_this.Jaws._projectJson,
|
||||
_this.evt.queued.stage,
|
||||
region),
|
||||
functions: _this.evt.uploaded[region],
|
||||
};
|
||||
|
||||
return _this.Jaws.actions.codeProvisionLambdaNodejs(newEvent)
|
||||
.then(cb);
|
||||
|
||||
}, function() {
|
||||
return resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy Endpoint By Region
|
||||
*/
|
||||
// TODO: MAKE EVT CLONE
|
||||
// TODO: Handle API Gateway Throttling Errors
|
||||
_deployEndpointByRegion() {
|
||||
let _this = this;
|
||||
return _this.Jaws.actions.endpointPackageApiGateway(evtClone)
|
||||
.bind(_this)
|
||||
.then(_this.Jaws.actions.endpointProvisionApiGateway);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "lBundleBrowserify",
|
||||
"name": "BundleBrowserify",
|
||||
"envVars": [],
|
||||
"package": {
|
||||
"optimize": {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "lBundleNonoptimized",
|
||||
"name": "BundleNonoptimized",
|
||||
"envVars": [],
|
||||
"package": {
|
||||
"optimize": {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "lSessionsCreate",
|
||||
"name": "SessionsCreate",
|
||||
"envVars": [],
|
||||
"package": {
|
||||
"optimize": {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "lSessionsShow",
|
||||
"name": "SessionsShow",
|
||||
"envVars": [],
|
||||
"package": {
|
||||
"optimize": {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "lUsersCreate",
|
||||
"name": "UsersCreate",
|
||||
"envVars": [],
|
||||
"package": {
|
||||
"optimize": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user