Skip to content

Commit

Permalink
Merge pull request #330 from lifeomic/no-task/handle-config-entrypoint
Browse files Browse the repository at this point in the history
No task/handle config entrypoint
  • Loading branch information
MorpheusNephew authored Sep 27, 2022
2 parents bb17e4e + d9bce64 commit 3f60e3f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ export async function destroyLambdaExecutionEnvironment (environment: ExecutionE
}
}

async function getEntrypoint (docker: Docker, imageName: string): Promise<string[]> {
const image = await (await docker.getImage(imageName)).inspect();
export async function getEntrypoint (docker: Docker, imageName: string): Promise<string[]> {
const image = await docker.getImage(imageName).inspect();
const entryPoint = image.ContainerConfig.Entrypoint ?? image.Config.Entrypoint;

if (image.ContainerConfig.Entrypoint) {
return flatten([image.ContainerConfig.Entrypoint]);
if (entryPoint) {
return flatten([entryPoint]);
} else {
const parentImageName = image.Parent;
assert(parentImageName, `The image ${imageName} has no entrypoint and no parent image`);
Expand Down
59 changes: 59 additions & 0 deletions test/lambda/entrypoint.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const test = require('ava');
const sinon = require('sinon');
const Dockerode = require('dockerode');
const { getEntrypoint } = require('../../src/lambda');

test.afterEach(() => {
sinon.restore();
});

test.serial('should fail to get entrypoint', async (test) => {
const imageName = 'image';
const errorMessage = `The image ${imageName} has no entrypoint and no parent image`;
const containerStub = sinon.createStubInstance(Dockerode.Container, {
inspect: sinon.stub().resolves({ Image: imageName })
});
const imageStub = sinon.createStubInstance(Dockerode.Image, {
inspect: sinon.stub().resolves({
Config: {},
ContainerConfig: {}
})
});
const dockerStub = sinon.createStubInstance(Dockerode, {
getContainer: sinon.stub().resolves(containerStub),
getImage: sinon.stub().returns(imageStub)
});

const error = await test.throwsAsync(getEntrypoint(dockerStub, imageName));

test.is(error.message, errorMessage);
});

test.serial('should not fail to get entrypoint', async (test) => {
const imageName = 'image';
const containerStub = sinon.createStubInstance(Dockerode.Container, {
inspect: sinon.stub().resolves({ Image: imageName })
});
const imageInspectStub = sinon.stub();
imageInspectStub.onFirstCall().resolves({
Config: {},
ContainerConfig: {},
Parent: `parent-${imageName}`
});
imageInspectStub.onSecondCall().resolves({
Config: {
Entrypoint: ['hello', 'entrypoint']
},
ContainerConfig: {}
});

const imageStub = sinon.createStubInstance(Dockerode.Image, {
inspect: imageInspectStub
});
const dockerStub = sinon.createStubInstance(Dockerode, {
getContainer: sinon.stub().resolves(containerStub),
getImage: sinon.stub().returns(imageStub)
});

await test.notThrowsAsync(getEntrypoint(dockerStub, imageName));
});

0 comments on commit 3f60e3f

Please sign in to comment.