Skip to content

Commit 8f52735

Browse files
authored
Merge pull request #710 from MetaCell/feature/CH-87
Feature/ch 87
2 parents 1d9aef6 + 717bb12 commit 8f52735

34 files changed

Lines changed: 256 additions & 14 deletions

File tree

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

Lines changed: 36 additions & 13 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, \
@@ -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,45 @@ 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')
142-
143-
if flask_main:
141+
mains_candidates = find_file_paths(context_path, '__main__.py')
142+
143+
def identify_unicorn_based_main(candidates):
144+
import re
145+
gunicorn_pattern = re.compile(r"gunicorn")
146+
for candidate in candidates:
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()):
161+
return candidate
162+
return None
163+
164+
task_main_file = identify_unicorn_based_main(mains_candidates)
165+
166+
if task_main_file:
144167
release_config['overrides']['apps'][app_key] = \
145168
{
146169
'harness': {
147170
'deployment': {
148171
'command': ['python'],
149-
'args': [f'/usr/src/app/{os.path.basename(flask_main[0])}/__main__.py']
172+
'args': [f'/usr/src/app/{os.path.basename(task_main_file)}/__main__.py']
150173
}
151174
}
152175
}
153-
176+
154177
test_config: ApplicationTestConfig = helm_values.apps[app_key].harness.test
155178
if test_config.unit.enabled and test_config.unit.commands:
156-
179+
157180
skaffold_conf['test'].append(dict(
158181
image=get_image_tag(app_name),
159182
custom=[dict(command="docker run $IMAGE " + cmd) for cmd in test_config.unit.commands]
@@ -209,7 +232,7 @@ def get_image_tag(name):
209232
"/usr/src/app"),
210233
}
211234
})
212-
235+
213236

214237
if not os.path.exists(os.path.dirname(vscode_launch_path)):
215238
os.makedirs(os.path.dirname(vscode_launch_path))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
**/node_modules
2+
.tox
3+
docs
4+
applications
5+
/infrastructure
6+
/blueprint
7+
test
8+
/tools/deployment-cli-tools
9+
.github
10+
.git
11+
.vscode
12+
/deployment
13+
skaffold.yaml
14+
*.egg-info
15+
__pycache__
16+
.hypothesis
17+
.coverage
18+
.pytest_cache
19+
/application-templates
20+
/deployment-configuration
21+
/cloud-harness
22+
.openapi-generator
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kafka:
2+
resources:
3+
limits:
4+
cpu: overridden-prod
5+
requests:
6+
cpu: 50m
7+
memory: 100Mi
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
kafka:
2+
resources:
3+
limits:
4+
cpu: 600m
5+
memory: overridden
6+
requests:
7+
cpu: 50m
8+
memory: 100Mi
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 gunicorn

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

Whitespace-only changes.

tools/deployment-cli-tools/tests/resources_buggy/applications/myapp/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

0 commit comments

Comments
 (0)