services:
  rabbitmq:
    image: rabbitmq:3-management
    container_name: aips-rabbitmq
    restart: unless-stopped
    environment:
      RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
      RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
      RABBITMQ_DEFAULT_VHOST: ${RABBITMQ_DEFAULT_VHOST}
    volumes:
      - rabbitmqdata:/var/lib/rabbitmq
    healthcheck:
      test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
      interval: 10s
      timeout: 10s
      retries: 5

  webapi:
    build:
      context: ..
      dockerfile: deploy/Dockerfile.webapi
    container_name: aips-webapi
    restart: unless-stopped
    environment:
      ASPNETCORE_URLS: "http://+:8080"
      ASPNETCORE_ENVIRONMENT: "Production"
      DB_CONN_STRING: "Host=postgres;Port=5432;Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}"
      RABBITMQ_AMQP_URI: "amqp://${RABBITMQ_DEFAULT_USER}:${RABBITMQ_DEFAULT_PASS}@rabbitmq:5672/${RABBITMQ_DEFAULT_VHOST}"
      RABBITMQ_EXCHANGE: "${RABBITMQ_EXCHANGE}"
      JWT_ISSUER: "${JWT_ISSUER}"
      JWT_AUDIENCE: "${JWT_AUDIENCE}"
      JWT_KEY: "${JWT_KEY}"
      JWT_EXPIRATION_MINUTES: "${JWT_EXPIRATION_MINUTES}"
      JWT_REFRESH_TOKEN_EXPIRATION_DAYS: "${JWT_REFRESH_TOKEN_EXPIRATION_DAYS}"
    networks:
      - default
      - back_network
    depends_on:
      rabbitmq:
        condition: service_healthy

  rt:
    build:
      context: ..
      dockerfile: deploy/Dockerfile.rt
    container_name: aips-rt
    restart: unless-stopped
    environment:
      ASPNETCORE_URLS: "http://+:8080"
      ASPNETCORE_ENVIRONMENT: "Production"
      DB_CONN_STRING: "Host=postgres;Port=5432;Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}"
      RABBITMQ_AMQP_URI: "amqp://${RABBITMQ_DEFAULT_USER}:${RABBITMQ_DEFAULT_PASS}@rabbitmq:5672/${RABBITMQ_DEFAULT_VHOST}"
      RABBITMQ_EXCHANGE: "${RABBITMQ_EXCHANGE}"
      JWT_ISSUER: "${JWT_ISSUER}"
      JWT_AUDIENCE: "${JWT_AUDIENCE}"
      JWT_KEY: "${JWT_KEY}"
      JWT_EXPIRATION_MINUTES: "${JWT_EXPIRATION_MINUTES}"
      JWT_REFRESH_TOKEN_EXPIRATION_DAYS: "${JWT_REFRESH_TOKEN_EXPIRATION_DAYS}"
    networks:
      - default
      - back_network
    depends_on:
      rabbitmq:
        condition: service_healthy

  worker:
    build:
      context: ..
      dockerfile: deploy/Dockerfile.worker
    container_name: aips-worker
    restart: unless-stopped
    environment:
      DB_CONN_STRING: "Host=postgres;Port=5432;Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}"
      RABBITMQ_AMQP_URI: "amqp://${RABBITMQ_DEFAULT_USER}:${RABBITMQ_DEFAULT_PASS}@rabbitmq:5672/${RABBITMQ_DEFAULT_VHOST}"
      RABBITMQ_EXCHANGE: "${RABBITMQ_EXCHANGE}"
      JWT_ISSUER: "${JWT_ISSUER}"
      JWT_AUDIENCE: "${JWT_AUDIENCE}"
      JWT_KEY: "${JWT_KEY}"
    networks:
      - default
      - back_network
    depends_on:
      rabbitmq:
        condition: service_healthy

  nginx:
    build:
      context: ..
      dockerfile: deploy/Dockerfile.front
    container_name: aips-nginx
    restart: unless-stopped
    ports:
      - "8090:80"
    depends_on:
      - webapi
      - rt

networks:
  back_network:
    external: true

volumes:
  rabbitmqdata:
