@@ -51,7 +51,7 @@ def build_artifact(image_name, context_path, requirements=None, dockerfile_path=
5151 in requirements ]
5252 return artifact_spec
5353
54-
54+
5555 base_images = set ()
5656
5757 def process_build_dockerfile (dockerfile_path , root_path , global_context = False , requirements = None , app_name = None ):
@@ -78,21 +78,21 @@ def process_build_dockerfile(dockerfile_path, root_path, global_context=False, r
7878
7979 for dockerfile_path in base_dockerfiles :
8080 process_build_dockerfile (dockerfile_path , root_path , global_context = True )
81-
82-
81+
82+
8383 release_config = skaffold_conf ['deploy' ]['helm' ]['releases' ][0 ]
8484 release_config ['name' ] = helm_values .namespace
8585 release_config ['namespace' ] = helm_values .namespace
8686 release_config ['artifactOverrides' ][KEY_APPS ] = {}
87-
87+
8888 static_images = set ()
8989 for root_path in root_paths :
9090 static_dockerfiles = find_dockerfiles_paths (
9191 join (root_path , STATIC_IMAGES_PATH ))
9292
9393 for dockerfile_path in static_dockerfiles :
9494 process_build_dockerfile (dockerfile_path , root_path )
95-
95+
9696
9797 for root_path in root_paths :
9898 apps_path = join (root_path , APPS_PATH )
@@ -138,22 +138,33 @@ def process_build_dockerfile(dockerfile_path, root_path, global_context=False, r
138138 }
139139 }
140140
141- flask_main = find_file_paths (context_path , '__main__.py' )
141+ mains_candidates = find_file_paths (context_path , '__main__.py' )
142+
143+ def identify_flask_main (candidates ):
144+ import re
145+ init_flask_pattern = re .compile (r"init_flask\(" )
146+ for candidate in candidates :
147+ with open (f"{ candidate } /__main__.py" , 'r' ) as file :
148+ if re .search (init_flask_pattern , file .read ()):
149+ return candidate
150+ return None
151+
152+ flask_main = identify_flask_main (mains_candidates )
142153
143154 if flask_main :
144155 release_config ['overrides' ]['apps' ][app_key ] = \
145156 {
146157 'harness' : {
147158 'deployment' : {
148159 'command' : ['python' ],
149- 'args' : [f'/usr/src/app/{ os .path .basename (flask_main [ 0 ] )} /__main__.py' ]
160+ 'args' : [f'/usr/src/app/{ os .path .basename (flask_main )} /__main__.py' ]
150161 }
151162 }
152163 }
153-
164+
154165 test_config : ApplicationTestConfig = helm_values .apps [app_key ].harness .test
155166 if test_config .unit .enabled and test_config .unit .commands :
156-
167+
157168 skaffold_conf ['test' ].append (dict (
158169 image = get_image_tag (app_name ),
159170 custom = [dict (command = "docker run $IMAGE " + cmd ) for cmd in test_config .unit .commands ]
@@ -209,7 +220,7 @@ def get_image_tag(name):
209220 "/usr/src/app" ),
210221 }
211222 })
212-
223+
213224
214225 if not os .path .exists (os .path .dirname (vscode_launch_path )):
215226 os .makedirs (os .path .dirname (vscode_launch_path ))
0 commit comments