forked from vfarcic/crossplane-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
210 lines (155 loc) · 5.88 KB
/
setup.sh
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
#!/bin/sh
set -e
gum style \
--foreground 212 --border-foreground 212 --border double \
--margin "1 2" --padding "2 4" \
'Setup for the examples of the Crossplane Configuration
"dot-application".'
gum confirm '
Are you ready to start?
Feel free to say "No" and inspect the script if you prefer setting up resources manually.
' || exit 0
rm -f .env
################
# Requirements #
################
echo "
## You will need following tools installed:
|Name |Required |More info |
|----------------|---------------------|---------------------------------------------------|
|helm |Yes |'https://helm.sh/docs/intro/install/' |
|kubectl |Yes |'https://kubernetes.io/docs/tasks/tools/#kubectl' |
|yq |Yes |'https://github.com/mikefarah/yq#install' |
|Google Cloud CLI|If using Google Cloud|'https://cloud.google.com/sdk/docs/install' |
" | gum format
gum confirm "
Do you have those tools installed?
" || exit 0
gum confirm '
Do you have a Kubernetes cluster with an ingress controller
up-and-running?
' || exit 0
echo "
Which Hyperscaler do you want to use?"
HYPERSCALER=$(gum choose "google" "aws" "azure" "none")
echo "export HYPERSCALER=$HYPERSCALER" >> .env
# TODO: Remove once other hyperscalers are supported
if [[ "$HYPERSCALER" != "google" ]]; then
gum style \
--foreground 212 --border-foreground 212 --border double \
--margin "1 2" --padding "2 4" \
'Right now, the script supports only Google Cloud.
Please open an issue if you would like me (or you) to add support
for other hyperscalers.'
exit 0
fi
kubectl create namespace a-team
export INGRESS_CLASS=$(kubectl get ingressclasses \
--output jsonpath="{.items[0].metadata.name}")
INGRESS_HOST=$(gum input --placeholder "What is the external IP of the Ingress service" --value "127.0.0.1")
echo "export INGRESS_HOST=$INGRESS_HOST" >> .env
yq --inplace \
".spec.parameters.host = \"silly-demo.$INGRESS_HOST.nip.io\"" \
examples/backend-db-google.yaml
###################################
# External Secrets Operator (ESO) #
###################################
if [[ "$HYPERSCALER" != "none" ]]; then
helm upgrade --install \
external-secrets external-secrets \
--repo https://charts.external-secrets.io \
--namespace external-secrets --create-namespace --wait
fi
##############
# Crossplane #
##############
helm upgrade --install crossplane crossplane-stable/crossplane \
--namespace crossplane-system --create-namespace --wait
kubectl apply --filename dependencies
sleep 2
kubectl wait --for=condition=healthy provider.pkg.crossplane.io \
--all --timeout=300s
kubectl apply --filename config.yaml
sleep 10
kubectl wait --for=condition=healthy provider.pkg.crossplane.io \
--all --timeout=300s
############################
# Crossplane: Hyperscalers #
############################
if [[ "$HYPERSCALER" == "google" ]]; then
export PROJECT_ID=dot-$(date +%Y%m%d%H%M%S)
echo "export PROJECT_ID=${PROJECT_ID}" >> .env
gcloud projects create ${PROJECT_ID}
echo "
Please open https://console.cloud.google.com/billing/enable?project=${PROJECT_ID} in a browser and set the billing account."
gum input --placeholder "
Press the enter key to continue."
echo "
Please open https://console.cloud.google.com/apis/library/sqladmin.googleapis.com?project=${PROJECT_ID} in a browser and ENABLE* the API."
gum input --placeholder "
Press the enter key to continue."
echo "
Please open https://console.cloud.google.com/marketplace/product/google/secretmanager.googleapis.com?project=${PROJECT_ID} in a browser and ENABLE* the API."
gum input --placeholder "
Press the enter key to continue."
export SA_NAME=devops-toolkit
export SA="${SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"
gcloud iam service-accounts create $SA_NAME \
--project ${PROJECT_ID}
export ROLE=roles/admin
gcloud projects add-iam-policy-binding \
--role $ROLE ${PROJECT_ID} --member serviceAccount:$SA
gcloud iam service-accounts keys create gcp-creds.json \
--project ${PROJECT_ID} --iam-account $SA
kubectl --namespace crossplane-system \
create secret generic gcp-creds \
--from-file creds=./gcp-creds.json
gcloud iam service-accounts --project ${PROJECT_ID} \
create external-secrets
echo '{"password": "YouWillNeverFindOut"}\c' \
| gcloud secrets --project ${PROJECT_ID} \
create production-postgresql --data-file=-
gcloud secrets --project ${PROJECT_ID} \
add-iam-policy-binding production-postgresql \
--member "serviceAccount:external-secrets@${PROJECT_ID}.iam.gserviceaccount.com" \
--role "roles/secretmanager.secretAccessor"
gcloud iam service-accounts --project ${PROJECT_ID} \
keys create account.json \
--iam-account=external-secrets@${PROJECT_ID}.iam.gserviceaccount.com
kubectl --namespace external-secrets \
create secret generic google \
--from-file=credentials=account.json
echo "
apiVersion: gcp.upbound.io/v1beta1
kind: ProviderConfig
metadata:
name: default
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
argocd.argoproj.io/hook: PostSync
spec:
projectID: ${PROJECT_ID}
credentials:
source: Secret
secretRef:
namespace: crossplane-system
name: gcp-creds
key: creds" \
| kubectl apply --filename -
echo "
apiVersion: external-secrets.io/v1beta1
kind: ClusterSecretStore
metadata:
name: google
spec:
provider:
gcpsm:
auth:
secretRef:
secretAccessKeySecretRef:
name: google
key: credentials
namespace: external-secrets
projectID: ${PROJECT_ID}" \
| kubectl apply --filename -
fi