Skip to content

Commit a20a86b

Browse files
committed
Merge pull request #440 from CodeNow/multi-dock
send more data to mavis
2 parents a120fc1 + 75c11ac commit a20a86b

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

lib/models/apis/mavis.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var ApiClient = require('simple-api-client');
66
var util = require('util');
77
var Boom = require('dat-middleware').Boom;
88
var debug = require('debug')('runnable-api:mavis:model');
9+
var isObject = require('101/is-object');
10+
var isFunction = require('101/is-function');
911

1012
module.exports = Mavis;
1113

@@ -23,7 +25,37 @@ util.inherits(Mavis, ApiClient);
2325
*/
2426
Mavis.prototype.findDockForNetwork = function (cb) {
2527
debug('findDockForNetwork', formatArgs(arguments));
26-
this.findDock('container_run', cb);
28+
this.findDockForContainer({}, cb);
29+
};
30+
31+
Mavis.prototype.findDockForBuild = function (contextVersion, cb) {
32+
debug('findDockForBuild', formatArgs(arguments));
33+
34+
if (!isObject(contextVersion)) {
35+
return cb(new Error('missing contextVersion'));
36+
}
37+
38+
var opts = {
39+
type: 'container_build'
40+
};
41+
opts.prevDuration = contextVersion.duration || 0;
42+
opts.prevImage = contextVersion.dockerTag || null;
43+
this.findDock(opts, cb);
44+
};
45+
46+
Mavis.prototype.findDockForContainer = function (contextVersion, cb) {
47+
debug('findDockForContainer', formatArgs(arguments));
48+
49+
if (!isObject(contextVersion)) {
50+
return cb(new Error('missing contextVersion'));
51+
}
52+
53+
var opts = {
54+
type: 'container_run'
55+
};
56+
// if dockerHost is not an address, its invalid
57+
opts.prevDock = contextVersion.dockerHost || null;
58+
this.findDock(opts, cb);
2759
};
2860

2961
/**
@@ -32,23 +64,11 @@ Mavis.prototype.findDockForNetwork = function (cb) {
3264
* @param prevDock: previous dock this image was run on
3365
* @param cb: Callback
3466
*/
35-
Mavis.prototype.findDock = function (taskType, prevDock, cb) {
36-
if (typeof prevDock === 'function') {
37-
cb = prevDock;
38-
prevDock = null;
39-
}
40-
41-
// if prevDock is not an address, its invalid
42-
if(prevDock && !~prevDock.indexOf('http')){
43-
prevDock = null;
44-
}
67+
Mavis.prototype.findDock = function (opts, cb) {
4568
// path must have trailing slash to ensure this is a file
4669
var self = this;
4770
this.post('dock', {
48-
json: {
49-
type: taskType,
50-
prevDock: prevDock
51-
}
71+
json: opts
5272
}, function (err, res) {
5373
if (err) {
5474
var boomErr = Boom.create(504, 'Unable to find dock', {
@@ -99,10 +119,6 @@ function responseErr (res) {
99119
});
100120
}
101121

102-
// TODO: add all the findDock types
103-
// Mavis.prototype.findDockForContainerCreate
104-
105-
var isFunction = require('101/is-function');
106122
function formatArgs (args) {
107123
return Array.prototype.slice.call(args)
108124
.map(function (arg) {

lib/routes/builds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ app.post('/builds/:id/actions/build',
239239
}))
240240
).else(
241241
mavis.create(),
242-
mavis.model.findDock('container_build'),
242+
mavis.model.findDockForBuild('contextVersion'),
243243
contextVersions.model.setBuildStarted('sessionUser', 'mavisResult', 'body'),
244244
docker.create('mavisResult'),
245245
contextVersions.model.populate('infraCodeVersion'),

lib/routes/contexts/versions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ app.post('/contexts/:contextId/versions/:id/actions/build',
214214
checkFound('contextVersion'),
215215
flow.try(
216216
mavis.create(),
217-
mavis.model.findDock('container_build', 'contextVersion.dockerHost'),
217+
mavis.model.findDockForContainer('contextVersion'),
218218
mw.req().set('originalContextVersion', 'contextVersion'),
219219
contextVersions.model.dedupe(),
220220
// FIXME: handle errors - bc if buildStarted this falls through to catch

lib/routes/instances/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ var createSaveAndNetworkContainer = flow.series(
122122
mw.req().set('dockerHost', 'body.forceDock'))
123123
.else(
124124
mavis.create(),
125-
mavis.model.findDock('container_run', 'contextVersion.dockerHost'),
125+
mavis.model.findDockForContainer('contextVersion'),
126126
mw.req().set('dockerHost', 'mavisResult')),
127127
flow.try(
128128
docker.create('dockerHost'),

0 commit comments

Comments
 (0)