Skip to content

Commit

Permalink
Merge pull request serverless-heaven#675 from MatteoGioioso/feature/a…
Browse files Browse the repository at this point in the history
…llowCustomRuntime
  • Loading branch information
j0k3r authored Dec 31, 2020
2 parents cc6abe0 + b9941bb commit ba015d8
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,21 @@ custom:
This can be useful, in case you want to upload the source maps to your Error
reporting system, or just have it available for some post processing.

#### Nodejs custom runtime

If you are using a nodejs custom runtime you can add the property `allowCustomRuntime: true`.

```yaml
exampleFunction:
handler: path/to/your/handler.default
runtime: provided
allowCustomRuntime: true
```

⚠️ **Note: this will only work if your custom runtime and function are written in JavaScript.
Make sure you know what you are doing when this option is set to `true`**


#### Examples

You can find an example setups in the [`examples`][link-examples] folder.
Expand Down
7 changes: 7 additions & 0 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,18 @@ module.exports = {
_.forEach(functions, (func, index) => {
const loadedFunc = this.serverless.service.getFunction(func);
const runtime = loadedFunc.runtime || this.serverless.service.provider.runtime || 'nodejs';

if (runtime.match(/node/)) {
// runtimes can be 'nodejsX.Y' (AWS, Azure) or 'google-nodejs' (Google Cloud)
const entry = getEntryForFunction.call(this, functions[index], loadedFunc);
_.merge(entries, entry);
}

if (runtime === 'provided' && loadedFunc.allowCustomRuntime) {
// allow custom runtime if the user has specified it
const entry = getEntryForFunction.call(this, functions[index], loadedFunc);
_.merge(entries, entry);
}
});
}

Expand Down
79 changes: 79 additions & 0 deletions tests/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,85 @@ describe('validate', () => {
});
});

it('should allow custom runtime', () => {
const testOutPath = 'test';
const testFunctionsConfig = {
func1: {
handler: 'module1.func1handler',
artifact: 'artifact-func1.zip',
events: [
{
http: {
method: 'get',
path: 'func1path'
}
}
],
runtime: 'node10.x'
},
func2: {
handler: 'module2.func2handler',
artifact: 'artifact-func2.zip',
events: [
{
http: {
method: 'POST',
path: 'func2path'
}
},
{
nonhttp: 'non-http'
}
],
runtime: 'provided',
allowCustomRuntime: true
},
func3: {
handler: 'module3.func2handler',
artifact: 'artifact-func3.zip',
events: [
{
http: {
method: 'POST',
path: 'func3path'
}
},
{
nonhttp: 'non-http'
}
],
runtime: 'provided'
}
};

const testConfig = {
entry: 'test',
context: 'testcontext',
output: {
path: testOutPath
},
getFunction: func => {
return testFunctionsConfig[func];
}
};

_.set(module.serverless.service, 'custom.webpack.config', testConfig);
module.serverless.service.functions = testFunctionsConfig;
globSyncStub.callsFake(filename => [_.replace(filename, '*', 'js')]);
return expect(module.validate()).to.be.fulfilled.then(() => {
const lib = require('../lib/index');
const expectedLibEntries = {
module1: './module1.js',
module2: './module2.js'
};

expect(lib.entries).to.deep.equal(expectedLibEntries);
expect(globSyncStub).to.have.callCount(2);
expect(serverless.cli.log).to.not.have.been.called;
return null;
});
});

describe('google provider', () => {
beforeEach(() => {
_.set(module.serverless, 'service.provider.name', 'google');
Expand Down

0 comments on commit ba015d8

Please sign in to comment.