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

Commit fecb01f

Browse files
ddoowaandresmgot
authored andcommitted
Add Support for individually prepackaged functions (#191)
1 parent 7b2113a commit fecb01f

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

deploy/kubelessDeploy.js

+24-5
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,37 @@ class KubelessDeploy {
7878
}
7979
}
8080

81+
getPkg(description, funcName) {
82+
const pkg = this.options.package ||
83+
this.serverless.service.package.path ||
84+
this.serverless.service.package.artifact ||
85+
description.package.artifact ||
86+
this.serverless.config.serverless.service.artifact;
87+
88+
89+
// if using the package option and packaging inidividually
90+
// then we're expecting a directory where artifacts for all the finctions live
91+
if (this.options.package && this.serverless.service.package.individually) {
92+
if (fs.lstatSync(pkg).isDirectory()) {
93+
return `${pkg + funcName}.zip`;
94+
}
95+
const errMsg = 'Expecting the Paramater to be a directory ' +
96+
'for individualy packaged functions';
97+
this.serverless.cli.log(errMsg);
98+
throw new Error(errMsg);
99+
}
100+
return pkg;
101+
}
102+
103+
81104
deployFunction() {
82105
const runtime = this.serverless.service.provider.runtime;
83106
const populatedFunctions = [];
84107
const kubelessConfig = new Config();
85108
return new BbPromise((resolve, reject) => {
86109
kubelessConfig.init().then(() => {
87110
_.each(this.serverless.service.functions, (description, name) => {
88-
const pkg = this.options.package ||
89-
this.serverless.service.package.path ||
90-
this.serverless.service.package.artifact ||
91-
description.package.artifact ||
92-
this.serverless.config.serverless.service.artifact;
111+
const pkg = this.getPkg(description, name);
93112

94113
this.checkSize(pkg);
95114

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-kubeless",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
55
"main": "index.js",
66
"directories": {

test/kubelessDeploy.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,23 @@ describe('KubelessDeploy', () => {
190190
kubelessDeploy.deployFunction()
191191
).to.be.fulfilled;
192192
});
193+
it('should deploy a function (nodejs) individually pre-packaged', () => {
194+
depsFile = path.join(cwd, 'package.json');
195+
fs.writeFileSync(depsFile, 'nodejs function deps');
196+
serverlessWithFunction.service.package.individually = true;
197+
kubelessDeploy = instantiateKubelessDeploy(pkgFile, depsFile, _.defaultsDeep(
198+
{ service: { provider: { runtime: 'nodejs6' } } },
199+
serverlessWithFunction
200+
));
201+
kubelessDeploy.options.package = path.join(cwd, '.serverless/');
202+
mocks.createDeploymentNocks(config.clusters[0].cluster.server, functionName, defaultFuncSpec({
203+
deps: 'nodejs function deps',
204+
runtime: 'nodejs6',
205+
}));
206+
return expect( // eslint-disable-line no-unused-expressions
207+
kubelessDeploy.deployFunction()
208+
).to.be.fulfilled;
209+
});
193210
it('should deploy a function (nodejs) with function level runtime override', () => {
194211
depsFile = path.join(cwd, 'package.json');
195212
fs.writeFileSync(depsFile, 'nodejs function deps');

0 commit comments

Comments
 (0)