Skip to content

Commit ac252f0

Browse files
committed
CH-194 fix image build arg
1 parent 0e102d4 commit ac252f0

4 files changed

Lines changed: 57 additions & 49 deletions

File tree

deployment-configuration/codefresh-template-dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ steps:
3434
working_directory: .
3535
commands:
3636
- bash cloud-harness/install.sh
37-
- harness-deployment $PATHS -d ${{DOMAIN}} -r ${{REGISTRY}} -rs ${{REGISTRY_SECRET}} -n ${{NAMESPACE}} --write-env -e $ENV --cache-url ${{IMAGE_CACHE_URL}} $PARAMS
37+
- harness-deployment $PATHS -d ${{DOMAIN}} -r ${{REGISTRY}} -rs '${{REGISTRY_SECRET}}' -n ${{NAMESPACE}} --write-env -e $ENV --cache-url '${{IMAGE_CACHE_URL}}' $PARAMS
3838
- cat deployment/.env >> ${{CF_VOLUME_PATH}}/env_vars_to_export
3939
- cat ${{CF_VOLUME_PATH}}/env_vars_to_export
4040
prepare_deployment_view:

deployment-configuration/codefresh-template-prod.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ steps:
3030
working_directory: .
3131
commands:
3232
- bash cloud-harness/install.sh
33-
- harness-deployment $PATHS -t ${{DEPLOYMENT_TAG}} -d ${{DOMAIN}} -r ${{REGISTRY}} -rs ${{REGISTRY_SECRET}} -n ${{NAMESPACE}} -e $ENV --no-cd $PARAMS
33+
- harness-deployment $PATHS -t ${{DEPLOYMENT_TAG}} -d ${{DOMAIN}} -r ${{REGISTRY}} -rs '${{REGISTRY_SECRET}}' -n ${{NAMESPACE}} -e $ENV --no-cd $PARAMS
3434
prepare_deployment_view:
3535
commands:
3636
- "helm template ./deployment/helm --debug -n ${{NAMESPACE}}"

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

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,56 @@ def e2e_test_environment(app_config: ApplicationHarnessConfig, app_domain: str =
154154
env = get_app_environment(app_config, app_domain, False)
155155
return [f"{k}={env[k]}" for k in env]
156156

157+
def codefresh_app_build_spec(app_name, app_context_path, dockerfile_path="Dockerfile", base_name=None, helm_values: HarnessMainConfig = {}, dependencies=None):
158+
logging.info('Generating build script for ' + app_name)
159+
title = app_name.capitalize().replace(
160+
'-', ' ').replace('/', ' ').replace('.', ' ').strip()
161+
build = codefresh_template_spec(
162+
template_path=CF_BUILD_PATH,
163+
image_name=get_image_name(app_name, base_name),
164+
title=title,
165+
working_directory='./' + app_context_path,
166+
dockerfile=dockerfile_path)
167+
168+
tag = app_specific_tag_variable(app_name)
169+
build["tag"] = "${{%s}}" % tag
170+
171+
specific_build_template_path = join(app_context_path, 'build.yaml')
172+
if exists(specific_build_template_path):
173+
logging.info("Specific build template found: %s" %
174+
(specific_build_template_path))
175+
with open(specific_build_template_path) as f:
176+
build_specific = yaml.safe_load(f)
177+
178+
build_specific.pop(
179+
'build_arguments') if 'build_arguments' in build_specific else []
180+
181+
build['dependencies'] = dependencies
182+
183+
def get_other_image_name(app_name):
184+
return ("${{REGISTRY}}/" + f"{build_steps[app_name]['image_name']}:{build_steps[app_name]['tag']}")\
185+
if app_name in build_steps \
186+
else image_tag_with_variables(app_name, app_specific_tag_variable(app_name), base_name)
187+
188+
def add_arg_dependencies(dependencies):
189+
arg_dependencies = [f"{d.upper().replace('-', '_')}={get_other_image_name(d)}"
190+
for d in dependencies]
191+
build['build_arguments'].extend(arg_dependencies)
192+
193+
values_key = app_name
194+
if dependencies is not None:
195+
add_arg_dependencies(dependencies)
196+
elif values_key in helm_values.apps:
197+
try:
198+
add_arg_dependencies(
199+
helm_values.apps[values_key].harness.dependencies.build)
200+
except (KeyError, AttributeError):
201+
add_arg_dependencies(helm_values['task-images'])
202+
203+
when_condition = existing_build_when_condition(tag)
204+
build["when"] = when_condition
205+
return build
206+
157207
def codefresh_steps_from_base_path(base_path, fixed_context=None, include=build_included, publish=True):
158208
found = False
159209
for dockerfile_path in find_dockerfiles_paths(base_path):
@@ -433,52 +483,6 @@ def app_specific_tag_variable(app_name):
433483
return "%s_TAG" % app_name.replace('-', '_').upper().strip()
434484

435485

436-
def codefresh_app_build_spec(app_name, app_context_path, dockerfile_path="Dockerfile", base_name=None, helm_values: HarnessMainConfig = {}, dependencies=None):
437-
logging.info('Generating build script for ' + app_name)
438-
title = app_name.capitalize().replace(
439-
'-', ' ').replace('/', ' ').replace('.', ' ').strip()
440-
build = codefresh_template_spec(
441-
template_path=CF_BUILD_PATH,
442-
image_name=get_image_name(app_name, base_name),
443-
title=title,
444-
working_directory='./' + app_context_path,
445-
dockerfile=dockerfile_path)
446-
447-
tag = app_specific_tag_variable(app_name)
448-
build["tag"] = "${{%s}}" % tag
449-
450-
specific_build_template_path = join(app_context_path, 'build.yaml')
451-
if exists(specific_build_template_path):
452-
logging.info("Specific build template found: %s" %
453-
(specific_build_template_path))
454-
with open(specific_build_template_path) as f:
455-
build_specific = yaml.safe_load(f)
456-
457-
build_specific.pop(
458-
'build_arguments') if 'build_arguments' in build_specific else []
459-
460-
build['dependencies'] = dependencies
461-
462-
def add_arg_dependencies(dependencies):
463-
arg_dependencies = [f"{d.upper().replace('-', '_')}={image_tag_with_variables(d, app_specific_tag_variable(d), base_name)}" for
464-
d in dependencies]
465-
build['build_arguments'].extend(arg_dependencies)
466-
467-
values_key = app_name
468-
if dependencies is not None:
469-
add_arg_dependencies(dependencies)
470-
elif values_key in helm_values.apps:
471-
try:
472-
add_arg_dependencies(
473-
helm_values.apps[values_key].harness.dependencies.build)
474-
except (KeyError, AttributeError):
475-
add_arg_dependencies(helm_values['task-images'])
476-
477-
when_condition = existing_build_when_condition(tag)
478-
build["when"] = when_condition
479-
return build
480-
481-
482486
def existing_build_when_condition(tag):
483487
"""
484488
See https://codefresh.io/docs/docs/pipelines/conditional-execution-of-steps/#execute-steps-according-to-the-presence-of-a-variable

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ def test_create_codefresh_configuration():
117117

118118
step = steps["myapp"]
119119
assert step['dockerfile'] == "Dockerfile"
120+
for build_argument in step['build_arguments']:
121+
if build_argument.startswith("CLOUDHARNESS_FLASK="):
122+
assert "cloud-harness" in build_argument, "Cloudharness flask image should have cloud-harness in its path"
123+
assert build_argument == "CLOUDHARNESS_FLASK=${{REGISTRY}}/cloud-harness/cloudharness-flask:${{CLOUDHARNESS_FLASK_TAG}}", "Dependency is not properly set in the build arguments"
124+
120125
assert os.path.samefile(step['working_directory'], os.path.join(
121126
RESOURCES, APPS_PATH, "myapp"))
122127

@@ -131,7 +136,6 @@ def test_create_codefresh_configuration():
131136
assert len(
132137
tstep['commands']) == 2, "Unit test commands are not properly loaded from the unit test configuration file"
133138
assert tstep['commands'][0] == "tox", "Unit test commands are not properly loaded from the unit test configuration file"
134-
135139
assert len(l1_steps[CD_STEP_CLONE_DEPENDENCIES]['steps']) == 3, "3 clone steps should be included as we have 2 dependencies from myapp, plus cloudharness"
136140
finally:
137141
shutil.rmtree(BUILD_MERGE_DIR)

0 commit comments

Comments
 (0)