version: "3.8"

services:
  dialer:
    build:
      target: debug
      context: ..
      args:
        PACKAGE: firezone-connection-tests
      cache_from:
        - type=registry,ref=us-east1-docker.pkg.dev/firezone-staging/cache/connection-tests:main
    image: us-east1-docker.pkg.dev/firezone-staging/firezone/connection-tests:${VERSION:-main}
    init: true
    environment:
      ROLE: "dialer"
      LISTEN_ADDR: 172.28.0.100
      REDIS_HOST: redis # All services share the `app` network.
    cap_add:
      - NET_ADMIN
    # depends_on:
    #   relay:
    #     condition: "service_healthy"
    #   redis:
    #     condition: "service_healthy"
    networks:
      app:
        ipv4_address: 172.28.0.100

  listener:
    build:
      target: debug
      context: ..
      args:
        PACKAGE: firezone-connection-tests
      cache_from:
        - type=registry,ref=us-east1-docker.pkg.dev/firezone-staging/cache/connection-tests:main
    image: us-east1-docker.pkg.dev/firezone-staging/firezone/connection-tests:${VERSION:-main}
    init: true
    environment:
      ROLE: "listener"
      LISTEN_ADDR: 172.28.0.101
      REDIS_HOST: redis # All services share the `app` network.
    cap_add:
      - NET_ADMIN
    # depends_on:
    #   relay:
    #     condition: "service_healthy"
    #   redis:
    #     condition: "service_healthy"
    networks:
      app:
        ipv4_address: 172.28.0.101

  # relay:
  #   environment:
  #     PUBLIC_IP4_ADDR: 172.28.0.102
  #     PUBLIC_IP6_ADDR: fcff:3990:3990::101
  #     LOWEST_PORT: 55555
  #     HIGHEST_PORT: 55666
  #     RUST_LOG: "debug"
  #     RUST_BACKTRACE: 1
  #   build:
  #     target: debug
  #     context: ..
  #     cache_from:
  #       - type=registry,ref=us-east1-docker.pkg.dev/firezone-staging/cache/relay:main
  #     args:
  #       PACKAGE: firezone-relay
  #   init: true
  #   healthcheck:
  #     test: ["CMD-SHELL", "lsof -i UDP | grep firezone-relay"]
  #     start_period: 20s
  #     interval: 30s
  #     retries: 5
  #     timeout: 5s
  #   ports:
  #     # XXX: Only 111 ports are used for local dev / testing because Docker Desktop
  #     # allocates a userland proxy process for each forwarded port X_X.
  #     #
  #     # Large ranges here will bring your machine to its knees.
  #     - "55555-55666:55555-55666/udp"
  #     - 3478:3478/udp
  #   networks:
  #     app:
  #       ipv4_address: 172.28.0.102

  redis:
    image: "redis:7-alpine"
    # healthcheck:
    #   test: ["CMD-SHELL", "echo 'ready';"]
    networks:
      app:
        ipv4_address: 172.28.0.103

networks:
  app:
    enable_ipv6: true
    ipam:
      config:
        - subnet: 172.28.0.0/16
        - subnet: 2001:db8:2::/64
