@@ -264,22 +264,45 @@ Docker.prototype.getLogs = function (containerId, tail, cb) {
264264 }
265265} ;
266266
267-
268-
269- Docker . prototype . createAndInspectContainer = function ( version , opts , cb ) {
270- debug ( 'createAndInspectContainer' , formatArgs ( arguments ) ) ;
271- var self = this ;
272- if ( typeof opts === 'function' ) {
267+ /**
268+ * creates a user container
269+ * @param version: version object which containes build
270+ * @param opts: opts to pass to docker
271+ * @param cb: Callback
272+ */
273+ Docker . prototype . createUserContainer = function ( version , opts , cb ) {
274+ debug ( 'createUserContainer' , formatArgs ( arguments ) ) ;
275+ if ( ! version . build || ! version . build . dockerTag ) {
276+ return cb ( Boom . badRequest ( 'Cannot create a container for an unbuilt version' , {
277+ debug : { versionId : version . _id . toString ( ) }
278+ } ) ) ;
279+ }
280+ if ( isFunction ( opts ) ) {
273281 cb = opts ;
274282 opts = { } ;
275283 }
276- // Create opts
277- opts . create = opts . create || { } ;
278- extend ( opts . create , {
284+ extend ( opts , {
279285 Image : version . build . dockerTag
280286 } ) ;
281- // Start opts
282- opts . start = opts . start || { } ;
287+
288+ this . createContainer ( opts , cb ) ;
289+ } ;
290+
291+ /**
292+ * start a user container
293+ * @param container: container object to start
294+ * @param opts: opts to pass to docker
295+ * @param cb: Callback
296+ */
297+ Docker . prototype . startUserContainer = function ( container , opts , cb ) {
298+ debug ( 'startUserContainer' , formatArgs ( arguments ) ) ;
299+ if ( ! container ) {
300+ return cb ( Boom . badRequest ( 'Container must be provided to start' ) ) ;
301+ }
302+ if ( isFunction ( opts ) ) {
303+ cb = opts ;
304+ opts = { } ;
305+ }
283306
284307 // order matters here , our custom DNS should come first
285308 var dns = [ ] ;
@@ -288,40 +311,31 @@ Docker.prototype.createAndInspectContainer = function (version, opts, cb) {
288311 }
289312 dns . push ( process . env . DNS_DEFAULT_IPADDRESS ) ;
290313
291- extend ( opts . start , {
314+ extend ( opts , {
292315 PublishAllPorts : true ,
293316 Dns : dns
294317 } ) ;
295318
296- async . waterfall ( [
297- createContainer ,
298- startContainer
299- ] , cb ) ;
300- function createContainer ( cb ) {
301- self . createContainer ( opts . create , cb ) ;
302- }
303- function startContainer ( container , cb ) {
304- self . startContainer ( container , opts . start , function ( err ) {
305- cb ( err , container ) ;
306- } ) ;
307- }
319+ this . startContainer ( container , opts , cb ) ;
308320} ;
309321
310- Docker . prototype . createContainerForVersion = function ( version , opts , cb ) {
311- debug ( 'createContainerForVersion' , formatArgs ( arguments ) ) ;
312- if ( typeof opts === 'function' ) {
313- cb = opts ;
314- opts = { } ;
315- }
316- if ( ! version . build || ! version . build . dockerImage ) {
317- return cb ( Boom . badRequest ( 'Cannot create a container for an unbuilt version' , {
318- debug : { versionId : version . _id . toString ( ) }
319- } ) ) ;
322+ /**
323+ * inspect a user container
324+ * @param container: container object to inspect
325+ * @param cb: Callback
326+ */
327+ Docker . prototype . inspectUserContainer = function ( container , cb ) {
328+ debug ( 'inspectUserContainer' , formatArgs ( arguments ) ) ;
329+ if ( ! container ) {
330+ return cb ( Boom . badRequest ( 'Container must be provided to start' ) ) ;
320331 }
321- this . createAndInspectContainer ( version , opts , cb ) ;
332+ var self = this ;
333+ self . inspectContainer ( container , function ( err , inspect ) {
334+ if ( err ) { return cb ( err ) ; }
335+ inspect . dockerHost = self . dockerHost ;
336+ cb ( null , inspect ) ;
337+ } ) ;
322338} ;
323-
324-
325339/**
326340 * CONTAINER METHODS - START
327341 */
@@ -334,7 +348,7 @@ Docker.prototype.createContainerForVersion = function (version, opts, cb) {
334348Docker . prototype . createContainer = function ( opts , cb ) {
335349 debug ( 'createContainer' , formatArgs ( arguments ) ) ;
336350 var self = this ;
337- if ( typeof opts === 'function' ) {
351+ if ( isFunction ( opts ) ) {
338352 cb = opts ;
339353 opts = { } ;
340354 }
@@ -370,7 +384,7 @@ Docker.prototype.startContainer = function (container, opts, cb) {
370384 debug ( 'startContainer' , formatArgs ( arguments ) ) ;
371385 var self = this ;
372386 var containerId = container . dockerContainer || container . Id ;
373- if ( typeof opts === 'function' ) {
387+ if ( isFunction ( opts ) ) {
374388 cb = opts ;
375389 opts = { } ;
376390 }
@@ -395,6 +409,17 @@ Docker.prototype.restartContainer = function (container, cb) {
395409 self . handleErr ( cb , 'Restart container failed' , { containerId : containerId } ) ) ;
396410} ;
397411
412+ /**
413+ * pulls image and returns stream
414+ * @param contextVersion - format 'myrepo/myname:tag'
415+ * @param cb: Callback
416+ */
417+ Docker . prototype . pullImage = function ( version , cb ) {
418+ debug ( 'pullImage' , formatArgs ( arguments ) ) ;
419+ var self = this ;
420+ self . docker . pull ( version . build . dockerTag , cb ) ;
421+ } ;
422+
398423/**
399424 * attempts to stop a running container.
400425 * if not stopped in passed in time, the process is kill 9'd
0 commit comments