version: "3.9"

services:
  sinsay_app:
    container_name: sinsay-app
    build:
      context: ./app
      dockerfile: Dockerfile
    restart: unless-stopped
    env_file: .env
    environment:
      DATABASE_URL: postgresql://proxy:proxy_secret@sinsay-postgres:5432/proxydb
      REDIS_URL: redis://sinsay-redis:6379
      AURORA_API_BASE: http://sinsay-payment:4177
    depends_on:
      sinsay_postgres:
        condition: service_healthy
      sinsay_redis:
        condition: service_healthy
      sinsay_payment:
        condition: service_started
    networks:
      - sinsay_net
      - morele_proxy_net

  sinsay_payment:
    container_name: sinsay-payment
    build:
      context: ./payment-gateway-app
      dockerfile: Dockerfile.prod
    restart: unless-stopped
    env_file: payment.env
    environment:
      SESSIONS_FILE: /data/payment-sessions.json
    volumes:
      - sinsay_payment_data:/data
    networks:
      - sinsay_net
      - morele_proxy_net

  sinsay_redis:
    container_name: sinsay-redis
    image: redis:7-alpine
    restart: unless-stopped
    volumes:
      - redis_data:/data
    command: redis-server --save 60 1 --appendonly yes --loglevel warning
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
    networks:
      - sinsay_net

  sinsay_postgres:
    container_name: sinsay-postgres
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: proxy
      POSTGRES_PASSWORD: 2cd883df0056db90dc9de3594523c154e49c3cde
      POSTGRES_DB: proxydb
    volumes:
      - pg_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U proxy"]
      interval: 5s
      timeout: 3s
      retries: 10
    networks:
      - sinsay_net

  neverbot:
    container_name: sinsay-neverbot
    build:
      context: /opt/neverbot
      dockerfile: Dockerfile
    restart: unless-stopped
    env_file: /opt/neverbot/.env
    depends_on:
      sinsay_postgres:
        condition: service_healthy
    networks:
      - sinsay_net
      - morele_proxy_net

volumes:
  redis_data:
  pg_data:
  sinsay_payment_data:

networks:
  sinsay_net:
    driver: bridge
  morele_proxy_net:
    external: true
    name: morele-proxy_morele_proxy_net
