Skip to content

Commit

Permalink
Use Redis Sentinel in development
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Mar 15, 2021
1 parent 93e74fc commit f948356
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .dockerdev/redis-sentinel/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

cp /redis/sentinel.conf.template /etc/sentinel.conf

sed -i "s/\$SENTINEL_MASTER/$SENTINEL_MASTER/g" /etc/sentinel.conf
sed -i "s/\$SENTINEL_QUORUM/$SENTINEL_QUORUM/g" /etc/sentinel.conf
sed -i "s/\$SENTINEL_DOWN_AFTER/$SENTINEL_DOWN_AFTER/g" /etc/sentinel.conf
sed -i "s/\$SENTINEL_FAILOVER/$SENTINEL_FAILOVER/g" /etc/sentinel.conf

redis-server /etc/sentinel.conf --sentinel
10 changes: 10 additions & 0 deletions .dockerdev/redis-sentinel/sentinel.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
port 26379

dir /tmp

requirepass "any_secret"

sentinel monitor $SENTINEL_MASTER redis 6379 $SENTINEL_QUORUM
sentinel down-after-milliseconds $SENTINEL_MASTER $SENTINEL_DOWN_AFTER
sentinel parallel-syncs $SENTINEL_MASTER 1
sentinel failover-timeout $SENTINEL_MASTER $SENTINEL_FAILOVER
37 changes: 36 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ x-backend: &backend
environment: &backend_environment
<<: *env
REDIS_URL: redis://redis:6379/
ANYCABLE_REDIS_SENTINELS: :any_secret@redis-sentinel:26379
DATABASE_URL: postgres://postgres:postgres@postgres:5432
CHROME_URL: http://chrome:3333
BOOTSNAP_CACHE_DIR: /usr/local/bundle/_bootsnap
Expand Down Expand Up @@ -66,6 +67,8 @@ services:
<<: *backend_environment
APP_HOST: anycable.test
ANYCABLE_RPC_HOST: 0.0.0.0:50051
# Do not use sentinels in tests
ANYCABLE_REDIS_SENTINELS: ""
CABLE_URL: "ws://ws.anycable.test:8080/cable"
depends_on:
<<: *backend_depends_on
Expand All @@ -83,12 +86,16 @@ services:
command: bundle exec sidekiq -C config/sidekiq.yml

ws: &ws
image: anycable/anycable-go:1.0
image: anycable/anycable-go:edge
ports:
- '8080:8080'
volumes:
- ./bin/:/usr/local/bin
environment: &ws_environment
ANYCABLE_HOST: "0.0.0.0"
ANYCABLE_REDIS_URL: redis://redis:6379/0
ANYCABLE_REDIS_SENTINELS: :any_secret@redis-sentinel:26379
ANYCABLE_REDIS_SENTINEL_DISCOVERY_INTERVAL: 2
ANYCABLE_RPC_HOST: anycable:50051
ANYCABLE_DEBUG: 1
depends_on:
Expand Down Expand Up @@ -149,6 +156,34 @@ services:
timeout: 3s
retries: 30

redis-slave:
image: redis:5.0-alpine
command: redis-server --slaveof redis 6379
depends_on:
redis:
condition: service_healthy
volumes:
- redis:/data

redis-sentinel:
image: redis:5.0-alpine
volumes:
- ./.dockerdev/redis-sentinel:/redis
working_dir: /redis
entrypoint: ./entrypoint.sh
environment:
SENTINEL_QUORUM: 2
SENTINEL_DOWN_AFTER: 1000
SENTINEL_FAILOVER: 1000
SENTINEL_MASTER: redis
ports:
- 26379
depends_on:
redis:
condition: service_started
redis-slave:
condition: service_started

webpacker:
<<: *app
command: bundle exec ./bin/webpack-dev-server
Expand Down

0 comments on commit f948356

Please sign in to comment.