@@ -10,93 +10,33 @@ puts-error() {
1010 echo " !!! $@ "
1111}
1212
13- kill-containers () {
14- puts-step " destroying containers "
15- docker rm -f " $MINIO_JOB " " $PG_JOB "
13+ kill-container () {
14+ puts-step " destroying container $1 "
15+ docker rm -f " $1 "
1616}
1717
18- # make sure we are in this dir
19- CURRENT_DIR= $( cd $( dirname $0 ) ; pwd )
18+ create-postgres-creds () {
19+ puts-step " creating fake postgres credentials "
2020
21- puts-step " creating fake postgres credentials"
22-
23- # create fake postgres credentials
24- mkdir -p $CURRENT_DIR /tmp/creds
25- echo " testuser" > $CURRENT_DIR /tmp/creds/user
26- echo " icanttellyou" > $CURRENT_DIR /tmp/creds/password
27-
28- puts-step " creating fake minio credentials"
29-
30- # create fake AWS credentials for minio admin credentials
31- mkdir -p $CURRENT_DIR /tmp/aws-admin
32- # needs to be 20 characters long
33- echo " 12345678901234567890" > $CURRENT_DIR /tmp/aws-admin/access-key-id
34- # needs to be 40 characters long
35- echo " 1234567890123456789012345678901234567890" > $CURRENT_DIR /tmp/aws-admin/access-secret-key
36-
37- # create fake AWS credentials for minio user credentials
38- mkdir -p $CURRENT_DIR /tmp/aws-user
39- # needs to be 20 characters long
40- echo " 12345678901234567890" > $CURRENT_DIR /tmp/aws-user/accesskey
41- echo " 12345678901234567890" > $CURRENT_DIR /tmp/aws-user/access-key-id
42- # needs to be 40 characters long
43- echo " 1234567890123456789012345678901234567890" > $CURRENT_DIR /tmp/aws-user/secretkey
44- echo " 1234567890123456789012345678901234567890" > $CURRENT_DIR /tmp/aws-user/access-secret-key
45-
46- puts-step " creating fake kubernetes service account token"
47-
48- # create fake k8s serviceaccount token for minio to "discover" itself
49- mkdir -p $CURRENT_DIR /tmp/k8s
50- echo " token" > $CURRENT_DIR /tmp/k8s/token
51- echo " cert" > $CURRENT_DIR /tmp/k8s/ca.crt
52-
53- # boot minio
54- MINIO_JOB=$( docker run -dv $CURRENT_DIR /tmp/aws-admin:/var/run/secrets/deis/minio/admin -v $CURRENT_DIR /tmp/aws-user:/var/run/secrets/deis/minio/user -v $CURRENT_DIR /tmp/k8s:/var/run/secrets/kubernetes.io/serviceaccount quay.io/deisci/minio:canary boot server /home/minio/)
55-
56- # boot postgres, linking the minio container and setting DEIS_MINIO_SERVICE_HOST and DEIS_MINIO_SERVICE_PORT
57- PG_JOB=$( docker run -d --link $MINIO_JOB :minio -e BACKUP_FREQUENCY=1s -e DATABASE_STORAGE=minio -e DEIS_MINIO_SERVICE_HOST=minio -e DEIS_MINIO_SERVICE_PORT=9000 -v $CURRENT_DIR /tmp/creds:/var/run/secrets/deis/database/creds -v $CURRENT_DIR /tmp/aws-user:/var/run/secrets/deis/objectstore/creds $1 )
58-
59- # kill containers when this script exits or errors out
60- trap kill-containers INT TERM
61-
62- # wait for postgres to boot
63- puts-step " sleeping for 90s while postgres is booting..."
64- sleep 90s
65-
66- # display logs for debugging purposes
67- puts-step " displaying minio logs"
68- docker logs $MINIO_JOB
69- puts-step " displaying postgres logs"
70- docker logs $PG_JOB
71-
72- # check if postgres is running
73- puts-step " checking if postgres is running"
74- docker exec $PG_JOB is_running
75-
76- # check if minio has the 5 backups
77- puts-step " checking if minio has 5 backups"
78- BACKUPS=" $( docker exec $MINIO_JOB ls /home/minio/dbwal/basebackups_005/ | grep json) "
79- NUM_BACKUPS=" $( docker exec $MINIO_JOB ls /home/minio/dbwal/basebackups_005/ | grep -c json) "
80- # NOTE (bacongobbler): the BACKUP_FREQUENCY is only 1 second, so we could technically be checking
81- # in the middle of a backup. Instead of failing, let's consider N+1 backups an acceptable case
82- if [[ ! " $NUM_BACKUPS " -eq " 5" && ! " $NUM_BACKUPS " -eq " 6" ]]; then
83- puts-error " did not find 5 or 6 base backups. 5 is the default, but 6 may exist if a backup is currently in progress (found $NUM_BACKUPS )"
84- puts-error " $BACKUPS "
85- exit 1
86- fi
87-
88- # kill off postgres, then reboot and see if it's running after recovering from backups
89- puts-step " shutting off postgres, then rebooting to test data recovery"
90- docker rm -f $PG_JOB
91- PG_JOB=$( docker run -d --link $MINIO_JOB :minio -e BACKUP_FREQUENCY=1s -e DATABASE_STORAGE=minio -e DEIS_MINIO_SERVICE_HOST=minio -e DEIS_MINIO_SERVICE_PORT=9000 -v $CURRENT_DIR /tmp/creds:/var/run/secrets/deis/database/creds -v $CURRENT_DIR /tmp/aws-user:/var/run/secrets/deis/objectstore/creds $1 )
21+ # create fake postgres credentials
22+ mkdir -p $CURRENT_DIR /tmp/creds
23+ echo " testuser" > $CURRENT_DIR /tmp/creds/user
24+ echo " icanttellyou" > $CURRENT_DIR /tmp/creds/password
25+ }
9226
93- # wait for postgres to boot
94- puts-step " sleeping for 90s while postgres is recovering from backup..."
95- sleep 90s
27+ start-postgres () {
28+ PG_JOB=$( $1 )
29+ # wait for postgres to boot
30+ puts-step " sleeping for 90s while postgres is booting..."
31+ sleep 90s
32+ }
9633
97- puts-step " displaying postgres logs"
98- docker logs $PG_JOB
34+ check-postgres () {
35+ # display logs for debugging purposes
36+ puts-step " displaying postgres logs"
37+ docker logs $1
9938
100- # check if postgres is running
101- puts-step " checking if postgres is running"
102- docker exec $PG_JOB is_running
39+ # check if postgres is running
40+ puts-step " checking if postgres is running"
41+ docker exec $1 is_running
42+ }
0 commit comments