
version: '3.7'

services:
  php:
    build:
      context: ..
      dockerfile: docker/php/Dockerfile
    container_name: escapepage-php
    volumes:
      - ../:/var/www/html:delegated
    environment:
      APP_ENV: ${APP_ENV:-dev}
    depends_on:
      - database
      - mercure
    networks:
      - backend
    restart: unless-stopped

  php-worker:
    build:
      context: ..
      dockerfile: docker/php/Dockerfile
    container_name: escapepage-php-worker
    volumes:
      - ../:/var/www/html:delegated
    environment:
      APP_ENV: ${APP_ENV:-dev}
    depends_on:
      - database
      - mercure
    command: ["php", "bin/console", "messenger:consume", "async", "-vv"]
    networks:
      - backend
    restart: unless-stopped

  nginx:
    image: nginx:1.29.4-alpine
    container_name: escapepage-nginx
    ports:
      - "8080:80"
    volumes:
      - ../:/var/www/html:ro
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - php
    networks:
      - backend
    restart: unless-stopped

  mailer:
    image: axllent/mailpit:latest
    container_name: escapepage-mailer
    ports:
      - "8025:8025"
    networks:
      - backend
    restart: unless-stopped

  mercure:
    image: dunglas/mercure:v0.21
    container_name: escapepage-mercure
    environment:
      SERVER_NAME: ":80"
      MERCURE_PUBLISHER_JWT_KEY: ${MERCURE_JWT_SECRET}
      MERCURE_SUBSCRIBER_JWT_KEY: ${MERCURE_JWT_SECRET}
      MERCURE_CORS_ALLOWED_ORIGINS: ${MERCURE_CORS_ALLOWED_ORIGINS:-http://localhost:8080}
      MERCURE_PUBLISH_ALLOWED_ORIGINS: ${MERCURE_CORS_ALLOWED_ORIGINS:-http://localhost:8080}
      MERCURE_EXTRA_DIRECTIVES: |
        cors_origins ${MERCURE_CORS_ALLOWED_ORIGINS:-http://localhost:8080}
        # Allow anonymous subscribers in dev only
        anonymous
    ports:
      - "8090:80"
    networks:
      - backend
    restart: unless-stopped

###> doctrine/doctrine-bundle ###
  database:
    image: mysql:8.0
    container_name: escapepage-db
    environment:
      MYSQL_DATABASE: ${DB_NAME:-app}
      MYSQL_USER: ${DB_USER:-app}
      MYSQL_PASSWORD: ${DB_PASSWORD:-!ChangeMe!}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-p${MYSQL_ROOT_PASSWORD:-root}"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 30s
    command: ["--default-authentication-plugin=mysql_native_password", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
    volumes:
      - database_data:/var/lib/mysql:rw
    # Uncomment the two lines below if you need to access MySQL from your host (workbench, etc.)
    # ports:
    #   - "3306:3306"
    networks:
      - backend
    restart: unless-stopped
###< doctrine/doctrine-bundle ###

volumes:
###> doctrine/doctrine-bundle ###
  database_data:
###< doctrine/doctrine-bundle ###

networks:
  backend:
    driver: bridge
