This repository was archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbootstrap
executable file
·77 lines (67 loc) · 2.15 KB
/
bootstrap
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
#!/bin/sh
#
# NAME
# bootstrap -- initialize the test container environment
#
# SYNOPSIS
# bootstrap
#
DOCKER_IP=${DOCKER_IP:-$1}
if [ -z "${DOCKER_IP}" ]
then
if test -e /var/run/docker.sock
then
DOCKER_IP=127.0.0.1
fi
fi
test -d build || mkdir build
COMPOSE_ARGS="-p tredis"
get_exposed_port() { # SERVICE PUBLIC-PORT [INDEX [PROTOCOL]]
if test -n "$3"
then
index="--index=$3"
fi
if test -n "$4"
then
proto="--protocol=$4"
fi
port=$(docker-compose $COMPOSE_ARGS port $index $proto $1 $2 | cut -d: -f2)
if test -z "$port"
then
exit 1
fi
echo $port
}
docker-compose ${COMPOSE_ARGS} stop
docker-compose ${COMPOSE_ARGS} rm --force
docker-compose ${COMPOSE_ARGS} up -d redis
docker-compose ${COMPOSE_ARGS} scale redis=2
REDIS1=$(docker inspect --format '{{ .NetworkSettings.Networks.tredis_default.IPAddress }}' tredis_redis_1)
REDIS2=$(docker inspect --format '{{ .NetworkSettings.Networks.tredis_default.IPAddress }}' tredis_redis_2)
echo "Making REDIS2 a slave of REDIS1: "
COMMAND="redis-cli SLAVEOF ${REDIS1} 6379"
docker exec -t -i tredis_redis_2 ${COMMAND}
docker-compose ${COMPOSE_ARGS} up -d node1 node2 node3
NODE1=$(docker inspect --format '{{ .NetworkSettings.Networks.tredis_default.IPAddress }}' tredis_node1_1)
NODE2=$(docker inspect --format '{{ .NetworkSettings.Networks.tredis_default.IPAddress }}' tredis_node2_1)
NODE3=$(docker inspect --format '{{ .NetworkSettings.Networks.tredis_default.IPAddress }}' tredis_node3_1)
# Create a cluster
echo "Creating a redis cluster with 3 nodes"
COMMAND="create --replicas 0 ${NODE1}:6700 ${NODE2}:6701 ${NODE3}:6702"
docker run --network tredis_default --rm -t -i gavinmroy/redis-trib:latest ${COMMAND}
cat > build/test-environment <<EOF
export DOCKER_IP=${DOCKER_IP}
export REDIS_HOST=${DOCKER_IP}
export REDIS_PORT=6379
export REDIS1_IP=${REDIS1}
export REDIS1_PORT=$(get_exposed_port redis 6379 1)
export REDIS2_IP=${REDIS2}
export REDIS2_PORT=$(get_exposed_port redis 6379 2)
export NODE1_IP=${NODE1}
export NODE1_PORT=6700
export NODE2_IP=${NODE2}
export NODE2_PORT=6701
export NODE3_IP=${NODE3}
export NODE3_PORT=6702
EOF
echo "\nDon't forget to 'source build/test-environment'"