forked from mesosphere/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDispatchfile
216 lines (196 loc) · 8.43 KB
/
Dispatchfile
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!mesosphere/dispatch-starlark:v0.6
# vi:syntax=python
#
load("github.com/mesosphere/dispatch-catalog/starlark/stable/[email protected]", "git_resource")
# TODO @faiq: once 0.0.5 of this package is released switch to that ref
load("github.com/mesosphere/dispatch-catalog/starlark/stable/[email protected]", "secret_var")
load("github.com/mesosphere/dispatch-catalog/starlark/stable/[email protected]", "pull_request", "push", "cron")
load("github.com/mesosphere/dispatch-catalog/starlark/stable/docker@dc4612e95b62ff8b744bda2e4d3c75cf2edeb694", "dind_task")
load("github.com/mesosphere/dispatch-tasks/bump_charts/bump_charts@master", "bump_charts", "bump_requirements")
git = "src-git"
dispatch_common_go_environment = [
k8s.corev1.EnvVar(name="GOARCH", value="amd64"),
k8s.corev1.EnvVar(name="GOOS", value="linux"),
k8s.corev1.EnvVar(name="GOPATH", value="/")
]
git_resource(git,
url="https://github.com/mesosphere/charts",
revision="$(context.git.commit)")
dind_task("publish",
inputs=[git],
steps=[
v1.Container(
name="publish-charts",
workingDir="/workspace/src-git",
args=[
"/bin/bash", "-c",
"""
git fetch origin master --unshallow
export GIT_REMOTE_URL=https://mesosphere:${GITHUB_USER_TOKEN}@github.com/mesosphere/charts.git
git config --global user.name 'Dispatch CI'
git config --global user.email '[email protected]'
make publish
"""
],
env=dispatch_common_go_environment + [
k8s.corev1.EnvVar(name="GITHUB_USER_TOKEN", valueFrom=secret_var("scmtoken", "password"))
]
)
]
)
dind_task("lint",
inputs=[git],
steps=[
v1.Container(
name="lint-charts",
workingDir="/workspace/src-git",
args=[
"/bin/bash", "-c",
"""
git fetch origin master --unshallow
make lint
"""
],
env=dispatch_common_go_environment
)
]
)
dind_task("test-helm2",
inputs=[git],
deps=["lint"],
steps=[
v1.Container(
name="charts-helm2",
workingDir="/workspace/src-git",
args=[
"/bin/bash", "-c",
"""
git fetch origin master --unshallow
make test.helm2
"""
],
env=dispatch_common_go_environment,
resources=k8s.corev1.ResourceRequirements(
limits={
"cpu": k8s.resource_quantity("1500m"),
"memory": k8s.resource_quantity("6Gi")
}
)
)
]
)
dind_task("test-helm3",
inputs=[git],
deps=["lint"],
steps=[
v1.Container(
name="charts-helm3",
workingDir="/workspace/src-git",
args=[
"/bin/bash", "-c",
"""
git fetch origin master --unshallow
make test.helm3
"""
],
env=dispatch_common_go_environment,
resources=k8s.corev1.ResourceRequirements(
limits={
"cpu": k8s.resource_quantity("1500m"),
"memory": k8s.resource_quantity("6Gi")
}
)
)
]
)
def bump_addon(task_name, addon_git_dir):
"""
Automatically creates PRs on the source repo to update helm charts within addon yaml definitions.
"""
task(task_name, inputs=[git, addon_git_dir], steps=[
v1.Container(
name=task_name,
image="mesosphere/bump-charts:master", # This docker image is built in this repo: https://github.com/mesosphere/dispatch-tasks
workingDir="/workspace/" + addon_git_dir,
command=["/bin/sh", "-c"],
args=[
"""
set -e
echo "$GPG_PRIVATE_KEY" > gpg_private_key
echo "$GPG_PUBLIC_KEY" > gpg_public_key
set -x
git fetch origin
gpg --import gpg_private_key
gpg --import gpg_public_key
git config --local commit.gpgsign true
git config --local user.signingkey $GPG_KEY_ID
git config --local user.name 'Dispatch CI'
git config --local user.email '[email protected]'
cp /bump_charts/update_single_addon.py /bump_charts/bump_charts.py .
cd /workspace/{}
git fetch --depth=3
CHANGED_FILES=$(git diff --name-only HEAD^)
cd /workspace/{}
python3 update_single_addon.py --changed-files "$CHANGED_FILES" --repo-name {} --commit-sha $(context.git.commit)
""".format(git, addon_git_dir, addon_git_dir)
],
resources=k8s.corev1.ResourceRequirements(
limits={
"cpu": k8s.resource_quantity("1000m"),
"memory": k8s.resource_quantity("4Gi")
}
),
env=dispatch_common_go_environment + [k8s.corev1.EnvVar(name="GITHUB_TOKEN", valueFrom=secret_var("d2iq-dispatch-basic-auth", "password")),
k8s.corev1.EnvVar(name="GPG_PRIVATE_KEY", valueFrom=secret_var("d2iq-dispatch-gpg", "private_key")),
k8s.corev1.EnvVar(name="GPG_PUBLIC_KEY", valueFrom=secret_var("d2iq-dispatch-gpg", "public_key")),
k8s.corev1.EnvVar(name="GPG_KEY_ID", valueFrom=secret_var("d2iq-dispatch-gpg", "key_id"))
]
)
])
return task_name
kubeaddons_kommander_git = "kubeaddons-kommander"
git_resource(
kubeaddons_kommander_git,
url="https://github.com/mesosphere/" + kubeaddons_kommander_git,
revision="master")
do_bump_kommander = bump_addon("bump-kommander", kubeaddons_kommander_git)
do_bump_kommander_catalog_api = bump_requirements("bump-catalog-api", git, "stable/kommander",
command=["/bin/sh", "-c"], args=[
"""
echo "$GPG_PRIVATE_KEY" > gpg_private_key
echo "$GPG_PUBLIC_KEY" > gpg_public_key
gpg --import gpg_private_key
gpg --import gpg_public_key
git config --local commit.gpgsign true
git config --local user.signingkey $GPG_KEY_ID
git config --local user.name 'Dispatch CI'
git config --local user.email '[email protected]'
bump_requirements --user=mesosphere --project=charts --bump-option=sliced --dependencies=kubeaddons-catalog
"""
],
env=dispatch_common_go_environment + [
k8s.corev1.EnvVar(name="GITHUB_TOKEN", valueFrom=secret_var("d2iq-dispatch-basic-auth", "password")),
k8s.corev1.EnvVar(name="GPG_PRIVATE_KEY", valueFrom=secret_var("d2iq-dispatch-gpg", "private_key")),
k8s.corev1.EnvVar(name="GPG_PUBLIC_KEY", valueFrom=secret_var("d2iq-dispatch-gpg", "public_key")),
k8s.corev1.EnvVar(name="GPG_KEY_ID", valueFrom=secret_var("d2iq-dispatch-gpg", "key_id"))
]
)
kba_git = "kubernetes-base-addons"
git_resource(
kba_git,
url="https://github.com/mesosphere/" + kba_git,
revision="master")
do_bump_addon = bump_addon("bump-addon", kba_git)
kommander_chart_path = "stable/kommander/Chart.yaml"
# Robot Actions
action(tasks=["test-helm2", "test-helm3"], on=pull_request())
action(tasks=["publish"], on=push(branches=["master"]))
action(tasks=[do_bump_kommander], on=push(branches=["master"], paths=[kommander_chart_path]))
action(tasks=[do_bump_addon], on=push(branches=["master"], paths=["!" + kommander_chart_path, "stable/*/Chart.yaml", "staging/*/Chart.yaml"]))
# Chatops Actions
action(tasks=["test-helm2", "test-helm3"], on=pull_request(chatops=["test"]))
action(tasks=["test-helm2"], on=pull_request(chatops=["test-helm2"]))
action(tasks=["test-helm3"], on=pull_request(chatops=["test-helm3"]))
action(tasks=[do_bump_kommander_catalog_api], on=pull_request(chatops=["bump-catalog-api"]))
# Cron Actions
action(name="bump-catalog-api", tasks=[do_bump_kommander_catalog_api], on=cron(schedule="0 8 * * 5"))