@ -886,11 +886,18 @@ class ContainerManager(DockerBaseClass):
except Exception as exc :
self . client . fail ( " Error: service image lookup failed - %s " % str ( exc ) )
out_redir_name , err_redir_name = make_redirection_tempfiles ( )
# pull the image
try :
service . pull ( ignore_pull_failures = False )
with stdout_redirector ( out_redir_name ) :
with stderr_redirector ( err_redir_name ) :
service . pull ( ignore_pull_failures = False )
except Exception as exc :
self . client . fail ( " Error: pull failed with %s " % str ( exc ) )
fail_reason = get_failure_info ( exc , out_redir_name , err_redir_name ,
msg_format = " Error: pull failed with %s " )
self . client . fail ( * * fail_reason )
else :
cleanup_redirection_tempfiles ( out_redir_name , err_redir_name )
# store the new image ID
new_image_id = ' '
@ -933,11 +940,18 @@ class ContainerManager(DockerBaseClass):
except Exception as exc :
self . client . fail ( " Error: service image lookup failed - %s " % str ( exc ) )
out_redir_name , err_redir_name = make_redirection_tempfiles ( )
# build the image
try :
new_image_id = service . build ( pull = self . pull , no_cache = self . nocache )
with stdout_redirector ( out_redir_name ) :
with stderr_redirector ( err_redir_name ) :
new_image_id = service . build ( pull = self . pull , no_cache = self . nocache )
except Exception as exc :
self . client . fail ( " Error: build failed with %s " % str ( exc ) )
fail_reason = get_failure_info ( exc , out_redir_name , err_redir_name ,
msg_format = " Error: build failed with %s " )
self . client . fail ( * * fail_reason )
else :
cleanup_redirection_tempfiles ( out_redir_name , err_redir_name )
if new_image_id not in old_image_id :
# if a new image was built
@ -966,10 +980,17 @@ class ContainerManager(DockerBaseClass):
) )
if not self . check_mode and result [ ' changed ' ] :
image_type = image_type_from_opt ( ' --rmi ' , self . remove_images )
out_redir_name , err_redir_name = make_redirection_tempfiles ( )
try :
self . project . down ( image_type , self . remove_volumes , self . remove_orphans )
with stdout_redirector ( out_redir_name ) :
with stderr_redirector ( err_redir_name ) :
self . project . down ( image_type , self . remove_volumes , self . remove_orphans )
except Exception as exc :
self . client . fail ( " Error stopping project - %s " % str ( exc ) )
fail_reason = get_failure_info ( exc , out_redir_name , err_redir_name ,
msg_format = " Error stopping project - %s " )
self . client . fail ( * * fail_reason )
else :
cleanup_redirection_tempfiles ( out_redir_name , err_redir_name )
return result
def cmd_stop ( self , service_names ) :
@ -1057,10 +1078,17 @@ class ContainerManager(DockerBaseClass):
result [ ' changed ' ] = True
service_res [ ' scale ' ] = scale - len ( containers )
if not self . check_mode :
out_redir_name , err_redir_name = make_redirection_tempfiles ( )
try :
service . scale ( scale )
with stdout_redirector ( out_redir_name ) :
with stderr_redirector ( err_redir_name ) :
service . scale ( scale )
except Exception as exc :
self . client . fail ( " Error scaling %s - %s " % ( service . name , str ( exc ) ) )
fail_reason = get_failure_info ( exc , out_redir_name , err_redir_name ,
msg_format = " Error scaling {0} - %s " . format ( service . name ) )
self . client . fail ( * * fail_reason )
else :
cleanup_redirection_tempfiles ( out_redir_name , err_redir_name )
result [ ' actions ' ] . append ( service_res )
return result