version: '3'
networks:
  default:
    driver: bridge
        
services:
  expmysql:
    image: "mysql:8.0" 
    ports:
      - "3306:3306"
    env_file:
      - path: ./db.env
    restart: always
    networks: 
      - default
    privileged: true
    volumes:
      - "/etc/localtime:/etc/localtime"
      - "./mysql/conf/my.cnf:/etc/my.cnf"
      - "./mysql/init:/docker-entrypoint-initdb.d/"
      - "./data/mysql:/var/lib/mysql"
  expredis:
    image: "redis:latest"
    restart: always
    networks:
      - default
    environment:
      - TZ=Asia/Shanghai
    command: /usr/local/bin/redis-server /etc/redis/redis.conf
    ports:
      - "6379:6379"   
    volumes:
      - "/etc/localtime:/etc/localtime"
      - "./redis/conf/redis.conf:/etc/redis/redis.conf"
      - "./data/redis:/data"
  expblockscan:
    image: "blockscan:latest"
    restart: always
    networks:
      - default
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - "/etc/localtime:/etc/localtime"
      - "./blockscan/config.yml:/root/config.yml"
      - "./blockscan/loger.xml:/root/loger.xml"
      - "./data/scanlog/:/root/logs"
    depends_on:
      - expredis
  expservice:
    image: "expservice:latest"
    restart: always
    networks:
      - default
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - "/etc/localtime:/etc/localtime"
      - "./expservice/:/root/conf"
      - "./data/servicelog/:/root/logs"
    ports:
      - "12011:12011"   
    depends_on:
      - expredis
      - expmysql
      - expblockscan
  caddy:
    image: caddy:latest
    restart: unless-stopped
    environment:
      - XDG_CONFIG_HOME=/config
      - XDG_DATA_HOME=/data
      - CADDY_ADMIN=0.0.0.0:2019
    ports:
      - "80:80"
      - "443:443"
      - "2019:2019"
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile
      - ./caddy/data:/data
      - ./caddy/certs:/certs
      - ./caddy/config:/config
      - ./caddy/root:/srv
      - ./caddy/logs:/var/log/caddy
      - ./web:/web
  ipfs:
    image: ipfs/kubo:v0.34.1
    container_name: ipfs_host
    mem_limit: 4g
    cpus: '4.0'
    environment:
      - GOMEMLIMIT=3800MiB
    ports:
      - "4001:4001"
      - "4001:4001/udp"
      - "127.0.0.1:18080:8080"
      - "127.0.0.1:15001:5001"
  nftdb:
    container_name: "mysql-nft"
    image: mysql:8
    restart: on-failure
    environment:
      MYSQL_ROOT_PASSWORD: XN2UARuys3zy4Oux
      MYSQL_DATABASE: nft
    volumes:
      - ./data/nftscan/mysql:/var/lib/mysql
    ports:
      - "127.0.0.1:53306:3306"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-pXN2UARuys3zy4Oux"]
      interval: 10s
      timeout: 5s
      retries: 5
  sync:
    image: token-collection:${TAG:-latest}
    container_name: token-collection
    environment:
      - SYNC=${SYNC:-0}
      - MIGRATE=${MIGRATE:-true}
    volumes:
      - ./data/nftscan/synclogs:/app
      - ./nftscan/config.toml:/config.toml
    command:
      - "/bin/sh"
      - "-c"
      - "/usr/bin/sync -c /config.toml"
    restart: unless-stopped
    depends_on:
      nftdb:
        condition: service_healthy
  api:
    image: token-collection:${TAG:-latest}
    container_name: token-collection-api
    environment:
      - MIGRATE=${MIGRATE:-true}
    ports:
      - "10256:10256"
    volumes:
      - ./data/nftscan/apilogs:/app
      - ./nftscan/config.toml:/config.toml
    command:
      - "/bin/sh"
      - "-c"
      - "/usr/bin/api -c /config.toml"
    restart: unless-stopped
    depends_on:
      nftdb:
        condition: service_healthy
