Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip container function with uri defined #877

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
Expand Down
62 changes: 61 additions & 1 deletion tests/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ describe('validate', () => {
},
dockerfunc: {
image: {
name: 'some-image-uri',
name: 'some-docker-image',
command: ['com.serverless.Handler']
},
events: [
Expand All @@ -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'
}
}
]
}
j0k3r marked this conversation as resolved.
Show resolved Hide resolved
};

Expand Down Expand Up @@ -693,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 = {
Expand Down