From 59a8bc32640857ec0d3bbab844c5277a25792be6 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 10 Jun 2021 21:58:05 +0200 Subject: [PATCH 1/2] Skip container function with `uri` defined It looks like a container function defined with a `uri` shouldn't be handled by the plugin because the image won't be handled by Serverless itself. So we just skip the function in that case. --- lib/utils.js | 6 ++++++ tests/validate.test.js | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 935e868d9..b7250cf7f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -114,9 +114,15 @@ function isNodeRuntime(runtime) { function getAllNodeFunctions() { const functions = this.serverless.service.getAllFunctions(); + return _.filter(functions, funcName => { const func = this.serverless.service.getFunction(funcName); + // if `uri` is provided, it means the image isn't built by Serverless so we shouldn't take care of it + if (func.image && func.image.uri) { + return false; + } + return isNodeRuntime(func.runtime || this.serverless.service.provider.runtime || 'nodejs'); }); } diff --git a/tests/validate.test.js b/tests/validate.test.js index 7eca04b6f..115b4dd96 100644 --- a/tests/validate.test.js +++ b/tests/validate.test.js @@ -507,7 +507,7 @@ describe('validate', () => { }, dockerfunc: { image: { - name: 'some-image-uri', + name: 'some-docker-image', command: ['com.serverless.Handler'] }, events: [ @@ -518,6 +518,21 @@ describe('validate', () => { } } ] + }, + dockerfuncuri: { + image: { + name: 'some-image-with-uri', + uri: 'http://hub.dock.er/image', + command: ['method.lambda'] + }, + events: [ + { + http: { + method: 'POST', + path: 'mydockerfuncpath' + } + } + ] } }; From c49d8accb7bc7191aad426a2f22d0d2c30439351 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 25 Aug 2021 10:28:20 +0200 Subject: [PATCH 2/2] Add test for image with URI defined --- tests/validate.test.js | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/validate.test.js b/tests/validate.test.js index 115b4dd96..61ac9c1e3 100644 --- a/tests/validate.test.js +++ b/tests/validate.test.js @@ -708,6 +708,51 @@ describe('validate', () => { }); }); + it('should skip image defined with URI', () => { + const testOutPath = 'test'; + const testFunctionsConfig = { + dockerfuncwithuri: { + image: { + name: 'some-image-with-uri', + uri: 'http://hub.dock.er/image', + command: ['method.lambda'] + }, + events: [ + { + http: { + method: 'POST', + path: 'mydockerfuncpath' + } + } + ] + } + }; + + 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 = {}; + + expect(lib.entries).to.deep.equal(expectedLibEntries); + expect(globSyncStub).to.have.callCount(0); + expect(serverless.cli.log).to.not.have.been.called; + return null; + }); + }); + it('should throw error if container image is not well defined', () => { const testOutPath = 'test'; const testFunctionsConfig = {