-
Notifications
You must be signed in to change notification settings - Fork 1
/
e2e-install.sh
executable file
·331 lines (279 loc) · 9.85 KB
/
e2e-install.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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/usr/bin/env bash
set -e
# This script installs an opinionated footprint of cf-toolsuite services
ORG_HOME=observability
SPACE_HOME=cf-toolsuite
function determine_jar_release() {
local date_pattern='[0-9]{4}\.[0-9]{2}\.[0-9]{2}'
local date=""
local current_date=""
for file in target/*.jar; do
if [[ $file =~ $date_pattern ]]; then
current_date="${BASH_REMATCH[0]}"
if [[ -z $date ]]; then
date="$current_date"
elif [[ $date != "$current_date" ]]; then
echo "Varying dates found."
return 1
fi
else
echo "No matching date found in: $file"
return 1
fi
done
if [[ -n $date ]]; then
echo $date
else
echo "No files with the expected date pattern found."
return 1
fi
}
# Define a function that checks for the existence of a file within the 'target' sub-directory.
# The function takes one parameter: the first few characters of a filename.
file_exists() {
local starts_with=$1
local search_pattern="./target/${starts_with}-1.0-SNAPSHOT.jar"
# Use find command to search for files matching the pattern
files_found=$(find . -wholename "$search_pattern")
# Check if the find command's result is non-empty
if [[ -n $files_found ]]; then
return 0
else
return 1
fi
}
# clones the repo if it doesn't exist
function clone_repo() {
local repo="$1"
name=$(echo "$repo" | cut -d '/' -f 2)
if [ ! -d "$name" ]; then
gh repo clone "$repo"
else
echo "$repo already exists, skipping clone..."
fi
}
# forks then clones the repo if it doesn't exist
function fork_clone_repo() {
local repo="$1"
local fork_name="$2"
name=$(echo "$fork_name" | cut -d '/' -f 2)
if [ ! -d "$name" ]; then
gh repo fork "$repo" --fork-name "$fork_name" --clone --remote
else
echo "$repo already exists, skipping fork and clone..."
fi
}
echo "-- Starting installation"
# Create configuration directory
mkdir -p /tmp/config
# Install cf-toolsuite to a target foundation
if [ -z "$1" ] && [ -z "$2" ] && [ -z "$3" ]; then
echo "Usage: e2e-install.sh {cf-api} {cf-admin-username} {cf-admin-password} {clone-projects} {build-projects} {mode} {config-suffix} {gateway-deployed}"
exit 1
fi
# e.g.,
# Default target, Dhaka: ./scripts/e2e-install.sh api.sys.dhaka.cf-app.com sso ' '
# Alternate foundation: ./scripts/e2e-install.sh api.sys.orca-916168.cf-app.com username 'password' true true full-install orca
CF_API="${1}"
CF_ADMIN="${2}"
CF_PASSWORD="${3}"
CLONE_PROJECTS="${4:-true}"
BUILD_PROJECTS="${5:-true}"
MODE="${6:-full-install}"
SUFFIX="${7:-dhaka}"
GATEWAY_DEPLOYED="${8:-false}"
echo "-- Verify required configuration files exist"
if [ ! -e "/tmp/config/secrets.cf-butler.$SUFFIX.json" ] || [ ! -e "/tmp/config/secrets.cf-archivist.$SUFFIX.json" ]; then
echo "Required configuration files missing! Please place secrets.cf-butler.$SUFFIX.json and secrets.cf-archivist.$SUFFIX.json inside the /tmp/config directory. Then attempt to re-run this script."
echo "If you haven't created these files yet, look in the footprints/tas/config directory for inspiration."
exit 1
fi
echo "-- Setting API endpoint for target foundation"
cf api "$CF_API"
echo "-- Authenticating"
if [ "$CF_ADMIN" = "sso" ]; then
cf login --sso
else
cf login -u "$CF_ADMIN" -p "$CF_PASSWORD"
fi
echo "-- Creating organization and space"
# Make sure org quota is set to support something like:
# ❯ cf org-quota runaway
# Getting org quota runaway as chris.phillipson...
# total memory: 100G
# instance memory: unlimited
# routes: 1000
# service instances: unlimited
# paid service plans: allowed
# app instances: unlimited
# route ports: 0
# log volume per second: unlimited
cf create-org $ORG_HOME
cf create-space -o $ORG_HOME $SPACE_HOME
echo "-- Targeting organization and space"
cf target -o $ORG_HOME -s $SPACE_HOME
cd /tmp
if [ "$CLONE_PROJECTS" == "true" ]; then
echo "-- Cloning Github repositories"
clone_repo 'cf-toolsuite/cf-butler'
fork_clone_repo 'cf-toolsuite/cf-butler-sample-config' 'cf-butler-config'
clone_repo 'cf-toolsuite/cf-hoover'
fork_clone_repo 'cf-toolsuite/cf-hoover-config' 'cf-hoover-config'
clone_repo 'cf-toolsuite/cf-hoover-ui'
clone_repo 'cf-toolsuite/cf-archivist'
fork_clone_repo 'cf-toolsuite/cf-archivist-sample-config' 'cf-archivist-config'
fi
if [ "$BUILD_PROJECTS" == "true" ]; then
echo "-- Building applications"
if [ "$MODE" == "butler-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-butler
./mvnw clean package -Ph2,expose-runtime-metadata
cd ..
fi
if [ "$MODE" == "hoover-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-hoover
./mvnw clean package -Pexpose-runtime-metadata
cd ..
fi
if [ "$MODE" == "hoover-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-hoover-ui
./mvnw clean verify --batch-mode -DskipTests -Pproduction,expose-runtime-metadata
cd ..
fi
if [ "$MODE" == "archivist-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-archivist
./mvnw clean verify --batch-mode -DskipTests -Pproduction,expose-runtime-metadata
cd ..
fi
else
echo "-- Verifying artifacts exist"
if [ "$MODE" == "butler-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-butler
if file_exists "cf-butler"; then
echo "+- cf-butler artifact exists!"
else
echo "+- Fetching latest available cf-butler artifact from Github Packages repository"
mkdir -p target
gh release download --pattern '*.jar' -D target --skip-existing
RELEASE=$(determine_jar_release)
sed -i'' -e "s/1.0-SNAPSHOT/$RELEASE/g" manifest.yml
fi
cd ..
fi
if [ "$MODE" == "hoover-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-hoover
if file_exists "cf-hoover"; then
echo "+- cf-hoover artifact exists!"
else
echo "+- Fetching latest available cf-hoover artifact from Github Packages repository"
mkdir -p target
gh release download --pattern '*.jar' -D target --skip-existing
RELEASE=$(determine_jar_release)
sed -i'' -e "s/1.0-SNAPSHOT/$RELEASE/g" manifest.yml
sed -i'' -e "s/1.0-SNAPSHOT/$RELEASE/g" manifest.with-registry.yml
fi
cd ..
fi
if [ "$MODE" == "hoover-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-hoover-ui
if file_exists "cf-hoover-ui"; then
echo "+- cf-hoover-ui artifact exists!"
else
echo "+- Fetching latest available cf-hoover-ui artifact from Github Packages repository"
mkdir -p target
gh release download --pattern '*.jar' -D target --skip-existing
RELEASE=$(determine_jar_release)
sed -i'' -e "s/1.0-SNAPSHOT/$RELEASE/g" manifest.yml
fi
cd ..
fi
if [ "$MODE" == "archivist-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-archivist
if file_exists "cf-archivist"; then
echo "+- cf-archivist artifact exists!"
else
echo "+- Fetching latest available cf-archivist artifact from Github Packages repository"
mkdir -p target
gh release download --pattern '*.jar' -D target --skip-existing
RELEASE=$(determine_jar_release)
sed -i'' -e "s/1.0-SNAPSHOT/$RELEASE/g" manifest.yml
fi
cd ..
fi
fi
echo "-- Deploying applications"
if [ "$MODE" == "butler-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-butler
if [[ "$GATEWAY_DEPLOYED" == "true" ]]; then
./scripts/deploy.alt.sh --with-credhub /tmp/config/secrets.cf-butler.$SUFFIX.json --no-route
cf map-route cf-butler apps.internal --hostname cf-butler
else
./scripts/deploy.alt.sh --with-credhub /tmp/config/secrets.cf-butler.$SUFFIX.json
fi
cd ..
fi
if [ "$MODE" == "hoover-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-hoover-config
# Get the repository URL using `git remote get-url`
repository_url=$(git remote get-url origin)
# Extract the owner from the repository URL (SSH or https)
owner=$(echo "$repository_url" | sed -nr 's/.*github.com[\/:](.*)\/.*/\1/p')
cd ../cf-hoover
mkdir -p config
cp -f samples/config-server.json config
sed -i'' -e "s/cf-toolsuite/$owner/g" "config/config-server.json"
if [[ "$GATEWAY_DEPLOYED" == "true" ]]; then
./scripts/deploy.with-registry.sh --no-route
cf map-route cf-hoover apps.internal --hostname cf-hoover
else
./scripts/deploy.with-registry.sh
fi
cd ..
fi
if [ "$MODE" == "hoover-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-hoover-ui
if [[ "$GATEWAY_DEPLOYED" == "true" ]]; then
./scripts/deploy.sh --no-route
cf map-route cf-hoover-ui apps.internal --hostname cf-hoover-ui
else
./scripts/deploy.sh
fi
cd ..
fi
if [ "$MODE" == "archivist-only" ] || [ "$MODE" == "full-install" ]; then
cd cf-archivist
if [[ "$GATEWAY_DEPLOYED" == "true" ]]; then
./scripts/deploy.alt.sh --with-credhub /tmp/config/secrets.cf-archivist.$SUFFIX.json --no-route
cf map-route cf-archivist apps.internal --hostname cf-archivist
else
./scripts/deploy.alt.sh --with-credhub /tmp/config/secrets.cf-archivist.$SUFFIX.json
fi
cd ..
fi
if [[ "$GATEWAY_DEPLOYED" == "true" ]]; then
GW_NAME=cf-toolsuite
cf create-service p.gateway standard $GW_NAME -c "{ \"host\": \"$GW_NAME\" }"
for (( i = 0; i < 90; i++ )); do
if [[ $(cf service $GW_NAME) != *"succeeded"* ]]; then
echo "$GW_NAME is not ready yet..."
sleep 10
else
break
fi
done
if [ "$MODE" == "butler-only" ] || [ "$MODE" == "full-install" ]; then
cf bind-service cf-butler $GW_NAME -c .gw-butler.json
cf restage cf-butler
fi
if [ "$MODE" == "hoover-only" ] || [ "$MODE" == "full-install" ]; then
cf bind-service cf-hoover $GW_NAME -c .gw-hoover.json
cf restage cf-hoover
cf bind-service cf-hoover-ui $GW_NAME -c .gw-hoover-ui.json
cf restage cf-hoover-ui
fi
if [ "$MODE" == "archivist-only" ] || [ "$MODE" == "full-install" ]; then
cf bind-service cf-archivist $GW_NAME -c .gw-archivist.json
cf restage cf-archivist
fi
fi
echo "-- Completed installation"