Skip to content

Commit 717bb12

Browse files
committed
CH-87 Add detection of gunicorn in Dockerfile or requirements.txt
1 parent f210c6b commit 717bb12

17 files changed

Lines changed: 114 additions & 9 deletions

File tree

tools/deployment-cli-tools/ch_cli_tools/skaffold.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import time
55

6-
from os.path import join, dirname, relpath, basename
6+
from os.path import join, relpath, basename, exists, abspath
77
from cloudharness_model import ApplicationTestConfig, HarnessMainConfig
88

99
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
140140

141141
mains_candidates = find_file_paths(context_path, '__main__.py')
142142

143-
def identify_flask_main(candidates):
143+
def identify_unicorn_based_main(candidates):
144144
import re
145-
init_flask_pattern = re.compile(r"init_flask\(")
145+
gunicorn_pattern = re.compile(r"gunicorn")
146146
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()):
149161
return candidate
150162
return None
151163

152-
flask_main = identify_flask_main(mains_candidates)
164+
task_main_file = identify_unicorn_based_main(mains_candidates)
153165

154-
if flask_main:
166+
if task_main_file:
155167
release_config['overrides']['apps'][app_key] = \
156168
{
157169
'harness': {
158170
'deployment': {
159171
'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']
161173
}
162174
}
163175
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
ARG CLOUDHARNESS_FLASK
2-
FROM $CLOUDHARNESS_FLASK
2+
FROM $CLOUDHARNESS_FLASK
3+
4+
RUN pip install gunicorn
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.ignored
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ARG CLOUDHARNESS_FLASK
2+
FROM $CLOUDHARNESS_FLASK
3+
4+
RUN pip install -r requirements.txt

tools/deployment-cli-tools/tests/resources_buggy/applications/myapp2/deploy/resources/aresource.txt

Whitespace-only changes.

tools/deployment-cli-tools/tests/resources_buggy/applications/myapp2/deploy/templates/mytemplate.yaml

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
harness:
2+
name: "I'm useless"
3+
subdomain: mysubdomain
4+
dependencies:
5+
soft:
6+
- legacy
7+
build:
8+
- cloudharness-flask
9+
- my-common
10+
a: b
11+
dev: true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a: test
2+
test: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
harness:
2+
database:
3+
auto: true
4+
type: mongo

tools/deployment-cli-tools/tests/resources_buggy/applications/myapp2/deploy/values-withoutdb.yaml

Whitespace-only changes.

0 commit comments

Comments
 (0)