docker-compose.yml 261 lignes · 6675 octets
# Three-instance Rustwarden topology for fediverse end-to-end tests.
# Each app talks to the others via the docker network using FEDIVERSE_DOMAIN
# as a network alias, so signed HTTP requests can resolve the peer hostnames
# without any /etc/hosts trickery on the host machine.
#
# Usage:
#   cd tests/fediverse-testbed
#   ./scripts/setup.sh
#   ./scripts/teardown.sh

name: rustwarden-fediverse-testbed

x-app-common: &app-common
  build:
    context: ../..
    dockerfile: tests/fediverse-testbed/Dockerfile
  image: rustwarden-fediverse-testbed:latest
  restart: unless-stopped
  healthcheck:
    test: ["CMD", "curl", "-fsS", "http://localhost/health"]
    interval: 5s
    timeout: 3s
    retries: 30
    start_period: 10s

services:
  postgres-alpha:
    image: postgres:18-trixie
    environment:
      POSTGRES_DB: rustwarden_alpha
      POSTGRES_USER: rustwarden
      POSTGRES_PASSWORD: rustwarden
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U rustwarden -d rustwarden_alpha"]
      interval: 3s
      timeout: 2s
      retries: 20
    networks: [fediverse-net]

  postgres-beta:
    image: postgres:18-trixie
    environment:
      POSTGRES_DB: rustwarden_beta
      POSTGRES_USER: rustwarden
      POSTGRES_PASSWORD: rustwarden
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U rustwarden -d rustwarden_beta"]
      interval: 3s
      timeout: 2s
      retries: 20
    networks: [fediverse-net]

  postgres-gamma:
    image: postgres:18-trixie
    environment:
      POSTGRES_DB: rustwarden_gamma
      POSTGRES_USER: rustwarden
      POSTGRES_PASSWORD: rustwarden
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U rustwarden -d rustwarden_gamma"]
      interval: 3s
      timeout: 2s
      retries: 20
    networks: [fediverse-net]

  # One-shot migration jobs. The rustwarden-app binary does NOT auto-run
  # migrations at startup — the dedicated `migrate` CLI (SeaORM) must run
  # first and exit 0 before the apps boot.
  migrate-alpha:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/alpha.env
    command: ["migrate", "up"]
    depends_on:
      postgres-alpha:
        condition: service_healthy
    networks: [fediverse-net]

  migrate-beta:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/beta.env
    command: ["migrate", "up"]
    depends_on:
      postgres-beta:
        condition: service_healthy
    networks: [fediverse-net]

  migrate-gamma:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/gamma.env
    command: ["migrate", "up"]
    depends_on:
      postgres-gamma:
        condition: service_healthy
    networks: [fediverse-net]

  # Fediverse-specific schema (tables `fediverse_*`). Runs after the
  # core migrator and uses its own tracking table
  # `seaql_fediverse_migrations`.
  migrate-fediverse-alpha:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/alpha.env
    command: ["migrate-fediverse", "up"]
    depends_on:
      migrate-alpha:
        condition: service_completed_successfully
    networks: [fediverse-net]

  migrate-fediverse-beta:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/beta.env
    command: ["migrate-fediverse", "up"]
    depends_on:
      migrate-beta:
        condition: service_completed_successfully
    networks: [fediverse-net]

  migrate-fediverse-gamma:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/gamma.env
    command: ["migrate-fediverse", "up"]
    depends_on:
      migrate-gamma:
        condition: service_completed_successfully
    networks: [fediverse-net]

  # Fediverse-guard schema (tables `fediverse_guard_*`). Runs after the
  # fediverse migrator and uses its own tracking table
  # `seaql_fediverse_guard_migrations`. Only required when the host
  # binary is built with the `fediverse-guard` feature.
  migrate-fediverse-guard-alpha:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/alpha.env
    command: ["migrate-fediverse-guard", "up"]
    depends_on:
      migrate-fediverse-alpha:
        condition: service_completed_successfully
    networks: [fediverse-net]

  migrate-fediverse-guard-beta:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/beta.env
    command: ["migrate-fediverse-guard", "up"]
    depends_on:
      migrate-fediverse-beta:
        condition: service_completed_successfully
    networks: [fediverse-net]

  migrate-fediverse-guard-gamma:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/gamma.env
    command: ["migrate-fediverse-guard", "up"]
    depends_on:
      migrate-fediverse-gamma:
        condition: service_completed_successfully
    networks: [fediverse-net]

  app-alpha:
    <<: *app-common
    env_file: env/alpha.env
    depends_on:
      migrate-fediverse-guard-alpha:
        condition: service_completed_successfully
    ports:
      - "3001:80"
    networks:
      fediverse-net:
        aliases: [alpha.local]

  app-beta:
    <<: *app-common
    env_file: env/beta.env
    depends_on:
      migrate-fediverse-guard-beta:
        condition: service_completed_successfully
    ports:
      - "3002:80"
    networks:
      fediverse-net:
        aliases: [beta.local]

  app-gamma:
    <<: *app-common
    env_file: env/gamma.env
    depends_on:
      migrate-fediverse-guard-gamma:
        condition: service_completed_successfully
    ports:
      - "3003:80"
    networks:
      fediverse-net:
        aliases: [gamma.local]

  # One-shot seed jobs: each waits for its app to be healthy (which means
  # migrations have run) then loads the Happy Days fixtures with
  # joanie/happydays123 as the admin user.
  seed-alpha:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/alpha.env
    command: ["seed", "--force"]
    depends_on:
      app-alpha:
        condition: service_healthy
    networks: [fediverse-net]

  seed-beta:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/beta.env
    command: ["seed", "--force"]
    depends_on:
      app-beta:
        condition: service_healthy
    networks: [fediverse-net]

  seed-gamma:
    <<: *app-common
    restart: "no"
    healthcheck:
      disable: true
    env_file: env/gamma.env
    command: ["seed", "--force"]
    depends_on:
      app-gamma:
        condition: service_healthy
    networks: [fediverse-net]

networks:
  fediverse-net:
    driver: bridge