@@ -154,6 +154,56 @@ def e2e_test_environment(app_config: ApplicationHarnessConfig, app_domain: str =
154154 env = get_app_environment (app_config , app_domain , False )
155155 return [f"{ k } ={ env [k ]} " for k in env ]
156156
157+ def codefresh_app_build_spec (app_name , app_context_path , dockerfile_path = "Dockerfile" , base_name = None , helm_values : HarnessMainConfig = {}, dependencies = None ):
158+ logging .info ('Generating build script for ' + app_name )
159+ title = app_name .capitalize ().replace (
160+ '-' , ' ' ).replace ('/' , ' ' ).replace ('.' , ' ' ).strip ()
161+ build = codefresh_template_spec (
162+ template_path = CF_BUILD_PATH ,
163+ image_name = get_image_name (app_name , base_name ),
164+ title = title ,
165+ working_directory = './' + app_context_path ,
166+ dockerfile = dockerfile_path )
167+
168+ tag = app_specific_tag_variable (app_name )
169+ build ["tag" ] = "${{%s}}" % tag
170+
171+ specific_build_template_path = join (app_context_path , 'build.yaml' )
172+ if exists (specific_build_template_path ):
173+ logging .info ("Specific build template found: %s" %
174+ (specific_build_template_path ))
175+ with open (specific_build_template_path ) as f :
176+ build_specific = yaml .safe_load (f )
177+
178+ build_specific .pop (
179+ 'build_arguments' ) if 'build_arguments' in build_specific else []
180+
181+ build ['dependencies' ] = dependencies
182+
183+ def get_other_image_name (app_name ):
184+ return ("${{REGISTRY}}/" + f"{ build_steps [app_name ]['image_name' ]} :{ build_steps [app_name ]['tag' ]} " )\
185+ if app_name in build_steps \
186+ else image_tag_with_variables (app_name , app_specific_tag_variable (app_name ), base_name )
187+
188+ def add_arg_dependencies (dependencies ):
189+ arg_dependencies = [f"{ d .upper ().replace ('-' , '_' )} ={ get_other_image_name (d )} "
190+ for d in dependencies ]
191+ build ['build_arguments' ].extend (arg_dependencies )
192+
193+ values_key = app_name
194+ if dependencies is not None :
195+ add_arg_dependencies (dependencies )
196+ elif values_key in helm_values .apps :
197+ try :
198+ add_arg_dependencies (
199+ helm_values .apps [values_key ].harness .dependencies .build )
200+ except (KeyError , AttributeError ):
201+ add_arg_dependencies (helm_values ['task-images' ])
202+
203+ when_condition = existing_build_when_condition (tag )
204+ build ["when" ] = when_condition
205+ return build
206+
157207 def codefresh_steps_from_base_path (base_path , fixed_context = None , include = build_included , publish = True ):
158208 found = False
159209 for dockerfile_path in find_dockerfiles_paths (base_path ):
@@ -433,52 +483,6 @@ def app_specific_tag_variable(app_name):
433483 return "%s_TAG" % app_name .replace ('-' , '_' ).upper ().strip ()
434484
435485
436- def codefresh_app_build_spec (app_name , app_context_path , dockerfile_path = "Dockerfile" , base_name = None , helm_values : HarnessMainConfig = {}, dependencies = None ):
437- logging .info ('Generating build script for ' + app_name )
438- title = app_name .capitalize ().replace (
439- '-' , ' ' ).replace ('/' , ' ' ).replace ('.' , ' ' ).strip ()
440- build = codefresh_template_spec (
441- template_path = CF_BUILD_PATH ,
442- image_name = get_image_name (app_name , base_name ),
443- title = title ,
444- working_directory = './' + app_context_path ,
445- dockerfile = dockerfile_path )
446-
447- tag = app_specific_tag_variable (app_name )
448- build ["tag" ] = "${{%s}}" % tag
449-
450- specific_build_template_path = join (app_context_path , 'build.yaml' )
451- if exists (specific_build_template_path ):
452- logging .info ("Specific build template found: %s" %
453- (specific_build_template_path ))
454- with open (specific_build_template_path ) as f :
455- build_specific = yaml .safe_load (f )
456-
457- build_specific .pop (
458- 'build_arguments' ) if 'build_arguments' in build_specific else []
459-
460- build ['dependencies' ] = dependencies
461-
462- def add_arg_dependencies (dependencies ):
463- arg_dependencies = [f"{ d .upper ().replace ('-' , '_' )} ={ image_tag_with_variables (d , app_specific_tag_variable (d ), base_name )} " for
464- d in dependencies ]
465- build ['build_arguments' ].extend (arg_dependencies )
466-
467- values_key = app_name
468- if dependencies is not None :
469- add_arg_dependencies (dependencies )
470- elif values_key in helm_values .apps :
471- try :
472- add_arg_dependencies (
473- helm_values .apps [values_key ].harness .dependencies .build )
474- except (KeyError , AttributeError ):
475- add_arg_dependencies (helm_values ['task-images' ])
476-
477- when_condition = existing_build_when_condition (tag )
478- build ["when" ] = when_condition
479- return build
480-
481-
482486def existing_build_when_condition (tag ):
483487 """
484488 See https://codefresh.io/docs/docs/pipelines/conditional-execution-of-steps/#execute-steps-according-to-the-presence-of-a-variable
0 commit comments