Skip to content

Commit d42f1f7

Browse files
committed
Merge branch 'feature/CH-169' of github.com:MetaCell/cloud-harness into feature/CH-110
2 parents eaa5440 + 67fdf62 commit d42f1f7

10 files changed

Lines changed: 114 additions & 87 deletions

File tree

applications/nfsserver/deploy/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ harness:
44
auto: false
55
deployment:
66
auto: false
7+
image: gcr.io/metacellllc/cloudharness/nfsserver:1.0
78

89

910
# nfs server pvc disk size (/exports)

applications/samples/deploy/values-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ harness:
55
- events
66
- common
77
- jupyterhub
8+
- volumemanager
89
accounts:
910
roles:
1011
- role1

deployment/codefresh-test.yaml

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ steps:
3333
working_directory: .
3434
commands:
3535
- bash cloud-harness/install.sh
36-
- 'harness-deployment . -n test-${{NAMESPACE_BASENAME}} -d ${{DOMAIN}} -r ${{REGISTRY}}
37-
-rs ${{REGISTRY_SECRET}} -e test --write-env -N '
36+
- harness-deployment . -n test-${{NAMESPACE_BASENAME}} -d ${{DOMAIN}} -r ${{REGISTRY}}
37+
-rs ${{REGISTRY_SECRET}} -e test --write-env -N -i samples
3838
- cat deployment/.env >> ${{CF_VOLUME_PATH}}/env_vars_to_export
3939
- cat ${{CF_VOLUME_PATH}}/env_vars_to_export
4040
prepare_deployment_view:
@@ -124,49 +124,6 @@ steps:
124124
type: parallel
125125
stage: build
126126
steps:
127-
nfsserver:
128-
type: build
129-
stage: build
130-
dockerfile: Dockerfile
131-
registry: '${{CODEFRESH_REGISTRY}}'
132-
buildkit: true
133-
build_arguments:
134-
- DOMAIN=${{DOMAIN}}
135-
- NOCACHE=${{CF_BUILD_ID}}
136-
- REGISTRY=${{REGISTRY}}/cloudharness/
137-
image_name: cloudharness/nfsserver
138-
title: Nfsserver
139-
working_directory: ./applications/nfsserver
140-
tag: '${{NFSSERVER_TAG}}'
141-
when:
142-
condition:
143-
any:
144-
buildDoesNotExist: includes('${{NFSSERVER_TAG_EXISTS}}', '{{NFSSERVER_TAG_EXISTS}}')
145-
== true
146-
forceNoCache: includes('${{NFSSERVER_TAG_FORCE_BUILD}}', '{{NFSSERVER_TAG_FORCE_BUILD}}')
147-
== false
148-
notifications:
149-
type: build
150-
stage: build
151-
dockerfile: Dockerfile
152-
registry: '${{CODEFRESH_REGISTRY}}'
153-
buildkit: true
154-
build_arguments:
155-
- DOMAIN=${{DOMAIN}}
156-
- NOCACHE=${{CF_BUILD_ID}}
157-
- REGISTRY=${{REGISTRY}}/cloudharness/
158-
- CLOUDHARNESS_BASE=${{REGISTRY}}/cloudharness/cloudharness-base:${{CLOUDHARNESS_BASE_TAG}}
159-
image_name: cloudharness/notifications
160-
title: Notifications
161-
working_directory: ./applications/notifications/server
162-
tag: '${{NOTIFICATIONS_TAG}}'
163-
when:
164-
condition:
165-
any:
166-
buildDoesNotExist: includes('${{NOTIFICATIONS_TAG_EXISTS}}', '{{NOTIFICATIONS_TAG_EXISTS}}')
167-
== true
168-
forceNoCache: includes('${{NOTIFICATIONS_TAG_FORCE_BUILD}}', '{{NOTIFICATIONS_TAG_FORCE_BUILD}}')
169-
== false
170127
accounts:
171128
type: build
172129
stage: build
@@ -210,27 +167,6 @@ steps:
210167
== true
211168
forceNoCache: includes('${{VOLUMEMANAGER_TAG_FORCE_BUILD}}', '{{VOLUMEMANAGER_TAG_FORCE_BUILD}}')
212169
== false
213-
sentry:
214-
type: build
215-
stage: build
216-
dockerfile: Dockerfile
217-
registry: '${{CODEFRESH_REGISTRY}}'
218-
buildkit: true
219-
build_arguments:
220-
- DOMAIN=${{DOMAIN}}
221-
- NOCACHE=${{CF_BUILD_ID}}
222-
- REGISTRY=${{REGISTRY}}/cloudharness/
223-
image_name: cloudharness/sentry
224-
title: Sentry
225-
working_directory: ./applications/sentry
226-
tag: '${{SENTRY_TAG}}'
227-
when:
228-
condition:
229-
any:
230-
buildDoesNotExist: includes('${{SENTRY_TAG_EXISTS}}', '{{SENTRY_TAG_EXISTS}}')
231-
== true
232-
forceNoCache: includes('${{SENTRY_TAG_FORCE_BUILD}}', '{{SENTRY_TAG_FORCE_BUILD}}')
233-
== false
234170
jupyterhub:
235171
type: build
236172
stage: build
@@ -466,7 +402,7 @@ steps:
466402
working_directory: ./${{CF_REPO_NAME}}
467403
title: Installing chart
468404
arguments:
469-
helm_version: 3.11.0
405+
helm_version: 3.6.2
470406
chart_name: deployment/helm
471407
release_name: test-${{NAMESPACE_BASENAME}}
472408
kube_context: '${{CLUSTER_NAME}}'
@@ -476,11 +412,6 @@ steps:
476412
custom_value_files:
477413
- ./deployment/helm/values.yaml
478414
custom_values:
479-
- apps_notifications_harness_secrets_email-user=${{EMAIL-USER}}
480-
- apps_notifications_harness_secrets_email-password=${{EMAIL-PASSWORD}}
481-
- apps_sentry_harness_secrets_email-server=${{EMAIL-SERVER}}
482-
- apps_sentry_harness_secrets_email-user=${{EMAIL-USER}}
483-
- apps_sentry_harness_secrets_email-password=${{EMAIL-PASSWORD}}
484415
- apps_samples_harness_secrets_asecret=${{ASECRET}}
485416
build_test_images:
486417
title: Build test images
@@ -537,10 +468,8 @@ steps:
537468
commands:
538469
- kubectl config use-context ${{CLUSTER_NAME}}
539470
- kubectl config set-context --current --namespace=test-${{NAMESPACE_BASENAME}}
540-
- kubectl rollout status deployment/notifications
541471
- kubectl rollout status deployment/accounts
542472
- kubectl rollout status deployment/volumemanager
543-
- kubectl rollout status deployment/sentry
544473
- kubectl rollout status deployment/argo-server-gk
545474
- kubectl rollout status deployment/samples
546475
- kubectl rollout status deployment/samples-gk
@@ -617,7 +546,7 @@ steps:
617546
image: '${{REGISTRY}}/cloudharness/test-e2e:${{TEST_E2E_TAG}}'
618547
fail_fast: false
619548
commands:
620-
- npx puppeteer browsers install chrome
549+
- npx puppeteer browsers install chrome
621550
- yarn test
622551
scale:
623552
jupyterhub_e2e_test:

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def codefresh_steps_from_base_path(base_path, build_step, fixed_context=None, in
173173
# Skip excluded apps
174174
continue
175175

176+
if app_config and not helm_values.apps[app_key].get('build', True):
177+
continue
178+
176179
if app_config and app_config.dependencies and app_config.dependencies.git:
177180
for dep in app_config.dependencies.git:
178181
step_name = f"clone_{basename(dep.url).replace('.', '_')}_{basename(dockerfile_relative_to_root).replace('.', '_')}"
@@ -319,11 +322,13 @@ def add_unit_test_step(app_config: ApplicationHarnessConfig):
319322
steps = codefresh["steps"]
320323
if CD_E2E_TEST_STEP in steps and not steps[CD_E2E_TEST_STEP]["scale"]:
321324
del steps[CD_E2E_TEST_STEP]
322-
del steps[CD_BUILD_STEP_TEST]["steps"]["test-e2e"]
325+
if CD_BUILD_STEP_TEST in steps and 'test-e2e' in steps[CD_BUILD_STEP_TEST]["steps"]:
326+
del steps[CD_BUILD_STEP_TEST]["steps"]["test-e2e"]
323327

324328
if CD_API_TEST_STEP in steps and not steps[CD_API_TEST_STEP]["scale"]:
325329
del steps[CD_API_TEST_STEP]
326-
del steps[CD_BUILD_STEP_TEST]["steps"]["test-api"]
330+
if CD_BUILD_STEP_TEST in steps and 'test-api' in steps[CD_BUILD_STEP_TEST]["steps"]:
331+
del steps[CD_BUILD_STEP_TEST]["steps"]["test-api"]
327332

328333
if CD_BUILD_STEP_TEST in steps and not steps[CD_BUILD_STEP_TEST]["steps"]:
329334
del steps[CD_BUILD_STEP_TEST]

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ def create_app_values_spec(self, app_name, app_path, base_image_name=None, helm_
190190
else:
191191
build_dependencies = []
192192

193-
if len(image_paths) > 0:
193+
deployment_values = values.get(KEY_HARNESS, {}).get(KEY_DEPLOYMENT, {})
194+
deployment_image = deployment_values.get('image', None) or values.get('image', None)
195+
values['build'] = not bool(deployment_image) # Used by skaffold and ci/cd to determine if the image should be built
196+
if len(image_paths) > 0 and not deployment_image:
194197
image_name = image_name_from_dockerfile_path(os.path.relpath(
195198
image_paths[0], os.path.dirname(app_path)), base_image_name)
196-
197199
values['image'] = self.image_tag(
198200
image_name, build_context_path=app_path, dependencies=build_dependencies)
199-
elif KEY_HARNESS in values and not values[KEY_HARNESS].get(KEY_DEPLOYMENT, {}).get('image', None) and values[
201+
elif KEY_HARNESS in values and not deployment_image and values[
200202
KEY_HARNESS].get(KEY_DEPLOYMENT, {}).get('auto', False):
201203
raise Exception(f"At least one Dockerfile must be specified on application {app_name}. "
202204
f"Specify harness.deployment.image value if you intend to use a prebuilt image.")

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def process_build_dockerfile(
8181
if app_name is None:
8282
app_name = app_name_from_path(basename(dockerfile_path))
8383
app_key = app_name.replace("-", "_")
84+
if app_key in helm_values.apps and not helm_values.apps[app_key]['build']:
85+
return
8486
if app_name in helm_values[KEY_TASK_IMAGES] or app_key in helm_values.apps:
8587
context_path = relpath_if(root_path, output_path) if global_context else relpath_if(dockerfile_path, output_path)
8688

@@ -157,6 +159,8 @@ def process_build_dockerfile(
157159
# app_image_tag, app_relative_to_skaffold, build_requirements)
158160
process_build_dockerfile(dockerfile_path, root_path, requirements=build_requirements, app_name=app_name)
159161
app = apps[app_key]
162+
if not app['build']:
163+
continue
160164
if app[KEY_HARNESS][KEY_DEPLOYMENT]['image']:
161165
release_config['artifactOverrides']['apps'][app_key] = \
162166
{
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
harness:
2+
dependencies:
3+
build: []
4+
deployment:
5+
image: "custom-image"

tools/deployment-cli-tools/tests/test_codefresh.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,39 @@ def test_create_codefresh_configuration_tests():
282282

283283
finally:
284284
shutil.rmtree(BUILD_MERGE_DIR)
285+
286+
287+
def test_create_codefresh_configuration_nobuild():
288+
values = create_helm_chart(
289+
[RESOURCES],
290+
output_path=OUT,
291+
include=['myapp'],
292+
exclude=['events'],
293+
domain="my.local",
294+
namespace='test',
295+
env=['dev', 'nobuild'],
296+
local=False,
297+
tag=1,
298+
registry='reg'
299+
)
300+
301+
root_paths = preprocess_build_overrides(
302+
root_paths=[CLOUD_HARNESS_PATH, RESOURCES],
303+
helm_values=values,
304+
merge_build_path=BUILD_MERGE_DIR
305+
)
306+
307+
build_included = [app['harness']['name']
308+
for app in values['apps'].values() if 'harness' in app]
309+
310+
cf = create_codefresh_deployment_scripts(root_paths, include=build_included,
311+
envs=['dev', 'nobuild'],
312+
base_image_name=values['name'],
313+
helm_values=values, save=False)
314+
l1_steps = cf['steps']
315+
steps = l1_steps["build_application_images"]["steps"]
316+
assert len(steps) == 1
317+
assert "myapp" not in steps
318+
assert "myapp-mytask" in steps
319+
assert "publish_myapp" not in l1_steps["publish"]["steps"]
320+
assert "publish_myapp-mytask" in l1_steps["publish"]["steps"]

tools/deployment-cli-tools/tests/test_helm.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ def test_collect_helm_values(tmp_path):
1717
exclude=['events'], domain="my.local",
1818
namespace='test', env='dev', local=False, tag=1, registry='reg')
1919

20-
# Auto values
21-
assert values[KEY_APPS]['myapp'][KEY_HARNESS]['deployment']['image'] == 'reg/cloudharness/myapp:1'
22-
assert values.apps['myapp'].harness.deployment.image == 'reg/cloudharness/myapp:1'
23-
assert values[KEY_APPS]['myapp'][KEY_HARNESS]['name'] == 'myapp'
24-
assert values[KEY_APPS]['legacy'][KEY_HARNESS]['name'] == 'legacy'
25-
assert values[KEY_APPS]['accounts'][KEY_HARNESS]['deployment']['image'] == 'reg/cloudharness/accounts:1'
26-
2720
# First level include apps
2821
assert 'samples' in values[KEY_APPS]
2922
assert 'myapp' in values[KEY_APPS]
@@ -41,6 +34,14 @@ def test_collect_helm_values(tmp_path):
4134
# Explicit exclude overrides include
4235
assert 'events' not in values[KEY_APPS]
4336

37+
# Auto values
38+
assert values[KEY_APPS]['myapp'][KEY_HARNESS]['deployment']['image'] == 'reg/cloudharness/myapp:1'
39+
assert values[KEY_APPS]['myapp']['build'] == True
40+
assert values.apps['myapp'].harness.deployment.image == 'reg/cloudharness/myapp:1'
41+
assert values[KEY_APPS]['myapp'][KEY_HARNESS]['name'] == 'myapp'
42+
assert values[KEY_APPS]['legacy'][KEY_HARNESS]['name'] == 'legacy'
43+
assert values[KEY_APPS]['accounts'][KEY_HARNESS]['deployment']['image'] == 'reg/cloudharness/accounts:1'
44+
4445
# Base values kept
4546
assert values[KEY_APPS]['accounts'][KEY_HARNESS]['subdomain'] == 'accounts'
4647

@@ -79,6 +80,15 @@ def test_collect_helm_values(tmp_path):
7980
assert 'cloudharness-base-debian' not in values[KEY_TASK_IMAGES]
8081

8182

83+
def test_collect_nobuild(tmp_path):
84+
out_folder = tmp_path / 'test_collect_helm_values'
85+
values = create_helm_chart([RESOURCES], output_path=out_folder, include=['myapp'],
86+
exclude=['events'], domain="my.local",
87+
namespace='test', env='nobuild', local=False, tag=1, registry='reg')
88+
assert values[KEY_APPS]['myapp'][KEY_HARNESS]['deployment']['image'] == 'custom-image'
89+
assert values[KEY_APPS]['myapp']['build'] == False
90+
91+
8292
def test_collect_helm_values_noreg_noinclude(tmp_path):
8393
out_path = tmp_path / 'test_collect_helm_values_noreg_noinclude'
8494
values = create_helm_chart([CLOUDHARNESS_ROOT, RESOURCES], output_path=out_path, domain="my.local",

tools/deployment-cli-tools/tests/test_skaffold.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,37 @@ def test_create_skaffold_configuration_with_conflicting_dependencies_requirement
180180

181181
myapp_config = release['overrides']['apps']['myapp2']
182182
assert myapp_config['harness']['deployment']['args'][0] == '/usr/src/app/myapp_code/__main__.py'
183+
184+
185+
def test_create_skaffold_configuration_nobuild():
186+
values = create_helm_chart(
187+
[RESOURCES],
188+
output_path=OUT,
189+
include=['myapp'],
190+
domain="my.local",
191+
namespace='test',
192+
env='nobuild',
193+
local=False,
194+
tag=1,
195+
registry='reg'
196+
)
197+
198+
BUILD_DIR = "/tmp/build"
199+
root_paths = preprocess_build_overrides(
200+
root_paths=[CLOUDHARNESS_ROOT, RESOURCES],
201+
helm_values=values,
202+
merge_build_path=BUILD_DIR
203+
)
204+
205+
sk = create_skaffold_configuration(
206+
root_paths=root_paths,
207+
helm_values=values,
208+
output_path=OUT
209+
)
210+
releases = sk['deploy']['helm']['releases']
211+
212+
assert len(sk['build']['artifacts']) == 1
213+
assert len(releases) == 1 # Ensure we only found 1 deployment (for myapp)
214+
215+
release = releases[0]
216+
assert 'myapp' not in release['overrides']['apps']

0 commit comments

Comments
 (0)