version: '3.5'

configs:
  nginx_config:
    content: |
      server {
        listen 80;
        server_name localhost;  # Or your domain name
      
        location / {
          proxy_pass http://web:3000; # Forward requests to the web service
        }
      
        location /api {
          proxy_pass http://service:8942; # Forward requests to the api service
        }
        location /taker/api {
          proxy_pass http://service:8942; # Forward requests to the taker api service
        }
      }

services:
  nginx:
    image: nginx:latest
    ports:
      - "17610:80"  # Map host port 17610 to nginx port 80
    depends_on:
      - web
      - service
    configs:
      - source: nginx_config
        target: /etc/nginx/conf.d/default.conf

  web:
    image: dotswap/dotswap-dex-web:latest
    depends_on:
      - service

  service:
    image: dotswap/dotswap-dex-service:v3.2.7
    env_file:
      - .env
    environment:
      DB_HOST: mysql
      DB_PORT: 3306
      DB_USERNAME: root
      DB_PASSWORD: pass
      DB_DBNAME: dotswap-ext
      # Override CORS origins for the service. Use a comma-separated list.
      # This value takes precedence over the config.yml file.
      # Example: CORS_ALLOWED_ORIGINS: "http://localhost:3000,https://your.frontend.com"
      CORS_ALLOWED_ORIGINS: "${CORS_ALLOWED_ORIGINS:-}"
      CACHE_ADDR: redis:6379
      CACHE_DB: 0
      NODES_BTC_NODE_CONFIG_HOST: 47.76.50.243:11332
      NODES_BTC_NODE_CONFIG_USER: fullnodetesting
      NODES_BTC_NODE_CONFIG_PASS: fullnodetesting9902kcylap0sdsdbldfasdpfuoupouewrh1111jknvllad
      NODES_BTC_NODE_ZMQ_HOST: tcp://47.76.50.243:11331
      ORD_URL: ${ORD_URL:-https://rune-ord.mempool.com}                                         # ord service url
      DOTSWAP_HOST: ${DOTSWAP_HOST:-https://api.dotswap.app}  # dotswap host
      DOTSWAP_ACCOUNT_ADDRESS: ${DOTSWAP_ACCOUNT_ADDRESS:?}                             # account address
      DOTSWAP_ACCOUNT_PRIVATE_KEY_HEX: ${DOTSWAP_ACCOUNT_PRIVATE_KEY_HEX:?}             # account address private key
      MNEMONIC: ${MNEMONIC:?}                                                           # mnemonic phrase
      TAKER_MNEMONIC: ${TAKER_MNEMONIC:-${MNEMONIC}}
      JWT_PUBLIC_KEY_PEM: |
        -----BEGIN RSA PUBLIC KEY-----
        MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA18oKBV9tXNFqaTHZfBgG
        pwu4eHtv9AW845yGDVX5xsGzI8ltelNg9j8Rtse2EhHnI+1F1Mjj8E4e1Bh+vnE9
        rfnzDNfddmU++Ivxu+19Nrges6wPmI5BwYG1sDGYhx7QaeI8St68YzTEnIFYsDX3
        TAXSIvxlD4jiRGdCudr0qLiaKdeBphvjSHiY+NkBv4ETkV3QhZYaC8etlNGzottf
        H3aHAGgPgMEA/njQflT6tu4lzKrxfie7mMucJD/+vFqZ0X3XP5HsG8BwCYypCEga
        pdJsQhptTOXRxJeW7WIWmAQUadiIfCrVchnoedlvXgCaTGlqx8KIGubgJT4UJAh8
        2wIDAQAB
        -----END RSA PUBLIC KEY-----
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    command: dotswap-ext -env=${APP_ENV:-prod} -mod=maker,taker
    restart: always
    healthcheck:
      test: [ "CMD-SHELL", "curl -f http://localhost:8942/ping || exit 1" ]
      interval: 3s
      timeout: 3s
      retries: 10

  mysql:
    image: mysql:latest
    environment:
      MYSQL_ROOT_HOST: '%'
      MYSQL_ROOT_PASSWORD: pass
      MYSQL_DATABASE: dotswap-ext
    volumes:
      - dotswap_ext_mysql:/var/lib/mysql
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      interval: 3s
      timeout: 3s
      retries: 10

  redis:
    image: redis:latest
    healthcheck:
      test: [ "CMD", "redis-cli", "ping" ]
      interval: 3s
      timeout: 3s
      retries: 10

volumes:
  dotswap_ext_mysql:
    driver: local
