#NEWLINE# def _build_with_dockerfile( self , build_path ) : #NEWLINE# #INDENT# info_log ( self . TAG , 'Building the app image with Dockerfile...' , app = self . name ) #NEWLINE# app_img_path = os . path . join ( build_path , 'app' ) #NEWLINE# repo_path = os . path . join ( app_img_path , 'repo' ) #NEWLINE# repo_df_path = os . path . join ( app_img_path , os . path . join ( repo_path , 'Dockerfile' ) ) #NEWLINE# final_df_path = os . path . join ( app_img_path , 'Dockerfile' ) #NEWLINE# with open ( final_df_path , 'w+' ) as final_df : #NEWLINE# #INDENT# with open ( repo_df_path , 'r' ) as repo_df : #NEWLINE# #INDENT# def filter_from( line ) : #NEWLINE# #INDENT# if line . startswith ( 'FROM ' ) : #NEWLINE# #INDENT# if ( not line . strip ( ) . endswith ( '/binder-base' ) ) : #NEWLINE# #INDENT# msg = 'Dockerfile base image is not binder-base. Building may fail.' #NEWLINE# warning_log ( self . TAG , msg , app = self . name ) #NEWLINE# #UNINDENT# return False #NEWLINE# #UNINDENT# return True #NEWLINE# #UNINDENT# lines = repo_df . readlines ( ) #NEWLINE# no_from = filter ( ( lambda line : filter_from ( line ) ) , lines ) #NEWLINE# final_lines = ( [ 'FROM {}\n' . format ( self . _get_base_image_name ( ) ) ] + no_from ) #NEWLINE# for line in final_lines : #NEWLINE# #INDENT# final_df . write ( line ) #NEWLINE# #UNINDENT# final_df . write ( '\n' ) #NEWLINE# final_df . write ( 'USER main\n' ) #NEWLINE# final_df . write ( '\n' ) #NEWLINE# notebook_path = ( self . _json [ 'notebooks' ] if ( 'notebooks' in self . _json ) else '.' ) #NEWLINE# final_df . write ( 'ADD {0} $HOME/notebooks\n' . format ( notebook_path ) ) #NEWLINE# final_df . write ( '\n' ) #NEWLINE# nb_img_path = os . path . join ( build_path , 'suffix' ) #NEWLINE# with open ( os . path . join ( nb_img_path , 'Dockerfile' ) , 'r' ) as nb_img : #NEWLINE# #INDENT# for line in nb_img . readlines ( ) : #NEWLINE# #INDENT# final_df . write ( line ) #NEWLINE# #UNINDENT# final_df . write ( '\n' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# shutil . move ( final_df_path , repo_df_path ) #NEWLINE# info_log ( self . TAG , 'Starting custom Dockerfile build (download logs for more details)' , app = self . name ) #NEWLINE# try : #NEWLINE# #INDENT# image_name = self . _get_image_name ( ) . lower ( ) #NEWLINE# cmd = [ 'docker' , 'build' , '-t' , image_name , '--no-cache' , os . path . join ( app_img_path , 'repo' ) ] #NEWLINE# proc = subprocess . Popen ( final_lines , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) #NEWLINE# write_stream ( self . TAG , 'info' , proc . stdout , app = self . name , no_publish = True ) #NEWLINE# write_stream ( self . TAG , 'error' , proc . stderr , app = self . name , no_publish = True ) #NEWLINE# exit_code = proc . wait ( ) #NEWLINE# if ( exit_code != 0 ) : #NEWLINE# #INDENT# raise subprocess . CalledProcessError ( exit_code , cmd = cmd ) #NEWLINE# #UNINDENT# #UNINDENT# except subprocess . CalledProcessError as e : #NEWLINE# #INDENT# error_log ( self . TAG , 'Dockerfile build failed! (download logs for more details)' , app = self . name ) #NEWLINE# raise App . BuildFailedException ( 'could not build app {0}: {1}' . format ( self . name , e ) ) #NEWLINE# #UNINDENT# info_log ( self . TAG , 'Completed custom Dockerfile build' , app = self . name )