@@ -127,24 +127,31 @@ var createSaveAndNetworkContainer = flow.series(
127127 . catch (
128128 mw . req ( ) . setToErr ( 'containerCreateErr' ) ,
129129 mw . req ( 'containerCreateErr.output.statusCode' ) . validate ( validations . equals ( 404 ) )
130+ . then (
131+ mw . req ( ) . set ( 'containerCreateErr.imageIsPulling' , true ) ) ,
132+ instances . model . modifyContainerCreateErr ( 'containerCreateErr' ) ,
133+ mw . req ( 'containerCreateErr.imageIsPulling' ) . validate ( validations . equals ( true ) )
130134 . then (
131135 docker . model . pullImage ( 'contextVersion' ) ,
132136 function ( req , res , next ) {
133137 // emitter.emit('dockerResult') need to emit pull event here
134- req . dockerResult . on ( 'data' , function ( ) { } ) ;
138+ req . dockerResult . on ( 'data' , function ( ) {
139+ // TODO: pipe to pull-stream
140+ } ) ;
141+ // on pull finish, redeploy instance
142+ req . dockerResult . on ( 'end' , function ( ) {
143+ flow . series (
144+ runnable . create ( { } , 'sessionUser' ) ,
145+ runnable . model . redeployInstance ( 'instance' , {
146+ forceDock : 'dockerHost' ,
147+ json : { build : 'build._id.toString()' }
148+ } ) ) ( req , res , function ( err ) {
149+ error . logIfErr ( err , req ) ;
150+ } ) ;
151+ } ) ;
152+ // next immediately, background pull and redeploy
135153 next ( ) ;
136- } ,
137- runnable . create ( { } , 'sessionUser' ) ,
138- // redeploy instance with host. remove lock associated with redeploy route
139- hosts . model . releaseHostLock ( 'ownerUsername' , 'instance.name' ) ,
140- runnable . model . redeployInstance ( 'instance' , {
141- forceDock : 'dockerHost' ,
142- json : { build : 'build._id.toString()' }
143- } ) ,
144- hosts . model . acquireHostLock ( 'ownerUsername' , 'instance.name' ) ,
145- instances . findById ( 'instanceId' ) )
146- . else (
147- instances . model . modifyContainerCreateErr ( 'containerCreateErr' ) ) ) ,
154+ } ) ) ,
148155 mw . req ( 'containerInfo' ) . require ( )
149156 . then ( // container create was successful
150157 docker . model . startUserContainer ( 'containerInfo' ) ,
0 commit comments