Skip to content

Commit

Permalink
#592 CH-48 conditional force build added
Browse files Browse the repository at this point in the history
  • Loading branch information
filippomc committed Mar 9, 2023
1 parent 98a1923 commit 35f424f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 35 deletions.
103 changes: 70 additions & 33 deletions deployment/codefresh-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ steps:
-d ${{CF_SHORT_REVISION}}.${{DOMAIN}} -r ${{REGISTRY}} -rs ${{REGISTRY_SECRET}}
-e test --write-env -N -i samples
- cat deployment/.env >> ${{CF_VOLUME_PATH}}/env_vars_to_export
- cat ${{CF_VOLUME_PATH}}/env_vars_to_export
prepare_deployment_view:
commands:
- helm template ./deployment/helm --debug -n test-${{NAMESPACE_BASENAME}}-${{CF_SHORT_REVISION}}
Expand Down Expand Up @@ -66,9 +67,11 @@ steps:
tag: '${{CLOUDHARNESS_BASE_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{CLOUDHARNESS_BASE_TAG_EXISTS}}', '{{CLOUDHARNESS_BASE_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{CLOUDHARNESS_BASE_TAG_EXISTS}}', '{{CLOUDHARNESS_BASE_TAG_EXISTS}}')
== true
forceNoCache: includes('${{CLOUDHARNESS_BASE_TAG_FORCE_BUILD}}', '{{CLOUDHARNESS_BASE_TAG_FORCE_BUILD}}')
== false
cloudharness-frontend-build:
type: build
stage: build
Expand All @@ -85,9 +88,11 @@ steps:
tag: '${{CLOUDHARNESS_FRONTEND_BUILD_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{CLOUDHARNESS_FRONTEND_BUILD_TAG_EXISTS}}',
any:
buildDoesNotExist: includes('${{CLOUDHARNESS_FRONTEND_BUILD_TAG_EXISTS}}',
'{{CLOUDHARNESS_FRONTEND_BUILD_TAG_EXISTS}}') == true
forceNoCache: includes('${{CLOUDHARNESS_FRONTEND_BUILD_TAG_FORCE_BUILD}}',
'{{CLOUDHARNESS_FRONTEND_BUILD_TAG_FORCE_BUILD}}') == false
build_static_images:
title: Build static images
type: parallel
Expand All @@ -110,9 +115,11 @@ steps:
tag: '${{CLOUDHARNESS_FLASK_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{CLOUDHARNESS_FLASK_TAG_EXISTS}}', '{{CLOUDHARNESS_FLASK_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{CLOUDHARNESS_FLASK_TAG_EXISTS}}', '{{CLOUDHARNESS_FLASK_TAG_EXISTS}}')
== true
forceNoCache: includes('${{CLOUDHARNESS_FLASK_TAG_FORCE_BUILD}}', '{{CLOUDHARNESS_FLASK_TAG_FORCE_BUILD}}')
== false
build_application_images:
type: parallel
stage: build
Expand All @@ -133,9 +140,11 @@ steps:
tag: '${{NFSSERVER_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{NFSSERVER_TAG_EXISTS}}', '{{NFSSERVER_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{NFSSERVER_TAG_EXISTS}}', '{{NFSSERVER_TAG_EXISTS}}')
== true
forceNoCache: includes('${{NFSSERVER_TAG_FORCE_BUILD}}', '{{NFSSERVER_TAG_FORCE_BUILD}}')
== false
accounts:
type: build
stage: build
Expand All @@ -152,9 +161,11 @@ steps:
tag: '${{ACCOUNTS_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{ACCOUNTS_TAG_EXISTS}}', '{{ACCOUNTS_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{ACCOUNTS_TAG_EXISTS}}', '{{ACCOUNTS_TAG_EXISTS}}')
== true
forceNoCache: includes('${{ACCOUNTS_TAG_FORCE_BUILD}}', '{{ACCOUNTS_TAG_FORCE_BUILD}}')
== false
samples:
type: build
stage: build
Expand All @@ -173,9 +184,11 @@ steps:
tag: '${{SAMPLES_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{SAMPLES_TAG_EXISTS}}', '{{SAMPLES_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{SAMPLES_TAG_EXISTS}}', '{{SAMPLES_TAG_EXISTS}}')
== true
forceNoCache: includes('${{SAMPLES_TAG_FORCE_BUILD}}', '{{SAMPLES_TAG_FORCE_BUILD}}')
== false
samples-print-file:
type: build
stage: build
Expand All @@ -193,9 +206,11 @@ steps:
tag: '${{SAMPLES_PRINT_FILE_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{SAMPLES_PRINT_FILE_TAG_EXISTS}}', '{{SAMPLES_PRINT_FILE_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{SAMPLES_PRINT_FILE_TAG_EXISTS}}', '{{SAMPLES_PRINT_FILE_TAG_EXISTS}}')
== true
forceNoCache: includes('${{SAMPLES_PRINT_FILE_TAG_FORCE_BUILD}}', '{{SAMPLES_PRINT_FILE_TAG_FORCE_BUILD}}')
== false
samples-secret:
type: build
stage: build
Expand All @@ -213,9 +228,11 @@ steps:
tag: '${{SAMPLES_SECRET_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{SAMPLES_SECRET_TAG_EXISTS}}', '{{SAMPLES_SECRET_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{SAMPLES_SECRET_TAG_EXISTS}}', '{{SAMPLES_SECRET_TAG_EXISTS}}')
== true
forceNoCache: includes('${{SAMPLES_SECRET_TAG_FORCE_BUILD}}', '{{SAMPLES_SECRET_TAG_FORCE_BUILD}}')
== false
samples-sum:
type: build
stage: build
Expand All @@ -233,9 +250,11 @@ steps:
tag: '${{SAMPLES_SUM_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{SAMPLES_SUM_TAG_EXISTS}}', '{{SAMPLES_SUM_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{SAMPLES_SUM_TAG_EXISTS}}', '{{SAMPLES_SUM_TAG_EXISTS}}')
== true
forceNoCache: includes('${{SAMPLES_SUM_TAG_FORCE_BUILD}}', '{{SAMPLES_SUM_TAG_FORCE_BUILD}}')
== false
common:
type: build
stage: build
Expand All @@ -253,9 +272,11 @@ steps:
tag: '${{COMMON_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{COMMON_TAG_EXISTS}}', '{{COMMON_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{COMMON_TAG_EXISTS}}', '{{COMMON_TAG_EXISTS}}')
== true
forceNoCache: includes('${{COMMON_TAG_FORCE_BUILD}}', '{{COMMON_TAG_FORCE_BUILD}}')
== false
workflows-send-result-event:
type: build
stage: build
Expand All @@ -273,9 +294,11 @@ steps:
tag: '${{WORKFLOWS_SEND_RESULT_EVENT_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{WORKFLOWS_SEND_RESULT_EVENT_TAG_EXISTS}}',
any:
buildDoesNotExist: includes('${{WORKFLOWS_SEND_RESULT_EVENT_TAG_EXISTS}}',
'{{WORKFLOWS_SEND_RESULT_EVENT_TAG_EXISTS}}') == true
forceNoCache: includes('${{WORKFLOWS_SEND_RESULT_EVENT_TAG_FORCE_BUILD}}',
'{{WORKFLOWS_SEND_RESULT_EVENT_TAG_FORCE_BUILD}}') == false
workflows-extract-download:
type: build
stage: build
Expand All @@ -292,9 +315,11 @@ steps:
tag: '${{WORKFLOWS_EXTRACT_DOWNLOAD_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{WORKFLOWS_EXTRACT_DOWNLOAD_TAG_EXISTS}}',
any:
buildDoesNotExist: includes('${{WORKFLOWS_EXTRACT_DOWNLOAD_TAG_EXISTS}}',
'{{WORKFLOWS_EXTRACT_DOWNLOAD_TAG_EXISTS}}') == true
forceNoCache: includes('${{WORKFLOWS_EXTRACT_DOWNLOAD_TAG_FORCE_BUILD}}',
'{{WORKFLOWS_EXTRACT_DOWNLOAD_TAG_FORCE_BUILD}}') == false
workflows-notify-queue:
type: build
stage: build
Expand All @@ -312,9 +337,11 @@ steps:
tag: '${{WORKFLOWS_NOTIFY_QUEUE_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{WORKFLOWS_NOTIFY_QUEUE_TAG_EXISTS}}', '{{WORKFLOWS_NOTIFY_QUEUE_TAG_EXISTS}}')
== true
any:
buildDoesNotExist: includes('${{WORKFLOWS_NOTIFY_QUEUE_TAG_EXISTS}}',
'{{WORKFLOWS_NOTIFY_QUEUE_TAG_EXISTS}}') == true
forceNoCache: includes('${{WORKFLOWS_NOTIFY_QUEUE_TAG_FORCE_BUILD}}',
'{{WORKFLOWS_NOTIFY_QUEUE_TAG_FORCE_BUILD}}') == false
workflows:
type: build
stage: build
Expand All @@ -332,9 +359,11 @@ steps:
tag: '${{WORKFLOWS_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{WORKFLOWS_TAG_EXISTS}}', '{{WORKFLOWS_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{WORKFLOWS_TAG_EXISTS}}', '{{WORKFLOWS_TAG_EXISTS}}')
== true
forceNoCache: includes('${{WORKFLOWS_TAG_FORCE_BUILD}}', '{{WORKFLOWS_TAG_FORCE_BUILD}}')
== false
tests_unit:
stage: unittest
type: parallel
Expand Down Expand Up @@ -389,9 +418,11 @@ steps:
tag: '${{TEST_E2E_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{TEST_E2E_TAG_EXISTS}}', '{{TEST_E2E_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{TEST_E2E_TAG_EXISTS}}', '{{TEST_E2E_TAG_EXISTS}}')
== true
forceNoCache: includes('${{TEST_E2E_TAG_FORCE_BUILD}}', '{{TEST_E2E_TAG_FORCE_BUILD}}')
== false
test-api:
type: build
stage: build
Expand All @@ -409,9 +440,11 @@ steps:
tag: '${{TEST_API_TAG}}'
when:
condition:
all:
whenVarExists: includes('${{TEST_API_TAG_EXISTS}}', '{{TEST_API_TAG_EXISTS}}')
any:
buildDoesNotExist: includes('${{TEST_API_TAG_EXISTS}}', '{{TEST_API_TAG_EXISTS}}')
== true
forceNoCache: includes('${{TEST_API_TAG_FORCE_BUILD}}', '{{TEST_API_TAG_FORCE_BUILD}}')
== false
wait_deployment:
stage: qa
title: Wait deployment to be ready
Expand All @@ -436,6 +469,7 @@ steps:
- echo $APP_NAME
scale:
samples_api_test:
title: samples api test
volumes:
- '${{CF_REPO_NAME}}/applications/samples:/home/test'
- '${{CF_REPO_NAME}}/deployment/helm/values.yaml:/opt/cloudharness/resources/allvalues.yaml'
Expand All @@ -450,6 +484,7 @@ steps:
--request-timeout=180000 --hypothesis-max-examples=2 --show-errors-tracebacks
- pytest -v test/api
common_api_test:
title: common api test
volumes:
- '${{CF_REPO_NAME}}/applications/common:/home/test'
- '${{CF_REPO_NAME}}/deployment/helm/values.yaml:/opt/cloudharness/resources/allvalues.yaml'
Expand All @@ -459,6 +494,7 @@ steps:
- st --pre-run cloudharness_test.apitest_init run api/openapi.yaml --base-url
https://common.${{CF_SHORT_REVISION}}.${{DOMAIN}}/api -c all
workflows_api_test:
title: workflows api test
volumes:
- '${{CF_REPO_NAME}}/applications/workflows:/home/test'
- '${{CF_REPO_NAME}}/deployment/helm/values.yaml:/opt/cloudharness/resources/allvalues.yaml'
Expand All @@ -483,6 +519,7 @@ steps:
- yarn test
scale:
samples_e2e_test:
title: samples e2e test
volumes:
- '${{CF_REPO_NAME}}/applications/samples/test/e2e:/home/test/__tests__/samples'
environment:
Expand Down
11 changes: 9 additions & 2 deletions tools/deployment-cli-tools/ch_cli_tools/codefresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,18 @@ def add_arg_dependencies(dependencies):
return build

def existing_build_when_condition(tag):
"""
See https://codefresh.io/docs/docs/pipelines/conditional-execution-of-steps/#execute-steps-according-to-the-presence-of-a-variable
the _EXISTS variable is added in the preparation step
the _FORCE_BUILD variable may be added manually by the user to force the build of a specific image
"""
is_built = tag + "_EXISTS"
force_build = tag + "_FORCE_BUILD"
when_condition = {
"condition": {
"all": {
"whenVarExists": "includes('${{%s}}', '{{%s}}') == true" % (is_built, is_built)
"any": {
"buildDoesNotExist": "includes('${{%s}}', '{{%s}}') == true" % (is_built, is_built),
"forceNoCache": "includes('${{%s}}', '{{%s}}') == false" % (force_build, force_build),
}
}
}
Expand Down

0 comments on commit 35f424f

Please sign in to comment.