version: "3.8"

networks:
  myapp_api:
    internal: false

services:
  web:
    image: nginx:latest
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - "./deploy/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro"
      - "./:/var/www/html:ro"
    ports:
      - "${WEB_PORT:-8051}:80"
    restart: always
    depends_on:
      - php
      - db
    networks:
      - myapp_api

  php:
    build:
      context: ./deploy/php
      dockerfile: Dockerfile
    restart: always
    #user: "${CURRENT_UID:-1000}:${CURRENT_UID:-1000}"
    environment:
      XDEBUG_SESSION: "1"
      XDEBUG_MODE: "debug,coverage"
      XDEBUG_CONFIG: "client_host=host.docker.internal client_port=9008"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - "./:/var/www/html"
    ports:
      - "9009:9009"
    networks:
      - myapp_api

  cron:
    build:
      context: .
      dockerfile: deploy/php/cron.Dockerfile
    volumes:
      - "./:/var/www/html"
    entrypoint: ["cron", "-f"]
    depends_on:
      - php
      - db
    networks:
      - myapp_api

  myadmin:
    image: phpmyadmin/phpmyadmin
    env_file:
      - ".env"
    ports:
      - "${ADMIN_PORT:-8041}:80"
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOST=db
      - PMA_USER=root
      - PMA_PASSWORD=
    restart: always
    depends_on:
      - db
    networks:
      - myapp_api

  db:
    image: mysql:8.0
    restart: always
    env_file:
      - ".env"
    ports:
      - "${DB_EXTERNAL_PORT}:3306"
    environment:
      - MYSQL_DATABASE=${DB_DATABASE}
      - MYSQL_USER=${DB_USERNAME}
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - MYSQL_ALLOW_EMPTY_PASSWORD=1
    volumes:
      - "mysql_data:/var/lib/mysql"
      - "./tests/resources/initdb.sql:/docker-entrypoint-initdb.d/initdb.sql"
    networks:
      - myapp_api

volumes:
  mysql_data:
