-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-stack.yaml
75 lines (73 loc) · 2.36 KB
/
docker-stack.yaml
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
version: '3.7'
services:
redis-cluster:
image: redis:5.0.1-alpine
volumes:
- redis-data:/data
entrypoint:
- /bin/sh
- -c
- |
redis_master_init=$$(nslookup tasks.redis-master-init 127.0.0.11 | tail -n +5 | awk '{print $$3}')
if [ $$redis_master_init ]; then
master_ip=$$redis_master_init
else
until [ "$$(redis-cli -h redis-sentinel -p 26379 ping)" = "PONG" ]; do
echo "redis-sentinel is unavailable - sleeping"
sleep 1
done
master_info=$$(redis-cli -h redis-sentinel -p 26379 sentinel get-master-addr-by-name redis-cluster)
master_ip=$$(echo $$master_info | awk '{print $$1}')
fi
redis-server /etc/redis.conf --slaveof $$master_ip 6379 --appendonly yes
deploy:
mode: global
ports:
- 6379:6379
networks:
- internal
configs:
- source: redis-conf-bootstrap
target: /etc/redis.conf
redis-sentinel:
image: redis:5.0.1-alpine
entrypoint:
- /bin/sh
- -c
- |
cp /tmp/sentinel.conf /etc/sentinel.conf
redis_master_init=$$(nslookup tasks.redis-master-init 127.0.0.11 | tail -n +5 | awk '{print $$3}')
if [ $$redis_master_init ]; then
sed -i "s/{{ MASTER_IP }}/$$redis_master_init/g" /etc/sentinel.conf
else
sentinel_node_list=$$(nslookup tasks.redis-sentinel 127.0.0.11 | tail -n +5 | awk '{print $$3}')
for sentinel_node in $$sentinel_node_list; do
master_info=$$(redis-cli -h $$sentinel_node -p 26379 sentinel get-master-addr-by-name redis-cluster)
if [ "$$master_info" ]; then
master_ip=$$(echo $$master_info | awk '{print $$1}')
sed -i "s/{{ MASTER_IP }}/$$master_ip/g" /etc/sentinel.conf
break
fi
done
fi
redis-server /etc/sentinel.conf --sentinel
deploy:
mode: global
ports:
- 26379:26379
networks:
- internal
configs:
- source: sentinel-conf
target: /tmp/sentinel.conf
configs:
redis-conf-bootstrap:
file: redis-bootstrap.conf
sentinel-conf:
file: sentinel.conf
networks:
internal:
external: true
volumes:
redis-data:
external: true