services:
  redis:
    image: "bitnami/redis:7.4"
    container_name: redis
    environment:
      ALLOW_EMPTY_PASSWORD: yes
    ports:
      - "6379:6379"
    healthcheck:
      test: [ "CMD-SHELL", "redis-cli --no-auth-warning ping | grep PONG" ]
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - redis-data:/bitnami/redis/data

  artemis:
    image: "romanowalex/artemis:2.28.0"
    container_name: artemis
    environment:
      ANONYMOUS_LOGIN: true
    ports:
      - "8161:8161"
      - "61616:61616"
    healthcheck:
      test: [ "CMD-SHELL", "/var/lib/artemis-instance/bin/artemis check queue --name TEST --produce 10 --browse 10 --consume 10 --url tcp://localhost:61616" ]
      interval: 10s
      timeout: 10s
      retries: 5
    volumes:
      - artemis-data:/var/lib/artemis-instance

  websocket-service-1:
    build: .
    image: "romanowalex/websocket-service:v1.0"
    container_name: "websocket-service-1"
    environment:
      SPRING_PROFILES_ACTIVE: docker
    ports:
      - "8081:8080"
    healthcheck:
      test: [ "CMD", "curl", "--silent", "--fail", "http://localhost:8080/manage/health" ]
      interval: 5s
      timeout: 5s
      retries: 5
    depends_on:
      redis:
        condition: service_healthy
      artemis:
        condition: service_healthy

  websocket-service-2:
    build: .
    image: "romanowalex/websocket-service:v1.0"
    container_name: "websocket-service-2"
    environment:
      SPRING_PROFILES_ACTIVE: docker
    ports:
      - "8082:8080"
    healthcheck:
      test: [ "CMD", "curl", "--silent", "--fail", "http://localhost:8080/manage/health" ]
      interval: 5s
      timeout: 5s
      retries: 5
    depends_on:
      redis:
        condition: service_healthy
      artemis:
        condition: service_healthy

  nginx:
    image: nginx:1.25
    container_name: nginx
    ports:
      - "8080:80"
    healthcheck:
      test: "curl --fail http://localhost/manage/health || exit 1"
      interval: 5s
      timeout: 3s
      retries: 5
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      websocket-service-1:
        condition: service_healthy
      websocket-service-2:
        condition: service_healthy

volumes:
  redis-data:
  artemis-data:
