Skip to content

Commit 6ae79f5

Browse files
committed
Merge pull request #427 from CodeNow/filter-image-builder-event
add image ignore
2 parents a20a86b + b8d3697 commit 6ae79f5

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

configs/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ GITHUB_DEPLOY_KEYS_POOL_SIZE=100
1717
GITHUB_DEPLOY_KEY_BITS=2048
1818
HASHIDS_SALT="VvCCYj8x3xaHs44QiDp9"
1919
HASHIDS_LENGTH=6
20+
DOCKER_IMAGE_BUILDER_NAME="runnable/image-builder"
2021
DOCKER_IMAGE_BUILDER_VERSION="d1.3.1-v1.4.3"
2122
DOCKER_IMAGE_BUILDER_CACHE="/tmp"
2223
BUILD_END_TIMEOUT=100

lib/models/apis/docker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Docker.prototype.createImageBuilderAndAttach = function (sessionUser, version, c
117117
var self = this;
118118
debug('create container');
119119
var builderContainerData = {
120-
Image: 'runnable/image-builder:' + process.env.DOCKER_IMAGE_BUILDER_VERSION,
120+
Image: process.env.DOCKER_IMAGE_BUILDER_NAME + ':' + process.env.DOCKER_IMAGE_BUILDER_VERSION,
121121
Env : getEnvForImageBuilder(version, dockerTag),
122122
Binds: []
123123
};

lib/models/events/docker.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ DockerEvents.prototype.handleDie = function (data) {
130130
if (err) {
131131
return logErr(err);
132132
}
133+
if (isImageBuilder(data)) {
134+
return { skip: data };
135+
}
133136
var containerId = data.id;
134137
activeApi.isMe(function (err, meIsActiveApi) {
135138
if (err) { return logErr(err); }
@@ -178,7 +181,12 @@ DockerEvents.prototype.handleDie = function (data) {
178181
}
179182
};
180183

184+
function isImageBuilder (data) {
185+
return ~data.from.indexOf(process.env.DOCKER_IMAGE_BUILDER_NAME);
186+
}
187+
181188
function validateDieEventData (data) {
189+
/*jshint maxcomplexity:6*/
182190
if (!data.uuid) {
183191
return Boom.badRequest('Invalid data: uuid is missing');
184192
}
@@ -191,6 +199,9 @@ function validateDieEventData (data) {
191199
if (!data.host) {
192200
return Boom.badRequest('Invalid data: host is missing');
193201
}
202+
if (!data.from) {
203+
return Boom.badRequest('Invalid data: from is missing');
204+
}
194205
}
195206

196207
// Singleton

unit/docker-events.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ describe('Docker Events', function () {
7070
dockerEvents.handleDie({uuid: 'some-uuid', id: 'some-id', time: new Date().getTime() });
7171
});
7272

73+
it('should return if image builder image', function (done) {
74+
var out = dockerEvents.handleDie({
75+
uuid: 'some-uuid',
76+
id: 'some-id',
77+
time: new Date().getTime(),
78+
host: 'http://localhost:4243',
79+
from: process.env.IMAGE_BUILDER
80+
});
81+
expect(out).to.have.property('skip');
82+
done();
83+
});
84+
7385
describe('while closing', function () {
7486
afterEach(dockerEvents.close.bind(dockerEvents));
7587

@@ -133,7 +145,8 @@ describe('Docker Events', function () {
133145
uuid: 'some-uuid',
134146
id: 'some-id',
135147
time: new Date().getTime(),
136-
host: 'http://127.0.0.1:4242'
148+
host: 'http://127.0.0.1:4242',
149+
from: 'container/name'
137150
};
138151
de.handleDie(data);
139152
});
@@ -244,7 +257,8 @@ describe('Docker Events', function () {
244257
uuid: uuid(),
245258
id: 'some-id',
246259
time: new Date().getTime(),
247-
host: 'http://localhost:4243'
260+
host: 'http://localhost:4243',
261+
from: 'container/name'
248262
};
249263
dockerEvents.handleDie(payload);
250264
dockerEvents.handleDie(payload);

0 commit comments

Comments
 (0)