Skip to content

Commit 0559e26

Browse files
authored
Test Automation, Fast Kubectl (#42)
* first-round * second-set * third-push * push4 * push5 * push6 * push * push * push * push * fixes * fixes * fixes * fixes * fixes * fixes * fixes * terra optimizations * terra fixes * env.sh and fixes * docker login fix * take out vaults for now * fixes * fixes * fixes * fixes * fixes * fixes * fixes * Deploy fixes and new terraform * terraform reorg and fixes * oci_core_services fix * Update core.tf * Update core.tf * Update main-destroy.sh * fixes * Update core.tf * fixes * Update oke-setup.sh * fixes * Boost Node CPU and Memory * Rename states for clarity * Update containerengine.tf * Update main-setup.sh * Build perf and main-setup.sh restart * fix * compute shape and docker login enhancements * Update main-setup.sh * build perf tuning * build fixes * Update build-all.sh * Update oci-cli-cs-key-auth.sh * terraform 3 AD * Update oci-cli-cs-key-auth.sh * Update core.tf * fixes * Update core.tf * fixes Uncomment Internet Gateway Comment DHCP settings Move SSL creation to earlier Add wait for OKE to warm up * fixes PropSetup Back to single domain Wait for OKE nodes msdataworkshop alias cwallet.sso name change remove terraform-orig * fixes wallet.zip VM.Standard.B1.1 image Prune terraform status to 60 characters * fixes add cwallet.sso link rm wallet folder (for security) * fixes Destroy new object atp secrets wait for OKE improved logging and setup handling * minor fixes * Fixes Remove RUN_TYPE for now Execute JAVA_BUILD and NON_JAVA_BUILD from main-setup * Fixes No Key Generated messages Improve end of setup * Update containerengine.tf Change image shape * Fixes Hardening oke-setup Different Shape * Update oke-setup.sh Hardening * Parallel Destroy Make destroy run in parallel * chmod * Update main-setup.sh More hardening * Update main-setup.sh * Update oke-setup.sh More defensive code * Typo * SODA build + cleanup Replace SODA jar with maven dependency Remove old scripts Fix global deploy/undeploy scripts * Reorg Jaeger * Jaeger Fixes * DB Prep in Setup and DB Name Changes Moved DB Setup from Java to Shell Change DB Name to o and i * Fixes and Start of GB Integration * DB Name Changes * Update db-setup.sh Fixes * Update db-setup.sh * GB Integration and Prop Fixes * fixes * Update oci-cli-cs-key-auth.sh * Removed DB Setup from UI * Update oci-cli-cs-key-auth.sh * Dot Net and Go * Fixes * Manage Non-Java Builds Better * Update main-destroy.sh * Build Reorg * Update main-setup.sh Reorg password collection * Update main-setup.sh Minor fixes * Minor Fixes * Binding Changes * Fixes * Remove Legacy Code Removed admin-helidon, atp-setup, Removed initContainers from deployment yamls * Fixed inventory-helidon-se * Minor fixes * Fixes go build.sh fix * Update oke-setup.sh * Update db-setup.sh Fixed unprotected password * GB Fix and Autotest * Fixes * Update oke-setup.sh * Avoid Concurrent kubectl * Update oke-setup.sh * kubectl perf booster * kube token cache * Build reordering * Update main-setup.sh * Update main-setup.sh * Update main-setup.sh
1 parent 0408b70 commit 0559e26

File tree

6 files changed

+156
-111
lines changed

6 files changed

+156
-111
lines changed

grabdish/utils/db-setup.sh

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ while ! state_done CWALLET_SSO_AUTH_URL; do
5555
done
5656

5757

58-
while ! state_done OKE_NAMESPACE; do
59-
echo "Waiting for OKE_NAMESPACE"
60-
sleep 5
58+
# Wait for DB Password
59+
while ! state_done DB_PASSWORD; do
60+
echo "`date`: Waiting for DB_PASSWORD"
61+
sleep 2
6162
done
6263

6364

@@ -115,13 +116,6 @@ ORDER_QUEUE=ORDERQUEUE
115116
INVENTORY_QUEUE=INVENTORYQUEUE
116117

117118

118-
# Wait for DB Password
119-
while ! state_done DB_PASSWORD; do
120-
echo "`date`: Waiting for DB_PASSWORD"
121-
sleep 2
122-
done
123-
124-
125119
# Get DB Password
126120
while true; do
127121
if DB_PASSWORD=`kubectl get secret dbuser -n msdataworkshop --template={{.data.dbpassword}} | base64 --decode`; then
@@ -270,13 +264,13 @@ commit;
270264
done
271265

272266

273-
# Order DB Link"
267+
# Order DB Link
274268
while ! state_done ORDER_DB_LINK; do
275269
U=$ORDER_USER
276270
SVC=$ORDER_DB_SVC
277271
TU=$INVENTORY_USER
278272
TSVC=$INVENTORY_DB_SVC
279-
TTNS=`grep "^$TSVC " $TNS_ADMIN/tnsnames.ora`
273+
TTNS=`grep -i "^$TSVC " $TNS_ADMIN/tnsnames.ora`
280274
LINK=$ORDER_LINK
281275
sqlplus /nolog <<!
282276
WHENEVER SQLERROR EXIT 1
@@ -311,7 +305,7 @@ while ! state_done INVENTORY_DB_LINK; do
311305
SVC=$INVENTORY_DB_SVC
312306
TU=$ORDER_USER
313307
TSVC=$ORDER_DB_SVC
314-
TTNS=`grep "^$TSVC " $TNS_ADMIN/tnsnames.ora`
308+
TTNS=`grep -i "^$TSVC " $TNS_ADMIN/tnsnames.ora`
315309
LINK=$INVENTORY_LINK
316310
sqlplus /nolog <<!
317311
WHENEVER SQLERROR EXIT 1

grabdish/utils/java-builds.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
set -e
77

88

9+
BUILDS="frontend-helidon order-helidon supplier-helidon-se inventory-helidon"
10+
911
# Provision Repos
1012
while ! state_done JAVA_REPOS; do
11-
BUILDS="frontend-helidon order-helidon supplier-helidon-se inventory-helidon inventory-helidon-se"
1213
for b in $BUILDS; do
1314
oci artifacts container repository create --compartment-id "$(state_get COMPARTMENT_OCID)" --display-name "$(state_get RUN_NAME)/$b" --is-public true
1415
done
@@ -42,7 +43,6 @@ done
4243

4344
# Build all the images (no push) except frontend-helidon (requires Jaeger)
4445
while ! state_done JAVA_BUILDS; do
45-
BUILDS="frontend-helidon order-helidon supplier-helidon-se inventory-helidon inventory-helidon-se"
4646
for b in $BUILDS; do
4747
cd $GRABDISH_HOME/$b
4848
time ./build.sh

grabdish/utils/kube_token_cache.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# Copyright (c) 2021 Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
5+
TOKEN_FILE=~/.kube/TOKEN
6+
7+
if ! test -f "$TOKEN_FILE" || test $(( `date +%s` - `stat -L --format %Y $TOKEN_FILE` )) -gt 240; then
8+
umask 177
9+
oci ce cluster generate-token --cluster-id "$5" --region "$7" >$TOKEN_FILE
10+
fi
11+
12+
cat $TOKEN_FILE

grabdish/utils/main-setup.sh

Lines changed: 110 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ fi
2121

2222
# Get the User OCID
2323
while ! state_done USER_OCID; do
24-
read -p "Please enter your OCI user's OCID: " USER_OCID
24+
if test -z "$TEST_USER_OCID"; then
25+
read -p "Please enter your OCI user's OCID: " USER_OCID
26+
else
27+
USER_OCID=$TEST_USER_OCID
28+
fi
2529
# Validate
2630
if test ""`oci iam user get --user-id "$USER_OCID" --query 'data."lifecycle-state"' --raw-output 2>$GRABDISH_LOG/user_ocid_err` == 'ACTIVE'; then
2731
state_set USER_OCID "$USER_OCID"
@@ -47,7 +51,7 @@ while ! state_done RUN_TYPE; do
4751
state_set RESERVATION_ID `grep -oP '(?<=LL).*?(?=-USER)' <<<"$(state_get USER_NAME)"`
4852
state_set_done PROVISIONING
4953
state_set RUN_NAME "grabdish$(state_get RESERVATION_ID)"
50-
state_set ORDER_DB_NAME "ORDERDB$(state_get RESERVATION_ID)"
54+
state_set ORDER_DB_NAME "ORDER$(state_get RESERVATION_ID)"
5155
state_set INVENTORY_DB_NAME "INVENTORY$(state_get RESERVATION_ID)"
5256
state_set_done OKE_LIMIT_CHECK
5357
state_set_done ATP_LIMIT_CHECK
@@ -57,46 +61,6 @@ while ! state_done RUN_TYPE; do
5761
done
5862

5963

60-
# Check OKE Limits
61-
if ! state_done OKE_LIMIT_CHECK; then
62-
# Cluster Service Limit
63-
OKE_LIMIT=`oci limits value list --compartment-id "$OCI_TENANCY" --service-name "container-engine" --query 'sum(data[?"name"=='"'cluster-count'"'].value)'`
64-
if test "$OKE_LIMIT" -lt 1; then
65-
echo 'The service limit for the "Container Engine" "Cluster Count" is insufficent to run this workshop. At least 1 is required.'
66-
exit
67-
elif test "$OKE_LIMIT" -eq 1; then
68-
echo 'You are limited to only one OKE cluster in this tenancy. This workshop will create one additional OKE cluster and so any other OKE clusters must be terminated.'
69-
read -p "Please confirm that no other un-terminated OKE clusters exist in this tenancy and then hit [RETURN]? " DUMMY
70-
fi
71-
state_set_done OKE_LIMIT_CHECK
72-
fi
73-
74-
75-
# Check ATP resource availability
76-
while ! state_done ATP_LIMIT_CHECK; do
77-
CHECK=1
78-
# ATP OCPU availability
79-
if test $(oci limits resource-availability get --compartment-id="$OCI_TENANCY" --service-name "database" --limit-name "atp-ocpu-count" --query 'to_string(min([data."fractional-availability",`4.0`]))' --raw-output) != '4.0'; then
80-
echo 'The "Autonomous Transaction Processing OCPU Count" resource availability is insufficent to run this workshop.'
81-
echo '4 OCPUs are required. Terminate some existing ATP databases and try again.'
82-
CHECK=0
83-
fi
84-
85-
# ATP storage availability
86-
if test $(oci limits resource-availability get --compartment-id="$OCI_TENANCY" --service-name "database" --limit-name "atp-total-storage-tb" --query 'to_string(min([data."fractional-availability",`2.0`]))' --raw-output) != '2.0'; then
87-
echo 'The "Autonomous Transaction Processing Total Storage (TB)" resource availability is insufficent to run this workshop.'
88-
echo '2 TB are required. Terminate some existing ATP databases and try again.'
89-
CHECK=0
90-
fi
91-
92-
if test $CHECK -eq 1; then
93-
state_set_done ATP_LIMIT_CHECK
94-
else
95-
read -p "Hit [RETURN] when you are ready to retry? " DUMMY
96-
fi
97-
done
98-
99-
10064
# Get Run Name from directory name
10165
while ! state_done RUN_NAME; do
10266
cd $GRABDISH_HOME
@@ -145,29 +109,14 @@ while ! state_done COMPARTMENT_OCID; do
145109
else
146110
read -p "Please enter your OCI compartments's OCID: " COMPARTMENT_OCID
147111
fi
148-
while ! test `oci iam compartment get --compartment-id "$COMPARTMENT_OCID" --query 'data."lifecycle-state"' --raw-output`"" == 'ACTIVE'; do
112+
while ! test `oci iam compartment get --compartment-id "$COMPARTMENT_OCID" --query 'data."lifecycle-state"' --raw-output`"" == 'ACTIVE' 2>/dev/null; do
149113
echo "Waiting for the compartment to become ACTIVE"
150114
sleep 2
151115
done
152116
state_set COMPARTMENT_OCID "$COMPARTMENT_OCID"
153117
done
154118

155119

156-
# Switch to SSH Key auth for the oci cli (workaround to perm issue awaiting fix)
157-
# source $GRABDISH_HOME/utils/oci-cli-cs-key-auth.sh
158-
159-
160-
# Run the terraform.sh in the background
161-
if ! state_get PROVISIONING; then
162-
if ps -ef | grep "$GRABDISH_HOME/utils/terraform.sh" | grep -v grep; then
163-
echo "$GRABDISH_HOME/utils/terraform.sh is already running"
164-
else
165-
echo "Executing terraform.sh in the background"
166-
nohup $GRABDISH_HOME/utils/terraform.sh &>> $GRABDISH_LOG/terraform.log &
167-
fi
168-
fi
169-
170-
171120
## Run the java-builds.sh in the background
172121
if ! state_get JAVA_BUILDS; then
173122
if ps -ef | grep "$GRABDISH_HOME/utils/java-builds.sh" | grep -v grep; then
@@ -190,6 +139,59 @@ if ! state_get NON_JAVA_BUILDS; then
190139
fi
191140

192141

142+
# Check OKE Limits
143+
if ! state_done OKE_LIMIT_CHECK; then
144+
# Cluster Service Limit
145+
OKE_LIMIT=`oci limits value list --compartment-id "$OCI_TENANCY" --service-name "container-engine" --query 'sum(data[?"name"=='"'cluster-count'"'].value)'`
146+
if test "$OKE_LIMIT" -lt 1; then
147+
echo 'The service limit for the "Container Engine" "Cluster Count" is insufficent to run this workshop. At least 1 is required.'
148+
exit
149+
elif test "$OKE_LIMIT" -eq 1; then
150+
echo 'You are limited to only one OKE cluster in this tenancy. This workshop will create one additional OKE cluster and so any other OKE clusters must be terminated.'
151+
if test -z "$TEST_USER_OCID"; then
152+
read -p "Please confirm that no other un-terminated OKE clusters exist in this tenancy and then hit [RETURN]? " DUMMY
153+
fi
154+
fi
155+
state_set_done OKE_LIMIT_CHECK
156+
fi
157+
158+
159+
# Check ATP resource availability
160+
while ! state_done ATP_LIMIT_CHECK; do
161+
CHECK=1
162+
# ATP OCPU availability
163+
if test $(oci limits resource-availability get --compartment-id="$OCI_TENANCY" --service-name "database" --limit-name "atp-ocpu-count" --query 'to_string(min([data."fractional-availability",`4.0`]))' --raw-output) != '4.0'; then
164+
echo 'The "Autonomous Transaction Processing OCPU Count" resource availability is insufficent to run this workshop.'
165+
echo '4 OCPUs are required. Terminate some existing ATP databases and try again.'
166+
CHECK=0
167+
fi
168+
169+
# ATP storage availability
170+
if test $(oci limits resource-availability get --compartment-id="$OCI_TENANCY" --service-name "database" --limit-name "atp-total-storage-tb" --query 'to_string(min([data."fractional-availability",`2.0`]))' --raw-output) != '2.0'; then
171+
echo 'The "Autonomous Transaction Processing Total Storage (TB)" resource availability is insufficent to run this workshop.'
172+
echo '2 TB are required. Terminate some existing ATP databases and try again.'
173+
CHECK=0
174+
fi
175+
176+
if test $CHECK -eq 1; then
177+
state_set_done ATP_LIMIT_CHECK
178+
else
179+
read -p "Hit [RETURN] when you are ready to retry? " DUMMY
180+
fi
181+
done
182+
183+
184+
## Run the terraform.sh in the background
185+
if ! state_get PROVISIONING; then
186+
if ps -ef | grep "$GRABDISH_HOME/utils/terraform.sh" | grep -v grep; then
187+
echo "$GRABDISH_HOME/utils/terraform.sh is already running"
188+
else
189+
echo "Executing terraform.sh in the background"
190+
nohup $GRABDISH_HOME/utils/terraform.sh &>> $GRABDISH_LOG/terraform.log &
191+
fi
192+
fi
193+
194+
193195
# Get Namespace
194196
while ! state_done NAMESPACE; do
195197
export OCI_CLI_PROFILE=$(state_get HOME_REGION)
@@ -201,32 +203,36 @@ done
201203

202204
# login to docker
203205
while ! state_done DOCKER_REGISTRY; do
204-
export OCI_CLI_PROFILE=$(state_get HOME_REGION)
205-
if ! TOKEN=`oci iam auth-token create --user-id "$(state_get USER_OCID)" --description 'grabdish docker login' --query 'data.token' --raw-output 2>$GRABDISH_LOG/docker_registry_err`; then
206-
if grep UserCapacityExceeded $GRABDISH_LOG/docker_registry_err >/dev/null; then
207-
# The key already exists
208-
echo 'ERROR: Failed to create auth token. Please delete an old token from the OCI Console (Profile -> User Settings -> Auth Tokens).'
209-
read -p "Hit return when you are ready to retry?"
210-
else
211-
echo "ERROR: Creating auth token had failed:"
212-
cat $GRABDISH_LOG/docker_registry_err
213-
exit
214-
fi
215-
else
216-
sleep 5 # Allow time for the auth token to come into effect
217-
RETRIES=0
218-
while test $RETRIES -le 10; do
219-
if echo "$TOKEN" | docker login -u "$(state_get NAMESPACE)/$(state_get USER_NAME)" --password-stdin "$(state_get REGION).ocir.io"; then
220-
state_set DOCKER_REGISTRY "$(state_get REGION).ocir.io/$(state_get NAMESPACE)/$(state_get RUN_NAME)"
221-
break
206+
if test $(state_get RUN_TYPE) -ne 3; then
207+
export OCI_CLI_PROFILE=$(state_get HOME_REGION)
208+
if ! TOKEN=`oci iam auth-token create --user-id "$(state_get USER_OCID)" --description 'grabdish docker login' --query 'data.token' --raw-output 2>$GRABDISH_LOG/docker_registry_err`; then
209+
if grep UserCapacityExceeded $GRABDISH_LOG/docker_registry_err >/dev/null; then
210+
# The key already exists
211+
echo 'ERROR: Failed to create auth token. Please delete an old token from the OCI Console (Profile -> User Settings -> Auth Tokens).'
212+
read -p "Hit return when you are ready to retry?"
213+
continue
222214
else
223-
echo "Docker login failed. Retrying"
224-
RETRIES=$((RETRIES+1))
225-
sleep 5
215+
echo "ERROR: Creating auth token had failed:"
216+
cat $GRABDISH_LOG/docker_registry_err
217+
exit
226218
fi
227-
done
219+
fi
220+
else
221+
read -p "Please generate an Auth Token and enter the value: " TOKEN
228222
fi
229-
export OCI_CLI_PROFILE=$(state_get REGION)
223+
224+
RETRIES=0
225+
while test $RETRIES -le 30; do
226+
if echo "$TOKEN" | docker login -u "$(state_get NAMESPACE)/$(state_get USER_NAME)" --password-stdin "$(state_get REGION).ocir.io" &>/dev/null; then
227+
state_set DOCKER_REGISTRY "$(state_get REGION).ocir.io/$(state_get NAMESPACE)/$(state_get RUN_NAME)"
228+
export OCI_CLI_PROFILE=$(state_get REGION)
229+
break
230+
else
231+
# echo "Docker login failed. Retrying"
232+
RETRIES=$((RETRIES+1))
233+
sleep 5
234+
fi
235+
done
230236
done
231237

232238

@@ -261,8 +267,12 @@ if ! state_done DB_PASSWORD; then
261267
echo
262268

263269
while true; do
264-
read -s -r -p "Enter the password to be used for the order and inventory databases: " PW
265-
if [[ ${#PW} -ge 12 && ${#PW} -le 30 && "$PW" =~ [A-Z] && "$PW" =~ [a-z] && "$PW" =~ [0-9] && "$PW" != *admin* && "$PW" != *'"'* ]]; then
270+
if test -z "$TEST_DB_PASSWORD"; then
271+
read -s -r -p "Enter the password to be used for the order and inventory databases: " PW
272+
else
273+
PW="$TEST_DB_PASSWORD"
274+
fi
275+
if [[ ${#PW} -ge 12 && ${#PW} -le 30 && "$PW" =~ [A-Z] && "$PW" =~ [a-z] && "$PW" =~ [0-9] && "$PW" != *admin* && "$PW" != *'"'* ]]; then
266276
echo
267277
break
268278
else
@@ -280,8 +290,12 @@ if ! state_done UI_PASSWORD; then
280290
echo
281291

282292
while true; do
283-
read -s -r -p "Enter the password to be used for accessing the UI: " PW
284-
if [[ ${#PW} -ge 8 && ${#PW} -le 30 ]]; then
293+
if test -z "$TEST_UI_PASSWORD"; then
294+
read -s -r -p "Enter the password to be used for accessing the UI: " PW
295+
else
296+
PW="$TEST_UI_PASSWORD"
297+
fi
298+
if [[ ${#PW} -ge 8 && ${#PW} -le 30 ]]; then
285299
echo
286300
break
287301
else
@@ -392,6 +406,13 @@ while ! state_done INVENTORY_DB_PASSWORD_SET; do
392406
done
393407

394408

409+
# Wait for OKE Setup
410+
while ! state_done OKE_SETUP; do
411+
# echo "`date`: Waiting for OKE_SETUP"
412+
sleep 2
413+
done
414+
415+
395416
# Collect UI password and create secret
396417
while ! state_done UI_PASSWORD; do
397418
while true; do
@@ -428,16 +449,17 @@ while ! state_done SETUP_VERIFIED; do
428449
bg_not_done=
429450
for bg in $bgs; do
430451
if state_done $bg; then
431-
echo "$bg completed"
452+
echo "$bg has completed"
432453
else
433-
echo "$bg has not completed"
454+
# echo "$bg is running"
434455
NOT_DONE=$((NOT_DONE+1))
435456
bg_not_done="$bg_not_done $bg"
436457
fi
437458
done
438459
if test "$NOT_DONE" -gt 0; then
439-
echo "Log files are located in $GRABDISH_LOG"
460+
# echo "Log files are located in $GRABDISH_LOG"
440461
bgs=$bg_not_done
462+
echo -ne r"\033[2K\r$bgs still running "
441463
sleep 10
442464
else
443465
state_set_done SETUP_VERIFIED

0 commit comments

Comments
 (0)