Skip to content

Commit 036757e

Browse files
gwdpvicary
andauthored
Allow simple string images (#961)
* Add test case and fixes usage of image param when simple remote string is used * Update documentation Co-authored-by: Vicary A <[email protected]>
1 parent b9417e2 commit 036757e

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,15 @@ functions:
592592
- app.handler2
593593
```
594594

595+
If you want to use a remote docker image but still need the webpack process before doing so, you can specify it as indicated below:
596+
597+
```yaml
598+
# serverless.yml
599+
functions:
600+
myFunction1:
601+
image: public.ecr.aws/lambda/nodejs:latest
602+
```
603+
595604
## Usage
596605

597606
### Automatic bundling

lib/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ function getAllNodeFunctions() {
118118
return _.filter(functions, funcName => {
119119
const func = this.serverless.service.getFunction(funcName);
120120

121-
// if `uri` is provided, it means the image isn't built by Serverless so we shouldn't take care of it
122-
if (func.image && func.image.uri) {
121+
// if `uri` is provided or simple remote image path, it means the
122+
// image isn't built by Serverless so we shouldn't take care of it
123+
if ((func.image && func.image.uri) || (func.image && typeof func.image == 'string')) {
123124
return false;
124125
}
125126

lib/validate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ module.exports = {
2525
return handlerProp;
2626
}
2727

28+
if (imageProp && typeof imageProp == 'string') return imageProp;
29+
2830
if (!imageProp || !imageProp.command || imageProp.command.length < 1) {
2931
const docsLink = 'https://www.serverless.com/blog/container-support-for-lambda';
3032
throw new this.serverless.classes.Error(

tests/validate.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,51 @@ describe('validate', () => {
795795
}).to.throw(/Either function.handler or function.image must be defined/);
796796
});
797797

798+
it('should not throw error if container image is a simple string', () => {
799+
const testOutPath = 'test';
800+
const testFunctionsConfig = {
801+
func1: {
802+
artifact: 'artifact-func1.zip',
803+
events: [
804+
{
805+
http: {
806+
method: 'POST',
807+
path: 'func1path'
808+
}
809+
},
810+
{
811+
nonhttp: 'non-http'
812+
}
813+
],
814+
image: 'XXXX.dkr.ecr.ca-central-1.amazonaws.com/myproject/customNode:latest'
815+
}
816+
};
817+
818+
const testConfig = {
819+
entry: 'test',
820+
context: 'testcontext',
821+
output: {
822+
path: testOutPath
823+
},
824+
getFunction: func => {
825+
return testFunctionsConfig[func];
826+
}
827+
};
828+
829+
_.set(module.serverless.service, 'custom.webpack.config', testConfig);
830+
module.serverless.service.functions = testFunctionsConfig;
831+
globSyncStub.callsFake(filename => [_.replace(filename, '*', 'js')]);
832+
return expect(module.validate()).to.be.fulfilled.then(() => {
833+
const lib = require('../lib/index');
834+
const expectedLibEntries = {};
835+
836+
expect(lib.entries).to.deep.equal(expectedLibEntries);
837+
expect(globSyncStub).to.have.callCount(0);
838+
expect(serverless.cli.log).to.not.have.been.called;
839+
return null;
840+
});
841+
});
842+
798843
describe('google provider', () => {
799844
beforeEach(() => {
800845
_.set(module.serverless, 'service.provider.name', 'google');

0 commit comments

Comments
 (0)