Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Add Support for individually prepackaged functions (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddoowa authored and andresmgot committed Oct 23, 2019
1 parent 7b2113a commit fecb01f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
29 changes: 24 additions & 5 deletions deploy/kubelessDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,37 @@ class KubelessDeploy {
}
}

getPkg(description, funcName) {
const pkg = this.options.package ||
this.serverless.service.package.path ||
this.serverless.service.package.artifact ||
description.package.artifact ||
this.serverless.config.serverless.service.artifact;


// if using the package option and packaging inidividually
// then we're expecting a directory where artifacts for all the finctions live
if (this.options.package && this.serverless.service.package.individually) {
if (fs.lstatSync(pkg).isDirectory()) {
return `${pkg + funcName}.zip`;
}
const errMsg = 'Expecting the Paramater to be a directory ' +
'for individualy packaged functions';
this.serverless.cli.log(errMsg);
throw new Error(errMsg);
}
return pkg;
}


deployFunction() {
const runtime = this.serverless.service.provider.runtime;
const populatedFunctions = [];
const kubelessConfig = new Config();
return new BbPromise((resolve, reject) => {
kubelessConfig.init().then(() => {
_.each(this.serverless.service.functions, (description, name) => {
const pkg = this.options.package ||
this.serverless.service.package.path ||
this.serverless.service.package.artifact ||
description.package.artifact ||
this.serverless.config.serverless.service.artifact;
const pkg = this.getPkg(description, name);

this.checkSize(pkg);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-kubeless",
"version": "0.8.1",
"version": "0.8.2",
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
"main": "index.js",
"directories": {
Expand Down
17 changes: 17 additions & 0 deletions test/kubelessDeploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,23 @@ describe('KubelessDeploy', () => {
kubelessDeploy.deployFunction()
).to.be.fulfilled;
});
it('should deploy a function (nodejs) individually pre-packaged', () => {
depsFile = path.join(cwd, 'package.json');
fs.writeFileSync(depsFile, 'nodejs function deps');
serverlessWithFunction.service.package.individually = true;
kubelessDeploy = instantiateKubelessDeploy(pkgFile, depsFile, _.defaultsDeep(
{ service: { provider: { runtime: 'nodejs6' } } },
serverlessWithFunction
));
kubelessDeploy.options.package = path.join(cwd, '.serverless/');
mocks.createDeploymentNocks(config.clusters[0].cluster.server, functionName, defaultFuncSpec({
deps: 'nodejs function deps',
runtime: 'nodejs6',
}));
return expect( // eslint-disable-line no-unused-expressions
kubelessDeploy.deployFunction()
).to.be.fulfilled;
});
it('should deploy a function (nodejs) with function level runtime override', () => {
depsFile = path.join(cwd, 'package.json');
fs.writeFileSync(depsFile, 'nodejs function deps');
Expand Down

0 comments on commit fecb01f

Please sign in to comment.