name: uninbox-local-dev

services:
  # Local Mysql DB with Planetscale Proxy
  ps-mysql:
    container_name: mysql-primary-db
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_DATABASE: planetscale
      MYSQL_ROOT_HOST: '%'
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    command:
      [
        '--max_connections=1000',
        '--default-authentication-plugin=mysql_native_password'
      ]
    ports:
      - 3307:3306
    volumes:
      - ps-mysql:/var/lib/mysql
  planetscale-proxy:
    container_name: planetscale-simulator-proxy
    image: ghcr.io/mattrobenolt/ps-http-sim:v0.0.3
    restart: always
    command:
      [
        '-mysql-no-pass',
        '-listen-port=3900',
        '-mysql-dbname=planetscale',
        '-mysql-addr=ps-mysql'
      ]
    depends_on:
      - ps-mysql
    ports:
      - 3900:3900
    links:
      - ps-mysql

  # Local Redis server
  redis:
    container_name: redis-cache-db
    image: redis:7.2-alpine
    restart: always
    ports:
      - '3901:6379' # expose redis on port 3102 to not collide with redis from elswhere and match memostash 310X ports
    command: redis-server --save 20 1 --loglevel warning
    volumes:
      - redis-data:/data

  # Local S3 Strorage
  minio:
    container_name: minio-storage
    image: 'bitnami/minio:latest'
    restart: always
    ports:
      - '3902:3902'
      - '3903:3903'
    environment:
      - MINIO_ROOT_USER=minioroot
      - MINIO_ROOT_PASSWORD=minioroot
      - MINIO_API_PORT_NUMBER=3902
      - MINIO_CONSOLE_PORT_NUMBER=3903
    volumes:
      - minio-data:/bitnami/minio/data
      - minio-certs:/certs

  createbuckets:
    container_name: minio-bucket-creation
    image: minio/mc
    depends_on:
      - minio
    entrypoint: >
      /bin/sh -c "
      sleep 10;
      /usr/bin/mc alias set myminio http://minio:3902 minioroot minioroot;
      /usr/bin/mc mb myminio/avatars;
      /usr/bin/mc mb myminio/attachments;
      echo '{\"Version\": \"2012-10-17\",\"Statement\": [{\"Effect\": \"Allow\",\"Principal\": {\"AWS\": [\"*\"]},\"Action\": [\"s3:GetObject\"],\"Resource\": [\"arn:aws:s3:::avatars/*\"]}]}' > /tmp/policy.json;
      /usr/bin/mc anonymous set-json /tmp/policy.json myminio/avatars;
      exit 0;
      "

  # Soketi Pusher Server
  soketi:
    container_name: soketi-server
    image: quay.io/soketi/soketi:1.4-16-debian
    restart: always
    ports:
      - '3904:6001'
    environment:
      - SOKETI_DB_REDIS_HOST=redis
      - SOKETI_DB_REDIS_PORT=6379
      - SOKETI_DB_REDIS_DB=0
      - SOKETI_DB_REDIS_KEY_PREFIX=soketi
      - SOKETI_CACHE_DRIVER=redis
      - SOKETI_DEFAULT_APP_ID=default
      - SOKETI_DEFAULT_APP_KEY=secretsecretsecret
      - SOKETI_DEFAULT_APP_SECRET=secretsecretsecret
      - SOKETI_DEFAULT_APP_USER_AUTHENTICATION=true
      - SOKETI_USER_AUTHENTICATION_TIMEOUT=10000 # 10 seconds
    depends_on:
      - redis
    links:
      - redis

volumes:
  ps-mysql:
  redis-data:
  minio-data:
  minio-certs:
