version: '3.8'

services:
  db:
    image: mysql:5.7.44
    # platform: linux/x86_64
    restart: always
    volumes:
      - ./volumes/mysql/data:/var/lib/mysql
    ports:
      - '3306:3306'
    environment:
      MYSQL_ROOT_PASSWORD: 'open-assistant-api@2023'
      MYSQL_USER: open_assistant
      MYSQL_PASSWORD: '123456'
      MYSQL_DATABASE: open_assistant
      # TZ: Asia/Shanghai
    command: [ 'mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci' ]
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      timeout: 20s
      retries: 10


  redis:
    image: redis:6-alpine
    # platform: linux/x86_64
    restart: always
    volumes:
      - ./volumes/redis/data:/data
    ports:
      - '6379:6379'
    command: redis-server --requirepass 123456
    healthcheck:
      test: [ "CMD", "redis-cli","ping" ]


  minio:
    image: minio/minio:RELEASE.2023-03-20T20-16-18Z
    # platform: linux/x86_64
    restart: always
    volumes:
      - ./volumes/minio/data:/minio_data
    ports:
      - '9001:9001'
      - '9000:9000'
    environment:
      MINIO_ACCESS_KEY: minioadmin
      MINIO_SECRET_KEY: minioadmin
    command: minio server /minio_data --console-address ':9001'
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:9000/minio/health/live" ]
      interval: 30s
      timeout: 20s
      retries: 3


  create-buckets:
    image: minio/mc
    # platform: linux/x86_64
    environment:
      MINIO_ACCESS_KEY: minioadmin
      MINIO_SECRET_KEY: minioadmin
      BUCKET_NAME: 'oas'
    depends_on:
      - minio
    entrypoint: >
      /bin/sh -c "
      /usr/bin/mc alias set minio http://minio:9000 $${MINIO_ACCESS_KEY} $${MINIO_SECRET_KEY};
      /usr/bin/mc mb -p minio/$${BUCKET_NAME};
      exit 0;
      "
