|
3 | 3 | import json |
4 | 4 | import time |
5 | 5 |
|
6 | | -from os.path import join, dirname, relpath, basename |
| 6 | +from os.path import join, relpath, basename, exists, abspath |
7 | 7 | from cloudharness_model import ApplicationTestConfig, HarnessMainConfig |
8 | 8 |
|
9 | 9 | from cloudharness_utils.constants import APPS_PATH, DEPLOYMENT_CONFIGURATION_PATH, \ |
@@ -140,24 +140,36 @@ def process_build_dockerfile(dockerfile_path, root_path, global_context=False, r |
140 | 140 |
|
141 | 141 | mains_candidates = find_file_paths(context_path, '__main__.py') |
142 | 142 |
|
143 | | - def identify_flask_main(candidates): |
| 143 | + def identify_unicorn_based_main(candidates): |
144 | 144 | import re |
145 | | - init_flask_pattern = re.compile(r"init_flask\(") |
| 145 | + gunicorn_pattern = re.compile(r"gunicorn") |
146 | 146 | for candidate in candidates: |
147 | | - with open(f"{candidate}/__main__.py", 'r') as file: |
148 | | - if re.search(init_flask_pattern, file.read()): |
| 147 | + dockerfile_path = f"{candidate}/.." |
| 148 | + while not exists(f"{dockerfile_path}/Dockerfile") and abspath(dockerfile_path) != abspath(root_path): |
| 149 | + dockerfile_path += "/.." |
| 150 | + dockerfile = f"{dockerfile_path}/Dockerfile" |
| 151 | + if not exists(dockerfile): |
| 152 | + continue |
| 153 | + with open(dockerfile, 'r') as file: |
| 154 | + if re.search(gunicorn_pattern, file.read()): |
| 155 | + return candidate |
| 156 | + requirements = f"{candidate}/../requirements.txt" |
| 157 | + if not exists(requirements): |
| 158 | + continue |
| 159 | + with open(requirements, 'r') as file: |
| 160 | + if re.search(gunicorn_pattern, file.read()): |
149 | 161 | return candidate |
150 | 162 | return None |
151 | 163 |
|
152 | | - flask_main = identify_flask_main(mains_candidates) |
| 164 | + task_main_file = identify_unicorn_based_main(mains_candidates) |
153 | 165 |
|
154 | | - if flask_main: |
| 166 | + if task_main_file: |
155 | 167 | release_config['overrides']['apps'][app_key] = \ |
156 | 168 | { |
157 | 169 | 'harness': { |
158 | 170 | 'deployment': { |
159 | 171 | 'command': ['python'], |
160 | | - 'args': [f'/usr/src/app/{os.path.basename(flask_main)}/__main__.py'] |
| 172 | + 'args': [f'/usr/src/app/{os.path.basename(task_main_file)}/__main__.py'] |
161 | 173 | } |
162 | 174 | } |
163 | 175 | } |
|
0 commit comments