-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathdot.nu
executable file
·247 lines (166 loc) · 5.73 KB
/
dot.nu
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env nu
source scripts/get-hyperscaler.nu
source scripts/github.nu
source scripts/kubernetes.nu
source scripts/ingress.nu
source scripts/crossplane.nu
source scripts/kyverno.nu
source scripts/argocd.nu
source scripts/argo-workflows.nu
source scripts/argo-events.nu
source scripts/registry.nu
source scripts/backstage.nu
source scripts/flux.nu
source scripts/gatekeeper.nu
def main [] {}
# Destroys the IDP chapter
def "main destroy idp" [] {
do --ignore-errors {(
kubectl --namespace production delete
--filename crossplane/repo.yaml
)}
cd cncf-demo-app
do --ignore-errors {
git pull
kubectl --namespace production delete --filename apps/
touch apps/empty
rm --force apps/*.yaml
git add .
git commit -m "Destroy"
git push
}
cd ..
main delete crossplane
if $env.HYPERSCALER == "google" {
gcloud projects delete $env.PROJECT_ID --quiet
}
main destroy kubernetes $env.HYPERSCALER
rm --force --recursive cncf-demo-app
gh repo delete $"($env.GITHUB_USER)/cncf-demo-app"
}
# Sets up the IDP chapter
def "main setup idp" [] {
rm --force .env
rm --force "kubeconfig*.yaml"
let hyperscaler = main get hyperscaler
main create kubernetes $hyperscaler
main apply ingress contour --hyperscaler $hyperscaler
kubectl create namespace production
}
# Sets up the IDP Crossplane chapter
def "main setup idp_crossplane" [
hyperscaler: string
] {
let github_data = main get github
(
main apply crossplane
--hyperscaler $hyperscaler
--db true --app true --github true
--github_user $github_data.user
--github_token $github_data.token
)
if $hyperscaler == "azure" {
let date_suffix = (date now | format date "%Y%m%d%H%M%S")
open crossplane/azure-sql.yaml |
| upsert spec.id $"silly-demo-db-($date_suffix)"
| save crossplane/azure-sql.yaml --force
open crossplane/azure-sql-password.yaml |
| upsert metadata.name $"silly-demo-db-($date_suffix)-password"
| save crossplane/azure-sql-password.yaml --force
open crossplane/app.yaml |
| upsert spec.parameters.db.secret $"silly-demo-db-($date_suffix)"
| save crossplane/app.yaml --force
} else {
open crossplane/app.yaml |
| upsert spec.parameters.db.secret "silly-demo-db"
| save crossplane/app.yaml --force
}
open crossplane/app.yaml
| upsert spec.parameters.host $"silly-demo.($env.INGRESS_IP).nip.io"
| upsert spec.parameters.image $"ghcr.io/($github_data.user)/cncf-demo-app"
| upsert spec.parameters.tag "FIXME"
| save crossplane/app.yaml --force
$"export API=crossplane\n" | save --append .env
$github_data
}
# Sets up the IDP Crossplane chapter
def "main setup idp_kubevela" [
hyperscaler: string
] {
let github_data = main setup idp_crossplane $hyperscaler
(
kubectl --namespace production apply
--filename crossplane/repo.yaml
)
vela install
(
vela addon enable velaux
domain=$"vela.($env.INGRESS_IP).nip.io"
gatewayDriver=nginx
)
vela env init production --namespace production
for file in [
"component-db-google.cue"
"component-db-aws.cue"
"component-db-azure.cue"
"component-app-backend.cue"
"trait-scaler.cue"
] {
vela def apply $"kubevela/($file)"
}
if $hyperscaler == "azure" {
let date_suffix = (date now | format date "%Y%m%d%H%M%S")
open kubevela/azure-sql.yaml |
| upsert spec.components.0.name $"silly-demo-db-($date_suffix)"
| save kubevela/azure-sql.yaml --force
open kubevela/azure-sql-password.yaml |
| upsert metadata.name $"silly-demo-db-($date_suffix)-password"
| save kubevela/azure-sql-password.yaml --force
open kubevela/app.yaml |
| upsert spec.components.0.properties.db.secret $"silly-demo-db-($date_suffix)"
| save kubevela/app.yaml --force
} else {
open kubevela/app.yaml |
| upsert spec.components.0.properties.db.secret "silly-demo-db"
| save kubevela/app.yaml --force
}
open kubevela/app.yaml
| upsert spec.components.0.properties.host $"silly-demo.($env.INGRESS_IP).nip.io"
| upsert spec.components.0.properties.image $"ghcr.io/($github_data.user)/cncf-demo-app"
| upsert spec.components.0.properties.tag "FIXME"
| save kubevela/app.yaml --force
(
kubectl wait githubs.devopstoolkit.live
--selector crossplane.io/claim-name=cncf-demo-app
--for=condition=Ready=true --timeout 300s
)
git clone $"https://github.com/($github_data.user)/cncf-demo-app"
cd cncf-demo-app
gh pr merge init --rebase
git pull
mkdir apps
cd ..
$"export API=kubevela\n" | save --append .env
}
def "main setup idp_argo_workflows" [
github_user: string
github_pat: string
] {
let email = input $"(ansi green_bold)Enter ghcr.io registry email \(e.g., [email protected]\):(ansi reset) "
(
main apply argoworkflows
$github_user $github_pat $email --registry "ghcr.io"
)
main apply argoevents
}
def "main setup idp_argocd" [] {
(
main apply argocd
--host_name $"argocd.($env.INGRESS_HOST)"
--ingress_class_name "contour"
--apply_apps false
)
open argocd/apps-idp.yaml
| upsert spec.source.repoURL $"https://github.com/($env.GITHUB_USER)/cncf-demo-app"
| save argocd/apps-idp.yaml --force
}