services:
  app:
    build:
      context: ./app
      dockerfile: Dockerfile
    restart: unless-stopped
    depends_on:
      mysql:
        condition: service_healthy
    expose:
      - "80"
    environment:
      APP_NAME: ${APP_NAME:-Dewemoji}
      APP_ENV: ${APP_ENV:-production}
      APP_DEBUG: ${APP_DEBUG:-false}
      APP_URL: ${APP_URL:-http://localhost:8000}
      APP_KEY: ${APP_KEY:-}

      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: ${DB_DATABASE:-dewemoji}
      DB_USERNAME: ${DB_USERNAME:-dewemoji}
      DB_PASSWORD: ${DB_PASSWORD:-changeme}

      SESSION_DRIVER: ${SESSION_DRIVER:-file}
      CACHE_STORE: ${CACHE_STORE:-file}
      QUEUE_CONNECTION: ${QUEUE_CONNECTION:-sync}

      DEWEMOJI_BILLING_MODE: ${DEWEMOJI_BILLING_MODE:-sandbox}

      WAIT_FOR_DB: ${WAIT_FOR_DB:-true}
      RUN_MIGRATIONS: ${RUN_MIGRATIONS:-true}
    volumes:
      - app_storage:/var/www/html/storage
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1/v1/health >/dev/null || exit 1"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 30s

  mysql:
    image: mysql:8.0
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-dewemoji}
      MYSQL_USER: ${DB_USERNAME:-dewemoji}
      MYSQL_PASSWORD: ${DB_PASSWORD:-changeme}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-rootchangeme}
    expose:
      - "3306"
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -u$$MYSQL_USER -p$$MYSQL_PASSWORD --silent"]
      interval: 10s
      timeout: 5s
      retries: 15
      start_period: 20s

volumes:
  app_storage:
  mysql_data:
