@@ -6,6 +6,8 @@ var ApiClient = require('simple-api-client');
66var util = require ( 'util' ) ;
77var Boom = require ( 'dat-middleware' ) . Boom ;
88var debug = require ( 'debug' ) ( 'runnable-api:mavis:model' ) ;
9+ var isObject = require ( '101/is-object' ) ;
10+ var isFunction = require ( '101/is-function' ) ;
911
1012module . exports = Mavis ;
1113
@@ -23,7 +25,37 @@ util.inherits(Mavis, ApiClient);
2325 */
2426Mavis . 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' ) ;
106122function formatArgs ( args ) {
107123 return Array . prototype . slice . call ( args )
108124 . map ( function ( arg ) {
0 commit comments