version: '3.8'

services:
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ../api:/var/www/api:ro
      - ../admin:/var/www/admin:ro
      - ../sdk:/var/www/sdk:ro
      - ../sw:/var/www/sw:ro
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/sites:/etc/nginx/sites:ro
      - ./nginx/ssl:/etc/nginx/ssl:ro
    depends_on:
      - php
    networks:
      - push-network

  php:
    build:
      context: ./php
      dockerfile: Dockerfile
    volumes:
      - ../api:/var/www/api
      - ../shopify-app:/var/www/shopify-app
    environment:
      - PUSH_BASE_URL=${PUSH_BASE_URL:-https://push.minifytool.com}
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_NAME=${DB_NAME:-push_notifications}
      - DB_USER=${DB_USER:-pushuser}
      - DB_PASS=${DB_PASS:-pushpass}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - ENCRYPTION_KEY=${ENCRYPTION_KEY:-changeme32characterslongexactly}
      - APP_ENV=${APP_ENV:-production}
    depends_on:
      - mysql
      - redis
    networks:
      - push-network

  mysql:
    image: mysql:8.0
    command: --default-authentication-plugin=mysql_native_password
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-rootpass}
      - MYSQL_DATABASE=${DB_NAME:-push_notifications}
      - MYSQL_USER=${DB_USER:-pushuser}
      - MYSQL_PASSWORD=${DB_PASS:-pushpass}
    volumes:
      - mysql-data:/var/lib/mysql
      - ../sql:/docker-entrypoint-initdb.d:ro
    ports:
      - "3306:3306"
    networks:
      - push-network

  redis:
    image: redis:7-alpine
    volumes:
      - redis-data:/data
    networks:
      - push-network

  worker:
    build:
      context: ./php
      dockerfile: Dockerfile
    command: ["php", "/var/www/api/cli/worker.php"]
    volumes:
      - ../api:/var/www/api
    environment:
      - PUSH_BASE_URL=${PUSH_BASE_URL:-https://push.minifytool.com}
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_NAME=${DB_NAME:-push_notifications}
      - DB_USER=${DB_USER:-pushuser}
      - DB_PASS=${DB_PASS:-pushpass}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - ENCRYPTION_KEY=${ENCRYPTION_KEY:-changeme32characterslongexactly}
      - APP_ENV=${APP_ENV:-production}
    depends_on:
      - mysql
      - redis
    networks:
      - push-network
    deploy:
      replicas: 2

volumes:
  mysql-data:
  redis-data:

networks:
  push-network:
    driver: bridge
