services:
  server:
    build:
      context: ./docker_nginx
      dockerfile: Dockerfile
      args:
        - UID=${UID:-1000}
        - GID=${GID:-1000}
    ports:
      - "80:80"
    depends_on:
      - backend
      - frontend

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
      args:
        - UID=${UID:-1000}
        - GID=${GID:-1000}
    depends_on:
      db:
        condition: service_healthy
    environment:
      - DB_HOST=db
      - DB_USER=user
      - DB_PASSWORD=password
      - DB_DATABASE=mydb
    volumes:
      - laravel-storage:/var/www/html/storage

  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: mydb
      MYSQL_USER: user
      MYSQL_PASSWORD: password
    volumes:
      - db-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "-p${MYSQL_ROOT_PASSWORD}"]
      timeout: 15s
      retries: 10
  
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
      args:
        - UID=${UID:-1000}
        - GID=${GID:-1000}
  
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    environment:
      PMA_HOST: db
      PMA_USER: user
      PMA_PASSWORD: password
    ports:
      - "8080:80"
    depends_on:
      - db

volumes:
  db-data:
  laravel-storage:
