This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Dispatchfile
131 lines (111 loc) · 5.35 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
#!mesosphere/dispatch-starlark:v0.8
# vi:syntax=python
load("github.com/mesosphere/dispatch-catalog/starlark/stable/[email protected]", "git_resource")
load("github.com/mesosphere/dispatch-catalog/starlark/stable/[email protected]", "tag", "pull_request", "push")
load("github.com/mesosphere/dispatch-catalog/starlark/stable/[email protected]", "secret_var")
dispatch_common_go_environment = [
k8s.corev1.EnvVar(name="GOARCH", value="amd64"),
k8s.corev1.EnvVar(name="GOOS", value="linux"),
k8s.corev1.EnvVar(name="GOPATH", value="/")
]
dispatch_git_secrets_environment = 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"))]
# Git Resource Reference Names
git_resource_konvoy = "konvoy-git"
git_resource_konvoy_soak = "gitops-git"
git_resource_kubeaddons_kommander = "kubeaddons-kommander-git"
# Git Resources
git_resource(git_resource_kubeaddons_kommander, url="https://github.com/mesosphere/kubeaddons-kommander", revision="$(context.git.commit)")
git_resource(git_resource_konvoy_soak, url="https://github.com/mesosphere/konvoy-soak", revision="master")
git_resource(git_resource_konvoy, url="https://github.com/mesosphere/konvoy", revision="master")
# Dispatch Tasks
def update_konvoy(task_name, target_branch):
task(task_name, inputs=[git_resource_konvoy, git_resource_kubeaddons_kommander], steps=[
v1.Container(
name=task_name,
image="mesosphere/bump-kubeaddons-kommander:master",
command=["/bin/bash", "-c"],
args=["update_kubeaddons_kommander.py", "--konvoy_target_branch", target_branch, "--kubeaddons_kommander_tag", "$(context.git.tag)"],
resources=k8s.corev1.ResourceRequirements(
limits={"cpu": k8s.resource_quantity("1000m"), "memory": k8s.resource_quantity("4Gi")}
),
env=dispatch_git_secrets_environment
)
])
return task_name
update_konvoy_master = update_konvoy("update-konvoy-master", "master")
update_konvoy_r17 = update_konvoy("update-konvoy-r17", "release-1.7")
update_konvoy_r16 = update_konvoy("update-konvoy-r16", "release-1.6")
task("update-soak", inputs=[git_resource_konvoy_soak, git_resource_kubeaddons_kommander], steps=[
v1.Container(
name="fetch-master",
image="alpine/git:v2.24.3",
workingDir="/workspace/" + git_resource_konvoy_soak,
args=[
"fetch",
"origin",
"master"
]
),
v1.Container(
name = "update-kommander-version",
image = "mikefarah/yq:3.3.4",
workingDir = "/workspace/{}/aws/".format(git_resource_konvoy_soak),
command = ["/bin/sh"],
args = [
"-c",
"yq w --doc 1 --inplace cluster.yaml spec.addons[3].configVersion $(context.git.tag)"
]
),
v1.Container(
name = "update-gitops-repo",
image = "mesosphere/update-gitops-repo:1.1.1",
workingDir = "/workspace/" + git_resource_konvoy,
command = ["/bin/sh", "-c"],
args = [
"""
set -x
depth=10
git fetch --tags --depth=$depth origin master
tag_head_sha=$(git rev-parse $(context.git.tag))
git log origin/master -n $depth | grep -q $tag_head_sha
if [ "$?" -eq 1 ]; then
echo The commit from tag $(context.git.tag) is not on the master branch
exit 0
fi
set +x
cd /workspace/gitops-git/aws
set -e
echo "$GPG_PRIVATE_KEY" > gpg_private_key
echo "$GPG_PUBLIC_KEY" > gpg_public_key
set -x
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]'
update-gitops-repo \
-git-revision={} \
-filepath=none.yaml.tmpl \
-commit-message="Update Kommander to {}"
""".format("$(context.git.commit)", "$(context.git.tag)")
],
env=[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"))]
)
])
# Dispatch Actions
action(tasks=["update-soak"], on=p.Condition(release=p.ReleaseCondition(tags=["v*"])))
action(tasks=[update_konvoy_master], on=p.Condition(release=p.ReleaseCondition(tags=["testing-1.20*"])))
action(tasks=[update_konvoy_master], on=p.Condition(release=p.ReleaseCondition(tags=["stable-1.20*"])))
action(tasks=[update_konvoy_r17], on=p.Condition(release=p.ReleaseCondition(tags=["testing-1.19*"])))
action(tasks=[update_konvoy_r17], on=p.Condition(release=p.ReleaseCondition(tags=["stable-1.19*"])))
action(tasks=[update_konvoy_r16], on=p.Condition(release=p.ReleaseCondition(tags=["testing-1.18*"])))
action(tasks=[update_konvoy_r16], on=p.Condition(release=p.ReleaseCondition(tags=["stable-1.18*"])))
# Dispatch Interactive Tasks - Useful only for testing
action(tasks=[update_konvoy_master], on=pull_request(chatops=[update_konvoy_master]))