-
Notifications
You must be signed in to change notification settings - Fork 13
/
overlays-pipeline.yaml
184 lines (175 loc) · 6.54 KB
/
overlays-pipeline.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: overlays-pipeline
labels:
app: aicoe-ci
spec:
params:
- name: git_ref
description: Git reference value.
- name: git_ref_type
description: Type of ref Tag or Branch.
- name: repo_name
description: The git repository title.
- name: repo_url
description: The git repository url.
- name: default_branch
description: The git repository default branch.
- name: uid
description: uid of the pipeline.
resources:
inputs:
- name: s2i-thoth
type: image
- name: repo
type: git
steps:
- name: overlays-pipelinerun-setup
image: $(resources.inputs.s2i-thoth.url)
workingDir: /workspace/repo
securityContext:
privileged: true
script: |
cat <<EOF > overlays-pipelinerun.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: $(params.repo_name)-{overlays}
labels:
app: aicoe-ci
project: $(params.repo_name)
overlay: {overlay}
component: custom-overlays-build-pipeline
spec:
serviceAccountName: aicoe-ci
pipelineRef:
name: overlays-release-pipeline
params:
- name: git_ref
value: $(params.git_ref)
- name: git_ref_type
value: $(params.git_ref_type)
- name: repo_name
value: $(params.repo_name)
- name: repo_url
value: $(params.repo_url)
- name: default_branch
value: $(params.default_branch)
- name: base_image
value: ""
- name: arch
value: ""
- name: build_stratergy
value: "Source"
- name: dockerfile_path
value: ""
- name: build_source_script
value: ""
- name: custom_tag
value: ""
- name: registry
value: ""
- name: registry_org
value: ""
- name: registry_project
value: ""
- name: registry_secret
value: {registry_secret}
- name: deploy
value: ""
- name: deploy_project_org
value: ""
- name: deploy_project_name
value: ""
- name: deploy_image_name
value: ""
- name: overlay_contextpath
value: ""
- name: overlays_name
value: ""
- name: overlays_dir
value: ""
resources:
- name: git-repo
resourceSpec:
type: git
params:
- name: revision
value: $(params.default_branch)
- name: url
value: $(params.repo_url)
- name: s2i-thoth
resourceSpec:
type: image
params:
- name: url
value: $(resources.inputs.s2i-thoth.url)
EOF
- name: overlays-pipeline-setup
image: $(resources.inputs.s2i-thoth.url)
workingDir: /workspace/repo
securityContext:
privileged: true
script: |
#!/usr/bin/env python3
import os
import json
import yaml
import uuid
ci_conf, thoth_conf = {}, {}
with open(".aicoe-ci.yaml", "r") as ci_stream:
ci_conf = yaml.safe_load(ci_stream)
uid = str(uuid.uuid4())[0:6]
if os.path.isfile(".thoth.yaml"):
with open(".thoth.yaml", "r") as thoth_stream:
thoth_conf = yaml.safe_load(thoth_stream)
if thoth_conf.get("overlays_dir"):
for runtime_env in thoth_conf["runtime_environments"]:
for overlay_env in ci_conf["overlays"]:
if runtime_env["name"] == overlay_env["name"] and "base_image" in runtime_env:
overlay_env["build"]["base-image"] = runtime_env.get("base_image")
overlays_dir = ci_conf.get("overlays_dir", "overlays")
for overlay_env in ci_conf["overlays"]:
with open("overlays-pipelinerun.yaml", "r") as pipelinerun_yaml:
pipelinerun = yaml.safe_load(pipelinerun_yaml)
overlay_name = overlay_env["name"]
pipelinerun["metadata"]["name"] = pipelinerun["metadata"]["name"].replace(
"{overlays}", overlay_name
)
pipelinerun["metadata"]["name"] = pipelinerun["metadata"]["name"] + '-' + uid
pipelinerun["metadata"]["labels"]["overlay"] = overlay_name
spec_params = []
for param in pipelinerun["spec"]["params"]:
for ele in overlay_env["build"]:
if param["name"] == "_".join(ele.split("-")):
param["value"] = overlay_env["build"].get(ele, "")
for ele in overlay_env.get("deploy", []):
if param["name"] == "overlay_contextpath":
param["value"] = overlay_env["deploy"].get(
"overlay-contextpath", ""
)
elif param["name"] == "deploy_" + "_".join(ele.split("-")):
param["value"] = overlay_env["deploy"].get(ele, "")
if param["name"] == "deploy":
param["value"] = "deploy" if overlay_env.get("deploy") else ""
if param["name"] == "overlays_name":
param["value"] = overlay_name
if param["name"] == "overlays_dir":
param["value"] = overlays_dir
spec_params.append(param)
pipelinerun["spec"]["params"] = spec_params
with open(
f"/workspace/pipelinerun-{overlay_name}.yaml", "w"
) as output_pipelinerun_yaml:
yaml.dump(
pipelinerun, output_pipelinerun_yaml, default_flow_style=False
)
- name: start-pipeline
image: quay.io/openshift/origin-cli:latest
workingDir: /workspace/repo
script: |
for overlay_file in /workspace/*.yaml
do
oc apply -f $overlay_file
done