services:
  database:
    image: mysql:8.0
    container_name: cepage-database
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: cepage
      MYSQL_USER: app
      MYSQL_PASSWORD: app
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "3306:3306"
    volumes:
      - cepage-mysql-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "app", "-papp"]
      interval: 5s
      timeout: 3s
      retries: 15

  php:
    build:
      context: ./docker/php
    container_name: cepage-php
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - ./:/var/www/html
    environment:
      DATABASE_URL: "mysql://app:app@database:3306/cepage?serverVersion=8.0.36&charset=utf8mb4"
    depends_on:
      database:
        condition: service_healthy

  caddy:
    image: caddy:2-alpine
    container_name: cepage-caddy
    restart: unless-stopped
    ports:
      - "8090:80"
    volumes:
      - ./docker/Caddyfile:/etc/caddy/Caddyfile
      - ./:/var/www/html
    depends_on:
      - php

  adminer:
    image: adminer:latest
    container_name: cepage-adminer
    restart: unless-stopped
    ports:
      - "8080:8080"
    depends_on:
      - database

volumes:
  cepage-mysql-data:
