-
Notifications
You must be signed in to change notification settings - Fork 69
/
setup.sh
executable file
·189 lines (138 loc) · 6.11 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
#!/bin/bash
set -e
rm -f .env
cp iac/do-cluster/.env .
source .env
gum style \
--foreground 212 --border-foreground 212 --border double \
--margin "1 2" --padding "2 4" \
'Backstage Demo Setup'
echo "
## You will need following tools installed:
|Name |Required |More info |
|----------------|---------------------|---------------------------------------------------|
|gum |Yes |'https://github.com/charmbracelet/gum' |
|gitHub CLI |Yes |'https://cli.github.com/' |
|yq |Yes |'https://github.com/mikefarah/yq#install' |
|kubeseal |Yes |'https://github.com/bitnami-labs/sealed-secrets#kubeseal'|
|Helm |Yes |'https://github.com/helm/helm#install' |
|kubectl |Yes |'https://github.com/kubernetes/kubectl' |
|argocd-cli |Yes |'https://argo-cd.readthedocs.io/en/stable/cli_installation/'|
" | gum format
gum confirm "
Do you have those tools installed?
" || exit 0
#gum confirm "Do you want to use an organizational GitHub account?" && USE_GH_ORG=true || USE_GH_ORG=false
#if $USE_GH_ORG ; then
# GITHUB_ORG=$(gum input \
# --placeholder "Which GitHub organization do you want to use?" \
# --value "$GITHUB_ORG")
# gh repo fork dirien/backstage-demo --clone --remote \
# --org $GITHUB_ORG
#else
# GITHUB_ORG=$(gum input \
# --placeholder "What's your GitHub user name?" \
# --value "$GITHUB_ORG")
# gh repo fork dirien/backstage-demo --clone --remote
#fi
#echo "export GITHUB_ORG=$GITHUB_ORG" >> .env
#echo "export GITHUB_ORG=dirien" >> .env
GITHUB_ORG=$(gum input --placeholder "Which GitHub organization/user do you want to use?" --value "GITHUB_ORG")
echo "export GITHUB_ORG=$GITHUB_ORG" >> .env
#cd backstage-demo
export INGRESS_HOST=$(\
kubectl --namespace default get service nginx-ingress-ingress-nginx-controller \
--output jsonpath="{.status.loadBalancer.ingress[0].ip}")
echo "export INGRESS_HOST=$INGRESS_HOST" >> .env
#yq --inplace \
# ".server.ingress.ingressClassName = \"$INGRESS_CLASS\"" \
# argocd/helm-values.yaml
yq --inplace \
".server.ingress.hostname = \"argocd.$INGRESS_HOST.nip.io\"" \
argocd/helm-values.yaml
yq --inplace \
".spec.source.repoURL = \"https://github.com/$GITHUB_ORG/backstage-demo\"" \
argocd/production-apps.yaml
yq --inplace \
".spec.source.repoURL = \"https://github.com/$GITHUB_ORG/backstage-demo\"" \
argocd/production-infra.yaml
yq --inplace \
".spec.source.repoURL = \"https://github.com/$GITHUB_ORG/backstage-demo\"" \
argocd/users-api.yaml
yq --inplace \
".spec.sources[0].repoURL = \"https://github.com/$GITHUB_ORG/backstage-demo\"" \
argocd/backstage.yaml
yq --inplace \
".spec.sources[2].repoURL = \"https://github.com/$GITHUB_ORG/backstage-demo\"" \
argocd/backstage.yaml
gum style \
--foreground 212 --border-foreground 212 --border double \
--margin "1 2" --padding "2 4" \
'Create a token in GitHub - https://github.com/settings/tokens' \
'or by navigating to Settings -> Developer Settings (left panel) ->' \
'Personal Access Token -> Tokens (Classic) -> Generate new token' \
'' \
'Required permissions:' \
' - repo' \
' - read:org' \
' - read:user' \
' - user:email' \
' - workflow'
GITHUB_TOKEN=$(gum input --placeholder "GitHub token" --value "$GITHUB_TOKEN" --password)
echo "export GITHUB_TOKEN=$GITHUB_TOKEN" >> .env
#yq --inplace \
# ".data.ARGOCD_URL = \"http://argocd.$INGRESS_HOST.nip.io/api/v1/\"" \
# backstage-resources/bs-config.yaml
yq --inplace \
".backstage.backstage.extraEnvVars |= map(select(.name == \"ARGOCD_URL\").value = \"http://argocd.$INGRESS_HOST.nip.io/api/v1/\")" \
backstage-resources/helm-values.yaml
#yq --inplace \
# ".data.CATALOG_LOCATION = \"https://github.com/$GITHUB_ORG/backstage-demo/blob/main/catalog/catalog-all.yaml\"" \
# backstage-resources/bs-config.yaml
yq --inplace \
".backstage.backstage.extraEnvVars |= map(select(.name == \"CATALOG_LOCATION\").value = \"https://github.com/$GITHUB_ORG/backstage-demo/blob/main/catalog/catalog-all.yaml\")" \
backstage-resources/helm-values.yaml
export BACKSTAGE_URL="backstage.$INGRESS_HOST.nip.io"
echo "export BACKSTAGE_URL=$BACKSTAGE_URL" >> .env
#yq --inplace ".data.BASE_URL = \"$BACKSTAGE_URL\"" \
# backstage-resources/bs-config.yaml
yq --inplace \
".backstage.ingress.host = \"$BACKSTAGE_URL\"" \
backstage-resources/helm-values.yaml
yq --inplace \
".backstage.backstage.extraEnvVars |= map(select(.name == \"BASE_URL\").value = \"$BACKSTAGE_URL\")" \
backstage-resources/helm-values.yaml
echo "
Deploying ArgoCD
" | gum format
###########
# Argo CD #
###########
helm upgrade --install argocd argo-cd \
--repo https://argoproj.github.io/argo-helm \
--namespace argocd --create-namespace \
--values argocd/helm-values.yaml --wait
echo "http://argocd.$INGRESS_HOST.nip.io"
# Open the URL from the output in a browser
# Use `admin` as the user and `admin123` as the password
cat argocd/production-apps.yaml
cat argocd/production-infra.yaml
kubectl apply --filename argocd/production-infra.yaml
kubectl apply --filename argocd/production-apps.yaml
export ARGOCD_ADMIN_PASSWORD=admin123
argocd login --insecure --port-forward --insecure \
--username admin --password $ARGOCD_ADMIN_PASSWORD \
--port-forward-namespace argocd --grpc-web --plaintext
# Generate API auth token for ArgoCD
export ARGOCD_AUTH_TOKEN=$(argocd account generate-token \
--port-forward --port-forward-namespace argocd)
export ARGOCD_AUTH_TOKEN_ENCODED="argocd.token=$ARGOCD_AUTH_TOKEN"
echo "export ARGOCD_AUTH_TOKEN_ENCODED=$ARGOCD_AUTH_TOKEN_ENCODED" >> .env
echo "export ARGOCD_URL=http://argocd.$INGRESS_HOST.nip.io" >> .env
echo "
Setup Done!
Please Make Sure You Can Access ArgoCD UI:
ArgoCD NIP http://argocd.$INGRESS_HOST.nip.io
Username: admin
Password: admin123
" | gum format