Skip to content

Commit 4331e66

Browse files
authored
Merge pull request #2358 from serverless-heaven/fix/image-ecr
Fix `image.name` not bundled when ECR image is provided
2 parents 8090d22 + ae1e9a6 commit 4331e66

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

lib/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,16 @@ function isNodeRuntime(runtime) {
121121

122122
function getAllNodeFunctions() {
123123
const functions = this.serverless.service.getAllFunctions();
124+
const ecrImages = Object.keys(this.serverless.service.provider?.ecr?.images || []);
124125

125126
return _.filter(functions, funcName => {
126127
const func = this.serverless.service.getFunction(funcName);
128+
const imageName = _.get(func, 'image.name');
129+
const isEcrImage = imageName && ecrImages.includes(imageName);
127130

128131
// if `uri` or `name` is provided or simple remote image path, it means the
129132
// image isn't built by Serverless so we shouldn't take care of it
130-
if ((func.image && (func.image.uri || func.image.name)) || (func.image && typeof func.image === 'string')) {
133+
if (func.image?.uri || (func.image && typeof func.image === 'string') || (func.image && imageName && !isEcrImage)) {
131134
return false;
132135
}
133136

tests/utils.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,33 @@ describe('Utils', () => {
182182

183183
expect(Utils.getAllNodeFunctions.call({ serverless: mockServerless })).toEqual(['foo']);
184184
});
185+
186+
it('should not ignore handlers with image.name property if defined as ecr image', () => {
187+
const mockServerless = {
188+
service: {
189+
getAllFunctions: jest.fn(() => ['foo', 'bar']),
190+
getFunction: jest.fn(name => {
191+
if (name === 'foo') {
192+
return { runtime: 'nodejs20.x' };
193+
}
194+
if (name === 'bar') {
195+
return { runtime: 'nodejs22.x', image: { name: 'fake-image-name' } };
196+
}
197+
}),
198+
provider: {
199+
ecr: {
200+
images: {
201+
'fake-image-name': {
202+
path: './'
203+
}
204+
}
205+
}
206+
}
207+
}
208+
};
209+
210+
expect(Utils.getAllNodeFunctions.call({ serverless: mockServerless })).toEqual(['foo', 'bar']);
211+
});
185212
});
186213

187214
describe('isProviderGoogle', () => {

0 commit comments

Comments
 (0)