Skip to content

Commit

Permalink
fix(jobs): will pull the docker image of the runner before starting it (
Browse files Browse the repository at this point in the history
  • Loading branch information
enudler authored and NivLipetz committed Feb 20, 2019
1 parent aa69465 commit 4ebf829
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ jobs:
- run: npm run unit-tests
- store_artifacts:
path: ./coverage
- run:
name: pull zooz/predator-runner:latest
command: ssh remote-docker \ docker pull zooz/predator-runner:latest
- run:
name: Integration tests with docker engine and sqlite configuration
command: npm run integration-tests
Expand Down
15 changes: 15 additions & 0 deletions src/jobs/models/docker/jobConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,22 @@ if (dockerConfig.host) {
}
let docker = new Docker(dockerConnection);

const pullImage = async (dockerImage) => {
let dockerImageStream = await docker.pull(dockerImage);
return new Promise((resolve, reject) => {
docker.modem.followProgress(dockerImageStream, (err) => {
if (!err) {
return resolve();
} else {
return reject(err);
}
});
});
};

module.exports.runJob = async (dockerJobConfig) => {
await pullImage(dockerJobConfig.dockerImage);

let envVarArray = Object.keys(dockerJobConfig.environmentVariables).map((envVar) => {
return `${envVar}=${dockerJobConfig.environmentVariables[envVar]}`;
});
Expand Down
28 changes: 26 additions & 2 deletions tests/unit-tests/jobs/models/docker/jobConnector-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let rewire = require('rewire');
let jobConnector = rewire('../../../../../src/jobs/models/docker/jobConnector');
describe('Docker job connector tests', function () {
let sandbox, createContainerStub, listContainersStub, getContainerStub, containerStopStub,
startContainerStub;
startContainerStub, pullStub, modemStub, followProgressStub;

let dockerJobConfig = {
environmentVariables: {
Expand Down Expand Up @@ -37,10 +37,20 @@ describe('Docker job connector tests', function () {

getContainerStub.resolves({ stop: containerStopStub });

pullStub = sandbox.stub();

followProgressStub = sandbox.stub();
followProgressStub.yields();
modemStub = {
followProgress: followProgressStub
};

jobConnector.__set__('docker', {
createContainer: createContainerStub,
listContainers: listContainersStub,
getContainer: getContainerStub
getContainer: getContainerStub,
pull: pullStub,
modem: modemStub
});
});

Expand All @@ -53,6 +63,9 @@ describe('Docker job connector tests', function () {
dockerJobConfig.parallelism = 3;
let jobResponse = await jobConnector.runJob(dockerJobConfig);

should(pullStub.callCount).eql(1);
should(pullStub.args[0][0]).eql('image');

should(createContainerStub.callCount).eql(3);

createContainerStub.callCount.should.eql(3);
Expand Down Expand Up @@ -96,6 +109,17 @@ describe('Docker job connector tests', function () {
startContainerStub.callCount.should.eql(1);
});

it('Fail to create a job - error on pulling image', async () => {
followProgressStub.yields(new Error('Failure pulling image'));

try {
await jobConnector.runJob(dockerJobConfig);
throw new Error('Should not get here');
} catch (error) {
error.should.eql(new Error('Failure pulling image'));
}
});

it('Fail to create a job - error on create containers', async () => {
createContainerStub.rejects(new Error('Failure to create docker'));

Expand Down

0 comments on commit 4ebf829

Please sign in to comment.