Skip to content

Commit 2f7a5fe

Browse files
committed
Use Redis Sentinel in development
1 parent 7bad973 commit 2f7a5fe

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
cp /redis/sentinel.conf.template /etc/sentinel.conf
4+
5+
sed -i "s/\$SENTINEL_MASTER/$SENTINEL_MASTER/g" /etc/sentinel.conf
6+
sed -i "s/\$SENTINEL_QUORUM/$SENTINEL_QUORUM/g" /etc/sentinel.conf
7+
sed -i "s/\$SENTINEL_DOWN_AFTER/$SENTINEL_DOWN_AFTER/g" /etc/sentinel.conf
8+
sed -i "s/\$SENTINEL_FAILOVER/$SENTINEL_FAILOVER/g" /etc/sentinel.conf
9+
10+
redis-server /etc/sentinel.conf --sentinel
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
port 26379
2+
3+
dir /tmp
4+
5+
requirepass "any_secret"
6+
7+
sentinel monitor $SENTINEL_MASTER redis 6379 $SENTINEL_QUORUM
8+
sentinel down-after-milliseconds $SENTINEL_MASTER $SENTINEL_DOWN_AFTER
9+
sentinel parallel-syncs $SENTINEL_MASTER 1
10+
sentinel failover-timeout $SENTINEL_MASTER $SENTINEL_FAILOVER

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
GIT
2+
remote: https://github.com/anycable/anycable.git
3+
revision: 8d38b181928536154083f2f529d8821fc18cd5c0
4+
specs:
5+
anycable (1.0.0)
6+
anyway_config (>= 1.4.2)
7+
grpc (~> 1.17)
8+
19
GEM
210
remote: https://rubygems.org/
311
specs:

docker-compose.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ x-backend: &backend
3434
environment: &backend_environment
3535
<<: *env
3636
REDIS_URL: redis://redis:6379/
37+
ANYCABLE_REDIS_SENTINELS: :any_secret@redis-sentinel:26379
3738
DATABASE_URL: postgres://postgres:postgres@postgres:5432
3839
CHROME_URL: http://chrome:3333
3940
BOOTSNAP_CACHE_DIR: /usr/local/bundle/_bootsnap
@@ -66,6 +67,8 @@ services:
6667
<<: *backend_environment
6768
APP_HOST: anycable.test
6869
ANYCABLE_RPC_HOST: 0.0.0.0:50051
70+
# Do not use sentinels in tests
71+
ANYCABLE_REDIS_SENTINELS: ""
6972
CABLE_URL: "ws://ws.anycable.test:8080/cable"
7073
depends_on:
7174
<<: *backend_depends_on
@@ -83,12 +86,16 @@ services:
8386
command: bundle exec sidekiq -C config/sidekiq.yml
8487

8588
ws: &ws
86-
image: anycable/anycable-go:1.0
89+
image: anycable/anycable-go:edge
8790
ports:
8891
- '8080:8080'
92+
volumes:
93+
- ./bin/:/usr/local/bin
8994
environment: &ws_environment
9095
ANYCABLE_HOST: "0.0.0.0"
9196
ANYCABLE_REDIS_URL: redis://redis:6379/0
97+
ANYCABLE_REDIS_SENTINELS: :any_secret@redis-sentinel:26379
98+
ANYCABLE_REDIS_SENTINEL_DISCOVERY_INTERVAL: 2
9299
ANYCABLE_RPC_HOST: anycable:50051
93100
ANYCABLE_DEBUG: 1
94101
depends_on:
@@ -148,6 +155,34 @@ services:
148155
timeout: 3s
149156
retries: 30
150157

158+
redis-slave:
159+
image: redis:5.0-alpine
160+
command: redis-server --slaveof redis 6379
161+
depends_on:
162+
redis:
163+
condition: service_healthy
164+
volumes:
165+
- redis:/data
166+
167+
redis-sentinel:
168+
image: redis:5.0-alpine
169+
volumes:
170+
- ./.dockerdev/redis-sentinel:/redis
171+
working_dir: /redis
172+
entrypoint: ./entrypoint.sh
173+
environment:
174+
SENTINEL_QUORUM: 2
175+
SENTINEL_DOWN_AFTER: 1000
176+
SENTINEL_FAILOVER: 1000
177+
SENTINEL_MASTER: redis
178+
ports:
179+
- 26379
180+
depends_on:
181+
redis:
182+
condition: service_started
183+
redis-slave:
184+
condition: service_started
185+
151186
webpacker:
152187
<<: *app
153188
command: ./bin/webpack-dev-server

0 commit comments

Comments
 (0)