mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Merge pull request #2561 from doapp-ryanp/master
Make `deploy function` lifecycle events more fine grain
This commit is contained in:
commit
700eb2ea86
@ -249,12 +249,14 @@ class Utils {
|
||||
}
|
||||
|
||||
let hasCustomResourcesDefined = false;
|
||||
|
||||
// check if configuration in resources.Resources is defined
|
||||
if ((serverless.service.resources &&
|
||||
serverless.service.resources.Resources &&
|
||||
Object.keys(serverless.service.resources.Resources).length)) {
|
||||
hasCustomResourcesDefined = true;
|
||||
}
|
||||
|
||||
// check if configuration in resources.Outputs is defined
|
||||
if ((serverless.service.resources &&
|
||||
serverless.service.resources.Outputs &&
|
||||
@ -270,6 +272,7 @@ class Utils {
|
||||
serverless.service.defaults.variableSyntax !== defaultVariableSyntax) {
|
||||
hasCustomVariableSyntaxDefined = true;
|
||||
}
|
||||
|
||||
// check if the variableSyntax in the provider section is defined
|
||||
if (serverless.service.provider &&
|
||||
serverless.service.provider.variableSyntax &&
|
||||
|
||||
@ -19,11 +19,15 @@ class AwsDeployFunction {
|
||||
Object.assign(this, validate);
|
||||
|
||||
this.hooks = {
|
||||
'deploy:function:deploy': () => BbPromise.bind(this)
|
||||
'deploy:function:initialize': () => BbPromise.bind(this)
|
||||
.then(this.validate)
|
||||
.then(this.logStatus)
|
||||
.then(this.checkIfFunctionExists)
|
||||
.then(this.zipFunction)
|
||||
.then(this.checkIfFunctionExists),
|
||||
|
||||
'deploy:function:packageFunction': () => BbPromise.bind(this)
|
||||
.then(this.packageFunction),
|
||||
|
||||
'deploy:function:deploy': () => BbPromise.bind(this)
|
||||
.then(this.deployFunction)
|
||||
.then(this.cleanup),
|
||||
};
|
||||
@ -31,7 +35,7 @@ class AwsDeployFunction {
|
||||
|
||||
logStatus() {
|
||||
this.serverless.cli.log(`Deploying function: ${this.options.function}...`);
|
||||
BbPromise.resolve();
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
checkIfFunctionExists() {
|
||||
@ -62,7 +66,8 @@ class AwsDeployFunction {
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
zipFunction() {
|
||||
packageFunction() {
|
||||
this.serverless.cli.log(`Packaging function: ${this.options.function}...`);
|
||||
return this.pkg.packageFunction(this.options.function);
|
||||
}
|
||||
|
||||
|
||||
@ -60,32 +60,43 @@ describe('AwsDeployFunction', () => {
|
||||
|
||||
expect(awsDeployFunctionWithEmptyOptions.options).to.deep.equal({});
|
||||
});
|
||||
});
|
||||
|
||||
it('should run promise chain in order', () => {
|
||||
describe('hooks', () => {
|
||||
it('should run "deploy:function:initialize" promise chain in order', () => {
|
||||
const validateStub = sinon
|
||||
.stub(awsDeployFunction, 'validate').returns(BbPromise.resolve());
|
||||
const checkIfFunctionExistsStub = sinon
|
||||
.stub(awsDeployFunction, 'checkIfFunctionExists').returns(BbPromise.resolve());
|
||||
const zipFunctionStub = sinon
|
||||
.stub(awsDeployFunction, 'zipFunction').returns(BbPromise.resolve());
|
||||
|
||||
return awsDeployFunction.hooks['deploy:function:initialize']().then(() => {
|
||||
expect(validateStub.calledOnce).to.equal(true);
|
||||
expect(checkIfFunctionExistsStub.calledAfter(validateStub)).to.equal(true);
|
||||
awsDeployFunction.checkIfFunctionExists.restore();
|
||||
});
|
||||
});
|
||||
|
||||
it('should run "deploy:function:packageFunction" promise chain in order', () => {
|
||||
const packageFunctionStub = sinon
|
||||
.stub(awsDeployFunction, 'packageFunction').returns(BbPromise.resolve());
|
||||
|
||||
return awsDeployFunction.hooks['deploy:function:packageFunction']().then(() => {
|
||||
expect(packageFunctionStub.calledOnce).to.equal(true);
|
||||
awsDeployFunction.packageFunction.restore();
|
||||
});
|
||||
});
|
||||
|
||||
it('should run "deploy:function:deploy" promise chain in order', () => {
|
||||
const deployFunctionStub = sinon
|
||||
.stub(awsDeployFunction, 'deployFunction').returns(BbPromise.resolve());
|
||||
const cleanupStub = sinon
|
||||
.stub(awsDeployFunction, 'cleanup').returns(BbPromise.resolve());
|
||||
|
||||
return awsDeployFunction.hooks['deploy:function:deploy']().then(() => {
|
||||
expect(validateStub.calledOnce).to.equal(true);
|
||||
expect(checkIfFunctionExistsStub.calledAfter(validateStub))
|
||||
.to.equal(true);
|
||||
expect(zipFunctionStub.calledAfter(checkIfFunctionExistsStub))
|
||||
.to.equal(true);
|
||||
expect(deployFunctionStub.calledAfter(zipFunctionStub))
|
||||
.to.equal(true);
|
||||
expect(deployFunctionStub.calledOnce).to.equal(true);
|
||||
expect(cleanupStub.calledAfter(deployFunctionStub))
|
||||
.to.equal(true);
|
||||
|
||||
awsDeployFunction.checkIfFunctionExists.restore();
|
||||
awsDeployFunction.zipFunction.restore();
|
||||
awsDeployFunction.deployFunction.restore();
|
||||
awsDeployFunction.cleanup.restore();
|
||||
});
|
||||
@ -125,7 +136,7 @@ describe('AwsDeployFunction', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#zipFunction()', () => {
|
||||
describe('#packageFunction()', () => {
|
||||
it('should zip the function', () => {
|
||||
const pkg = new Package();
|
||||
|
||||
@ -134,7 +145,7 @@ describe('AwsDeployFunction', () => {
|
||||
const packageFunctionStub = sinon
|
||||
.stub(pkg, 'packageFunction').returns(BbPromise.resolve());
|
||||
|
||||
return awsDeployFunction.zipFunction().then(() => {
|
||||
return awsDeployFunction.packageFunction().then(() => {
|
||||
expect(packageFunctionStub.calledOnce).to.be.equal(true);
|
||||
expect(packageFunctionStub.args[0][0]).to.be.equal(awsDeployFunction.options.function);
|
||||
|
||||
|
||||
@ -38,6 +38,8 @@ class Deploy {
|
||||
function: {
|
||||
usage: 'Deploy a single function from the service',
|
||||
lifecycleEvents: [
|
||||
'initialize',
|
||||
'packageFunction',
|
||||
'deploy',
|
||||
],
|
||||
options: {
|
||||
|
||||
@ -67,6 +67,10 @@ module.exports = {
|
||||
functionObject.artifact = null; // reset the current artifact
|
||||
|
||||
if (funcPackageConfig.artifact) {
|
||||
if (process.env.SLS_DEBUG) {
|
||||
this.serverless.cli.log('package.artifact is defined, skipping packaging');
|
||||
}
|
||||
|
||||
functionObject.artifact = funcPackageConfig.artifact;
|
||||
return BbPromise.resolve(funcPackageConfig.artifact);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user