Skip to content
Snippets Groups Projects
Commit 95323ad5 authored by Philipp S. Sommer's avatar Philipp S. Sommer
Browse files

Merge branch 'multiple-build-targets' into 'main'

implement build targets

See merge request !48
parents 6e50c8cd 84b41478
No related branches found
No related tags found
1 merge request!48implement build targets
Pipeline #463430 passed
......@@ -29,6 +29,8 @@ shutil.rmtree(
{% if cookiecutter.__include_build_config == "no" %}
os.remove("templates/{{cookiecutter.template_base_name}}/buildconfig.yaml")
os.remove("templates/{{cookiecutter.template_base_name}}/target-buildconfigs.yaml")
os.remove("templates/{{cookiecutter.template_base_name}}/target-secrets.yaml")
shutil.rmtree(
"templates/{{cookiecutter.template_base_name}}/helpers/buildconfig"
)
......
......@@ -7,11 +7,15 @@ setup() {
create_template '{"include_build_config": "yes"}'
assert [ -e "${TEMPLATE_FOLDER}/buildconfig.yaml" ]
assert [ -e "${TEMPLATE_FOLDER}/deployment.yaml" ]
assert [ -e "${TEMPLATE_FOLDER}/target-buildconfigs.yaml" ]
assert [ -e "${TEMPLATE_FOLDER}/target-secrets.yaml" ]
}
@test "skip buildconfig" {
create_template '{"include_build_config": "no"}'
assert [ ! -e "${TEMPLATE_FOLDER}/buildconfig.yaml" ]
assert [ ! -e "${TEMPLATE_FOLDER}/target-buildconfigs.yaml" ]
assert [ ! -e "${TEMPLATE_FOLDER}/target-secrets.yaml" ]
}
@test "create build secret" {
......@@ -29,4 +33,10 @@ setup() {
create_template '{"include_build_config": "yes"}'
assert [ -e "${TEMPLATE_FOLDER}/buildconfig.yaml" ]
lint_chart "buildSource: {gitlabProject: somerepo}"
}
@test "buildtargets" {
create_template '{"include_build_config": "yes"}'
assert [ -e "${TEMPLATE_FOLDER}/buildconfig.yaml" ]
lint_chart "buildTargets: {some-project: {cluster: dev-cluster}}"
}
\ No newline at end of file
{%- if cookiecutter.__include_build_config == "yes" %}
{%- raw %}
{{- range $targetName, $targetData := .Values.buildTargets }}
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
name: {{ $targetName }}
namespace: {{ $.Release.Namespace }}
labels:
{%- endraw %}
{{ "{{-" }} include "{{ cookiecutter.template_base_name }}.labels" $ | nindent 4 {{ "}}" }}
io.kompose.service: {% raw %}{{ $.Values.baseName }}{% endraw %}
spec:
runPolicy: "Serial"
source:
dockerfile: |
{% raw %}FROM {{ $.Values.baseName }}:latest{% endraw %}
triggers:
- imageChange:
from:
name: "{% raw %}{{ $.Values.baseName }}:latest{% endraw %}"
kind: ImageStreamTag
type: ImageChange
{%- raw %}
failedBuildsHistoryLimit: {{ $.Values.failedBuildsHistoryLimit }}
successfulBuildsHistoryLimit: {{ $.Values.successfulBuildsHistoryLimit }}
strategy:
type: Docker
dockerStrategy:
from:
kind: "ImageStreamTag"
name: "{{ $.Values.baseName }}:latest"
{%- endraw %}
output:
to:
kind: "DockerImage"
name: {% raw %}"{{ printf "%s-quay-registry.apps.%s.fzg.local" (regexFind "dev|prod" $targetData.cluster) $targetData.cluster }}/{{ required "You need to specify a cluster" $targetData.cluster }}_{{ default (get $targetData "namespace") $targetName }}/{{default $targetData.targetImage (printf "%s:latest" $.Values.baseName) }}"{% endraw %}
pushSecret:
{%- raw %}
name: build-secret-{{ $targetName }}
{{- $builtinResources := include "{% endraw %}{{ cookiecutter.template_base_name }}{% raw %}.builtinBuildResources" $ | fromYaml }}
{{- $mergedResources := mustMergeOverwrite (dict) $builtinResources $.Values.buildResources }}
resources: {{ toYaml $mergedResources | nindent 4 }}
{%- endraw %}
{% raw %}{{- end }}{% endraw %}
{%- endif %}
{%- if cookiecutter.__include_build_config == "yes" %}
{%- raw %}
{{- range $targetName, $targetData := .Values.buildTargets }}
{{- $secretName := printf "build-secret-%s" $targetName }}
apiVersion: v1
kind: Secret
metadata:
namespace: {{ $.Release.Namespace }}
labels:
{%- endraw %}
{{ "{{-" }} include "{{ cookiecutter.template_base_name }}.labels" $ | nindent 4 {{ "}}" }}
io.kompose.service: {% raw %}{{ $.Values.baseName }}{% endraw %}
name: {{ "{{" }} $secretName {{ "}}" }}
annotations:
"helm.sh/resource-policy": keep
data:
{%- raw %}
{{- $secretObj := (lookup "v1" "Secret" $.Release.Namespace $secretName) | default dict }}
{{- $secretValue := get ((get $secretObj "data") | default dict) ".dockerconfigjson" }}
{{- $secretDefault := (randAlphaNum 32) | b64enc }}
".dockerconfigjson": {{ $secretValue | default $secretDefault }}
{%- endraw %}
{% raw %}{{- end }}{% endraw %}
{% endif %}
\ No newline at end of file
......@@ -46,6 +46,12 @@ buildSecrets: {}
# buildSecretName is the name of the secret to use during the build.
buildSecretName: null
# a mapping to specify where to push the image to.
buildTargets: {}
# <key>: # the name for the secret (can be the namespace to use)
# cluster: <the cluster to push to (used to obtain the registry)
# namespace: <target k8s namespace> # optional. when empty, <key> is used
# successfulBuildsHistoryLimit is the number of old successful builds to
# retain. When a BuildConfig is created, the 2 most recent successful builds
# are retained unless this value is set. If removed after the BuildConfig has
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment