Last active
February 19, 2026 16:49
-
-
Save Gavinok/3eae1edc0f974cb1bab591a8e4917cdd to your computer and use it in GitHub Desktop.
Script to start a redis cluster for testing with vc-authn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Redis Cluster test configuration | |
| # Usage: docker compose -f docker-compose.yaml -f docker-compose-cluster.yaml up | |
| # | |
| # This replaces the single Redis instance with a Redis Cluster setup: | |
| # - 3 master nodes with 3 replica nodes (6 nodes total) | |
| # | |
| # Set these environment variables before starting: | |
| # REDIS_MODE=cluster | |
| # REDIS_HOST=redis-node-1:6379,redis-node-2:6379,redis-node-3:6379 | |
| services: | |
| # Override controller to depend on cluster services instead of single redis | |
| controller: | |
| environment: | |
| - REDIS_MODE=cluster | |
| - REDIS_HOST=redis-node-1:6379,redis-node-2:6379,redis-node-3:6379 | |
| depends_on: | |
| redis-cluster-init: | |
| condition: service_completed_successfully | |
| controller-db: | |
| condition: service_started | |
| # Replace the single redis service with a stub | |
| redis: | |
| image: busybox | |
| command: ["sh", "-c", "while true; do sleep 3600; done"] | |
| restart: "no" | |
| networks: | |
| - vc_auth | |
| healthcheck: | |
| test: ["CMD", "true"] | |
| interval: 1s | |
| timeout: 1s | |
| retries: 1 | |
| # Redis Cluster Node 1 (master) | |
| redis-node-1: | |
| image: redis:8-alpine | |
| command: > | |
| redis-server | |
| --port 6379 | |
| --cluster-enabled yes | |
| --cluster-config-file nodes.conf | |
| --cluster-node-timeout 5000 | |
| --appendonly yes | |
| volumes: | |
| - redis-node-1-data:/data | |
| networks: | |
| - vc_auth | |
| healthcheck: | |
| test: ["CMD", "redis-cli", "ping"] | |
| interval: 5s | |
| timeout: 3s | |
| retries: 3 | |
| # Redis Cluster Node 2 (master) | |
| redis-node-2: | |
| image: redis:8-alpine | |
| command: > | |
| redis-server | |
| --port 6379 | |
| --cluster-enabled yes | |
| --cluster-config-file nodes.conf | |
| --cluster-node-timeout 5000 | |
| --appendonly yes | |
| volumes: | |
| - redis-node-2-data:/data | |
| networks: | |
| - vc_auth | |
| healthcheck: | |
| test: ["CMD", "redis-cli", "ping"] | |
| interval: 5s | |
| timeout: 3s | |
| retries: 3 | |
| # Redis Cluster Node 3 (master) | |
| redis-node-3: | |
| image: redis:8-alpine | |
| command: > | |
| redis-server | |
| --port 6379 | |
| --cluster-enabled yes | |
| --cluster-config-file nodes.conf | |
| --cluster-node-timeout 5000 | |
| --appendonly yes | |
| volumes: | |
| - redis-node-3-data:/data | |
| networks: | |
| - vc_auth | |
| healthcheck: | |
| test: ["CMD", "redis-cli", "ping"] | |
| interval: 5s | |
| timeout: 3s | |
| retries: 3 | |
| # Redis Cluster Node 4 (replica) | |
| redis-node-4: | |
| image: redis:8-alpine | |
| command: > | |
| redis-server | |
| --port 6379 | |
| --cluster-enabled yes | |
| --cluster-config-file nodes.conf | |
| --cluster-node-timeout 5000 | |
| --appendonly yes | |
| volumes: | |
| - redis-node-4-data:/data | |
| networks: | |
| - vc_auth | |
| healthcheck: | |
| test: ["CMD", "redis-cli", "ping"] | |
| interval: 5s | |
| timeout: 3s | |
| retries: 3 | |
| # Redis Cluster Node 5 (replica) | |
| redis-node-5: | |
| image: redis:8-alpine | |
| command: > | |
| redis-server | |
| --port 6379 | |
| --cluster-enabled yes | |
| --cluster-config-file nodes.conf | |
| --cluster-node-timeout 5000 | |
| --appendonly yes | |
| volumes: | |
| - redis-node-5-data:/data | |
| networks: | |
| - vc_auth | |
| healthcheck: | |
| test: ["CMD", "redis-cli", "ping"] | |
| interval: 5s | |
| timeout: 3s | |
| retries: 3 | |
| # Redis Cluster Node 6 (replica) | |
| redis-node-6: | |
| image: redis:8-alpine | |
| command: > | |
| redis-server | |
| --port 6379 | |
| --cluster-enabled yes | |
| --cluster-config-file nodes.conf | |
| --cluster-node-timeout 5000 | |
| --appendonly yes | |
| volumes: | |
| - redis-node-6-data:/data | |
| networks: | |
| - vc_auth | |
| healthcheck: | |
| test: ["CMD", "redis-cli", "ping"] | |
| interval: 5s | |
| timeout: 3s | |
| retries: 3 | |
| # Initialize the cluster (runs once) | |
| redis-cluster-init: | |
| image: redis:8-alpine | |
| depends_on: | |
| redis-node-1: | |
| condition: service_healthy | |
| redis-node-2: | |
| condition: service_healthy | |
| redis-node-3: | |
| condition: service_healthy | |
| redis-node-4: | |
| condition: service_healthy | |
| redis-node-5: | |
| condition: service_healthy | |
| redis-node-6: | |
| condition: service_healthy | |
| networks: | |
| - vc_auth | |
| command: > | |
| sh -c " | |
| if redis-cli -h redis-node-1 cluster info | grep -q 'cluster_state:ok'; then | |
| echo 'Redis cluster already initialized.' | |
| else | |
| echo 'Creating Redis Cluster...' && | |
| redis-cli --cluster create redis-node-1:6379 redis-node-2:6379 redis-node-3:6379 redis-node-4:6379 redis-node-5:6379 redis-node-6:6379 --cluster-replicas 1 --cluster-yes && | |
| echo 'Cluster created successfully!' | |
| fi | |
| " | |
| restart: "no" | |
| volumes: | |
| redis-node-1-data: | |
| redis-node-2-data: | |
| redis-node-3-data: | |
| redis-node-4-data: | |
| redis-node-5-data: | |
| redis-node-6-data: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Test Redis Cluster mode with VC-AuthN OIDC | |
| # | |
| # Usage: | |
| # ./test-cluster.sh start - Start cluster test environment | |
| # ./test-cluster.sh stop - Stop all services | |
| # ./test-cluster.sh logs - View logs | |
| # ./test-cluster.sh status - Check Redis Cluster status | |
| # | |
| set -e | |
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | |
| cd "$SCRIPT_DIR" | |
| # Colors for output | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| NC='\033[0m' # No Color | |
| echo_info() { echo -e "${YELLOW}$1${NC}"; } | |
| echo_success() { echo -e "${GREEN}$1${NC}"; } | |
| echo_error() { echo -e "${RED}$1${NC}"; } | |
| # Check for .env file | |
| check_env() { | |
| if [[ ! -f ".env" ]]; then | |
| echo_error "ERROR: .env file not found!" | |
| echo_info "Please copy .env.example to .env first:" | |
| echo " cp .env.example .env" | |
| exit 1 | |
| fi | |
| } | |
| # Apply cluster environment overrides | |
| apply_cluster_env() { | |
| # Export cluster-specific settings | |
| export REDIS_MODE=cluster | |
| export REDIS_HOST="redis-node-1:6379,redis-node-2:6379,redis-node-3:6379" | |
| export REDIS_PORT=6379 # Not used in cluster mode, but compose references it | |
| export REDIS_PASSWORD= | |
| export REDIS_DB=0 | |
| # Set dummy values for unused variables to suppress compose warnings | |
| export AGENT_ENDPOINT="${AGENT_ENDPOINT:-http://localhost:8030}" | |
| export AGENT_ADMIN_MODE="${AGENT_ADMIN_MODE:-admin-insecure-mode}" | |
| export CONTROLLER_URL="${CONTROLLER_URL:-http://localhost:5000}" | |
| export ACAPY_TENANT_WALLET_ID="${ACAPY_TENANT_WALLET_ID:-}" | |
| export ACAPY_TENANT_WALLET_KEY="${ACAPY_TENANT_WALLET_KEY:-}" | |
| echo_info "Redis Cluster configuration:" | |
| echo " REDIS_MODE=$REDIS_MODE" | |
| echo " REDIS_HOST=$REDIS_HOST" | |
| } | |
| # Compose command for cluster | |
| compose_cluster() { | |
| docker compose -f docker-compose.yaml -f docker-compose-cluster.yaml "$@" | |
| } | |
| case "${1:-help}" in | |
| start) | |
| check_env | |
| apply_cluster_env | |
| echo_info "Building images if needed..." | |
| docker build -t 'acapy-vc-authn-oidc-controller' -f './oidc-controller/Dockerfile' '..' | |
| echo_info "Starting Redis Cluster test environment..." | |
| echo_info "(This is a minimal setup - no ngrok/agent for quick testing)" | |
| # Start only the minimal services needed for testing Redis Cluster | |
| compose_cluster up -d \ | |
| redis-node-1 \ | |
| redis-node-2 \ | |
| redis-node-3 \ | |
| redis-node-4 \ | |
| redis-node-5 \ | |
| redis-node-6 \ | |
| redis-cluster-init \ | |
| controller-db \ | |
| controller \ | |
| controller-lb | |
| echo "" | |
| echo_success "Cluster test environment started!" | |
| echo "" | |
| echo "Services running:" | |
| echo " - Redis Cluster Nodes 1-6 (redis-node-{1..6}:6379)" | |
| echo " - Controller (http://localhost:5000)" | |
| echo "" | |
| echo "Useful commands:" | |
| echo " ./test-cluster.sh logs - View logs" | |
| echo " ./test-cluster.sh status - Check Redis Cluster status" | |
| echo " ./test-cluster.sh stop - Stop all services" | |
| ;; | |
| stop) | |
| echo_info "Stopping cluster test environment..." | |
| compose_cluster down -v | |
| echo_success "Stopped." | |
| ;; | |
| logs) | |
| compose_cluster logs -f controller redis-node-1 redis-node-2 redis-node-3 | |
| ;; | |
| status) | |
| echo_info "=== Redis Cluster Status ===" | |
| echo "" | |
| echo "Cluster Info:" | |
| docker compose -f docker-compose.yaml -f docker-compose-cluster.yaml exec redis-node-1 \ | |
| redis-cli cluster info 2>/dev/null | head -10 || echo "Cluster not ready" | |
| echo "" | |
| echo "Cluster Nodes:" | |
| docker compose -f docker-compose.yaml -f docker-compose-cluster.yaml exec redis-node-1 \ | |
| redis-cli cluster nodes 2>/dev/null || echo "Nodes not available" | |
| ;; | |
| *) | |
| echo "Redis Cluster Test Environment" | |
| echo "" | |
| echo "Usage: $0 <command>" | |
| echo "" | |
| echo "Commands:" | |
| echo " start - Start cluster test environment (minimal services)" | |
| echo " stop - Stop all services and remove volumes" | |
| echo " logs - View logs from cluster and controller" | |
| echo " status - Show Redis Cluster status" | |
| echo "" | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment