diff --git a/.env.example b/.env.example index c0d71b4..005c690 100644 --- a/.env.example +++ b/.env.example @@ -2,3 +2,7 @@ UPTIME_DATABASE_URL=postgres://uptime:uptime@localhost:5432/uptime?sslmode=disab UPTIME_REDIS_URL=redis://localhost:6379/0 UPTIME_LOG_FORMAT=text UPTIME_CHECKER_REGION=local + +# Sentinel instead of a single redis (docker compose --profile sentinel up -d) +# UPTIME_REDIS_SENTINEL_MASTER=uptime +# UPTIME_REDIS_SENTINEL_ADDRS=127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381 diff --git a/Makefile b/Makefile index cfe3faf..128135b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none) PKG := git.zb-server.de/ZB-Server/uptimesebi LDFLAGS := -s -w -X $(PKG)/internal/buildinfo.Version=$(VERSION) -X $(PKG)/internal/buildinfo.Commit=$(COMMIT) -.PHONY: generate web build test lint dev-up dev-down migrate image +.PHONY: generate web build test lint dev-up dev-up-sentinel dev-down migrate image generate: sqlc generate @@ -24,8 +24,11 @@ lint: dev-up: docker compose up -d --wait +dev-up-sentinel: + docker compose --profile sentinel up -d --wait + dev-down: - docker compose down + docker compose --profile sentinel down migrate: go run ./cmd/api migrate up diff --git a/compose.yaml b/compose.yaml index 46cdd1c..c1ae869 100644 --- a/compose.yaml +++ b/compose.yaml @@ -22,5 +22,33 @@ services: interval: 2s retries: 30 + # Sentinel topology for HA testing: docker compose --profile sentinel up -d + # Host networking keeps announced addresses reachable from the host. + redis-primary: + image: redis:8-alpine + profiles: [sentinel] + network_mode: host + command: redis-server --port 6380 + + redis-replica: + image: redis:8-alpine + profiles: [sentinel] + network_mode: host + command: redis-server --port 6381 --replicaof 127.0.0.1 6380 + + sentinel-1: &sentinel + image: redis:8-alpine + profiles: [sentinel] + network_mode: host + entrypoint: ["sh", "-c", "cp /cfg/sentinel.conf /tmp/s.conf && exec redis-sentinel /tmp/s.conf --port $$PORT"] + environment: {PORT: "26379"} + volumes: [./deploy/dev/sentinel.conf:/cfg/sentinel.conf:ro] + sentinel-2: + <<: *sentinel + environment: {PORT: "26380"} + sentinel-3: + <<: *sentinel + environment: {PORT: "26381"} + volumes: pgdata: diff --git a/deploy/dev/sentinel.conf b/deploy/dev/sentinel.conf new file mode 100644 index 0000000..68ec77c --- /dev/null +++ b/deploy/dev/sentinel.conf @@ -0,0 +1,5 @@ +port 26379 +sentinel resolve-hostnames yes +sentinel monitor uptime 127.0.0.1 6380 2 +sentinel down-after-milliseconds uptime 3000 +sentinel failover-timeout uptime 10000