Skip to content

Commit c480c01

Browse files
author
Vaughn Dice
authored
Merge pull request #191 from vdice/fix-contrib-ci-scripts
fix(contrib/ci/*): fix scripts
2 parents 8279219 + f36f1e9 commit c480c01

File tree

4 files changed

+88
-74
lines changed

4 files changed

+88
-74
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ IMAGE_PREFIX ?= deis
88

99
include versioning.mk
1010

11-
SHELL_SCRIPTS = $(wildcard _scripts/*.sh) rootfs/bin/backup rootfs/bin/is_running
11+
SHELL_SCRIPTS = $(wildcard _scripts/*.sh contrib/ci/*.sh rootfs/bin/*backup) rootfs/bin/is_running
1212

1313
# The following variables describe the containerized development environment
1414
# and other build options

contrib/ci/test-minio.sh

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,86 @@
22

33
set -eof pipefail
44

5-
TEST_ROOT=$(dirname "${BASH_SOURCE}")/
5+
cleanup() {
6+
kill-containers "${MINIO_JOB}" "${PG_JOB}"
7+
}
8+
trap cleanup EXIT
9+
10+
TEST_ROOT=$(dirname "${BASH_SOURCE[0]}")/
11+
# shellcheck source=/dev/null
612
source "${TEST_ROOT}/test.sh"
713

814
# make sure we are in this dir
9-
CURRENT_DIR=$(cd $(dirname $0); pwd)
15+
CURRENT_DIR=$(cd "$(dirname "$0")"; pwd)
1016

1117
create-postgres-creds
1218

1319
puts-step "creating fake minio credentials"
1420

1521
# create fake AWS credentials for minio admin credentials
16-
mkdir -p $CURRENT_DIR/tmp/aws-admin
22+
mkdir -p "${CURRENT_DIR}"/tmp/aws-admin
1723
# needs to be 20 characters long
18-
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-admin/access-key-id
24+
echo "12345678901234567890" > "${CURRENT_DIR}"/tmp/aws-admin/access-key-id
1925
# needs to be 40 characters long
20-
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-admin/access-secret-key
26+
echo "1234567890123456789012345678901234567890" > "${CURRENT_DIR}"/tmp/aws-admin/access-secret-key
2127

2228
# create fake AWS credentials for minio user credentials
23-
mkdir -p $CURRENT_DIR/tmp/aws-user
29+
mkdir -p "${CURRENT_DIR}"/tmp/aws-user
2430
# needs to be 20 characters long
25-
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-user/accesskey
26-
echo "12345678901234567890" > $CURRENT_DIR/tmp/aws-user/access-key-id
31+
echo "12345678901234567890" > "${CURRENT_DIR}"/tmp/aws-user/accesskey
32+
echo "12345678901234567890" > "${CURRENT_DIR}"/tmp/aws-user/access-key-id
2733
# needs to be 40 characters long
28-
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-user/secretkey
29-
echo "1234567890123456789012345678901234567890" > $CURRENT_DIR/tmp/aws-user/access-secret-key
34+
echo "1234567890123456789012345678901234567890" > "${CURRENT_DIR}"/tmp/aws-user/secretkey
35+
echo "1234567890123456789012345678901234567890" > "${CURRENT_DIR}"/tmp/aws-user/access-secret-key
3036

3137
puts-step "creating fake kubernetes service account token"
3238

3339
# create fake k8s serviceaccount token for minio to "discover" itself
34-
mkdir -p $CURRENT_DIR/tmp/k8s
35-
echo "token" > $CURRENT_DIR/tmp/k8s/token
36-
echo "cert" > $CURRENT_DIR/tmp/k8s/ca.crt
40+
mkdir -p "${CURRENT_DIR}"/tmp/k8s
41+
echo "token" > "${CURRENT_DIR}"/tmp/k8s/token
42+
echo "cert" > "${CURRENT_DIR}"/tmp/k8s/ca.crt
3743

38-
# kill containers when this script exits or errors out
39-
trap 'kill-container $MINIO_JOB' INT TERM
4044
# boot minio
41-
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/)
45+
MINIO_JOB=$(docker run -d \
46+
-v "${CURRENT_DIR}"/tmp/aws-admin:/var/run/secrets/deis/minio/admin \
47+
-v "${CURRENT_DIR}"/tmp/aws-user:/var/run/secrets/deis/minio/user \
48+
-v "${CURRENT_DIR}"/tmp/k8s:/var/run/secrets/kubernetes.io/serviceaccount \
49+
quay.io/deisci/minio:canary boot server /home/minio/)
4250

4351
# boot postgres, linking the minio container and setting DEIS_MINIO_SERVICE_HOST and DEIS_MINIO_SERVICE_PORT
44-
PG_CMD="docker run -d --link $MINIO_JOB:minio -e PGCTLTIMEOUT=1200 -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"
52+
PG_CMD="docker run -d --link ${MINIO_JOB}:minio -e PGCTLTIMEOUT=1200 \
53+
-e BACKUP_FREQUENCY=1s -e DATABASE_STORAGE=minio \
54+
-e DEIS_MINIO_SERVICE_HOST=minio -e DEIS_MINIO_SERVICE_PORT=9000 \
55+
-v ${CURRENT_DIR}/tmp/creds:/var/run/secrets/deis/database/creds \
56+
-v ${CURRENT_DIR}/tmp/aws-user:/var/run/secrets/deis/objectstore/creds $1"
4557

46-
# kill containers when this script exits or errors out
47-
trap 'kill-container $PG_JOB' INT TERM
48-
start-postgres "$PG_CMD"
58+
start-postgres "${PG_CMD}"
4959

5060
# display logs for debugging purposes
5161
puts-step "displaying minio logs"
52-
docker logs $MINIO_JOB
62+
docker logs "${MINIO_JOB}"
5363

54-
check-postgres $PG_JOB
64+
check-postgres "${PG_JOB}"
5565

5666
# check if minio has the 5 backups
5767
puts-step "checking if minio has 5 backups"
58-
BACKUPS="$(docker exec $MINIO_JOB ls /home/minio/dbwal/basebackups_005/ | grep json)"
59-
NUM_BACKUPS="$(docker exec $MINIO_JOB ls /home/minio/dbwal/basebackups_005/ | grep -c json)"
68+
BACKUPS="$(docker exec "${MINIO_JOB}" ls /home/minio/dbwal/basebackups_005/ | grep json)"
69+
NUM_BACKUPS="$(echo "${BACKUPS}" | wc -w)"
6070
# NOTE (bacongobbler): the BACKUP_FREQUENCY is only 1 second, so we could technically be checking
6171
# in the middle of a backup. Instead of failing, let's consider N+1 backups an acceptable case
62-
if [[ ! "$NUM_BACKUPS" -eq "5" && ! "$NUM_BACKUPS" -eq "6" ]]; then
72+
if [[ ! "${NUM_BACKUPS}" -eq "5" && ! "${NUM_BACKUPS}" -eq "6" ]]; then
6373
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)"
64-
puts-error "$BACKUPS"
74+
puts-error "${BACKUPS}"
6575
exit 1
6676
fi
6777

6878
# kill off postgres, then reboot and see if it's running after recovering from backups
6979
puts-step "shutting off postgres, then rebooting to test data recovery"
70-
kill-container $PG_JOB
80+
kill-containers "${PG_JOB}"
81+
82+
start-postgres "${PG_CMD}"
7183

72-
start-postgres "$PG_CMD"
84+
check-postgres "${PG_JOB}"
7385

74-
check-postgres $PG_JOB
86+
puts-step "tests PASSED!"
87+
exit 0

contrib/ci/test-swift.sh

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,77 @@
22

33
set -eof pipefail
44

5-
TEST_ROOT=$(dirname "${BASH_SOURCE}")/
5+
cleanup() {
6+
kill-containers "${SWIFT_DATA}" "${SWIFT_JOB}" "${PG_JOB}"
7+
}
8+
trap cleanup EXIT
9+
10+
TEST_ROOT=$(dirname "${BASH_SOURCE[0]}")/
11+
# shellcheck source=/dev/null
612
source "${TEST_ROOT}/test.sh"
713

814
# make sure we are in this dir
9-
CURRENT_DIR=$(cd $(dirname $0); pwd)
15+
CURRENT_DIR=$(cd "$(dirname "$0")"; pwd)
1016

1117
create-postgres-creds
1218

1319
puts-step "fetching openstack credentials"
1420

1521
# turn creds into something that we can use.
16-
mkdir -p $CURRENT_DIR/tmp/swift
22+
mkdir -p "${CURRENT_DIR}"/tmp/swift
1723

1824
# guess which value to use for tenant:
1925
TENANT=""
2026

21-
echo "test:tester" > $CURRENT_DIR/tmp/swift/username
22-
echo "testing" > $CURRENT_DIR/tmp/swift/password
23-
echo ${TENANT} > $CURRENT_DIR/tmp/swift/tenant
24-
echo "http://swift:8080/auth/v1.0" > $CURRENT_DIR/tmp/swift/authurl
25-
echo "1" > $CURRENT_DIR/tmp/swift/authversion
26-
echo "deis-swift-test" > $CURRENT_DIR/tmp/swift/database-container
27+
echo "test:tester" > "${CURRENT_DIR}"/tmp/swift/username
28+
echo "testing" > "${CURRENT_DIR}"/tmp/swift/password
29+
echo "${TENANT}" > "${CURRENT_DIR}"/tmp/swift/tenant
30+
echo "http://swift:8080/auth/v1.0" > "${CURRENT_DIR}"/tmp/swift/authurl
31+
echo "1" > "${CURRENT_DIR}"/tmp/swift/authversion
32+
echo "deis-swift-test" > "${CURRENT_DIR}"/tmp/swift/database-container
2733

28-
# kill containers when this script exits or errors out
29-
trap 'kill-container $SWIFT_DATA' INT TERM
3034
# boot swift
31-
SWIFT_DATA=$(docker run -v /srv --name SWIFT_DATA busybox)
32-
33-
# kill containers when this script exits or errors out
34-
trap 'kill-container $SWIFT_JOB' INT TERM
35-
SWIFT_JOB=$(docker run --name onlyone --hostname onlyone -d --volumes-from SWIFT_DATA -t deis/swift-onlyone:git-8516d23)
35+
SWIFT_DATA=$(docker run -d -v /srv --name SWIFT_DATA busybox)
3636

37+
SWIFT_JOB=$(docker run -d --name onlyone --hostname onlyone --volumes-from SWIFT_DATA -t deis/swift-onlyone:git-8516d23)
3738

3839
# postgres container command
39-
PG_CMD="docker run -d --link $SWIFT_JOB:swift -e BACKUP_FREQUENCY=3s \
40-
-e DATABASE_STORAGE=swift \
41-
-e PGCTLTIMEOUT=1200 \
42-
-v $CURRENT_DIR/tmp/creds:/var/run/secrets/deis/database/creds \
43-
-v $CURRENT_DIR/tmp/swift:/var/run/secrets/deis/objectstore/creds \
44-
$1"
45-
46-
# kill containers when this script exits or errors out
47-
trap 'kill-container $PG_JOB' INT TERM
40+
PG_CMD="docker run -d --link ${SWIFT_JOB}:swift -e BACKUP_FREQUENCY=3s \
41+
-e DATABASE_STORAGE=swift \
42+
-e PGCTLTIMEOUT=1200 \
43+
-v ${CURRENT_DIR}/tmp/creds:/var/run/secrets/deis/database/creds \
44+
-v ${CURRENT_DIR}/tmp/swift:/var/run/secrets/deis/objectstore/creds \
45+
$1"
46+
4847
start-postgres "$PG_CMD"
4948

5049
# display logs for debugging purposes
5150
puts-step "displaying swift logs"
52-
docker logs $SWIFT_JOB
51+
docker logs "${SWIFT_JOB}"
5352

54-
check-postgres $PG_JOB
53+
check-postgres "${PG_JOB}"
5554

5655
# check if swift has some backups ... 3 ?
5756
puts-step "checking if swift has at least 3 backups"
5857

59-
BACKUPS="$(docker exec $SWIFT_JOB swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list deis-swift-test | grep basebackups_005 | grep json)"
60-
NUM_BACKUPS="$(docker exec $SWIFT_JOB swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list deis-swift-test | grep basebackups_005 | grep -c json)"
58+
BACKUPS="$(docker exec "${SWIFT_JOB}" swift -A http://127.0.0.1:8080/auth/v1.0 \
59+
-U test:tester -K testing list deis-swift-test | grep basebackups_005 | grep json)"
60+
NUM_BACKUPS="$(echo "${BACKUPS}" | wc -w)"
6161
# NOTE (bacongobbler): the BACKUP_FREQUENCY is only 1 second, so we could technically be checking
6262
# in the middle of a backup. Instead of failing, let's consider N+1 backups an acceptable case
63-
if [[ ! "$NUM_BACKUPS" -eq "5" && ! "$NUM_BACKUPS" -eq "6" ]]; then
63+
if [[ ! "${NUM_BACKUPS}" -eq "5" && ! "${NUM_BACKUPS}" -eq "6" ]]; then
6464
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)"
65-
puts-error "$BACKUPS"
65+
puts-error "${BACKUPS}"
6666
exit 1
6767
fi
6868

6969
# kill off postgres, then reboot and see if it's running after recovering from backups
7070
puts-step "shutting off postgres, then rebooting to test data recovery"
71-
kill-container $PG_JOB
71+
kill-containers "${PG_JOB}"
7272

73-
start-postgres "$PG_CMD"
73+
start-postgres "${PG_CMD}"
7474

75-
check-postgres $PG_JOB
75+
check-postgres "${PG_JOB}"
7676

7777
puts-step "tests PASSED!"
7878
exit 0

contrib/ci/test.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,29 @@
33
set -eof pipefail
44

55
puts-step() {
6-
echo "-----> $@"
6+
echo "-----> $*"
77
}
88

99
puts-error() {
10-
echo "!!! $@"
10+
echo "!!! $*"
1111
}
1212

13-
kill-container() {
14-
puts-step "destroying container $1"
15-
docker rm -f "$1"
13+
kill-containers() {
14+
puts-step "destroying containers $*"
15+
docker rm -f "$@"
1616
}
1717

1818
create-postgres-creds() {
1919
puts-step "creating fake postgres credentials"
2020

2121
# 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
22+
mkdir -p "${CURRENT_DIR}"/tmp/creds
23+
echo "testuser" > "${CURRENT_DIR}"/tmp/creds/user
24+
echo "icanttellyou" > "${CURRENT_DIR}"/tmp/creds/password
2525
}
2626

2727
start-postgres() {
28+
export PG_JOB
2829
PG_JOB=$($1)
2930
# wait for postgres to boot
3031
puts-step "sleeping for 90s while postgres is booting..."
@@ -34,9 +35,9 @@ start-postgres() {
3435
check-postgres() {
3536
# display logs for debugging purposes
3637
puts-step "displaying postgres logs"
37-
docker logs $1
38+
docker logs "$1"
3839

3940
# check if postgres is running
4041
puts-step "checking if postgres is running"
41-
docker exec $1 is_running
42+
docker exec "$1" is_running
4243
}

0 commit comments

Comments
 (0)