version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: codex-app
    restart: unless-stopped
    working_dir: /app
    volumes:
      - ./:/app
      - ./storage:/app/storage
    ports:
      - "8080:80"
    environment:
      APP_ENV: development
      DB_HOST: database
      DB_NAME: saas_barbearia
      DB_USER: codex_user
      DB_PASS: codex_password
    depends_on:
      - database
    networks:
      - codex

  database:
    image: mysql:8.0
    container_name: codex-db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: saas_barbearia
      MYSQL_USER: codex_user
      MYSQL_PASSWORD: codex_password
    ports:
      - "3306:3306"
    volumes:
      - ./database/mysql:/var/lib/mysql
    networks:
      - codex
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      timeout: 20s
      retries: 10

  phpmyadmin:
    image: phpmyadmin:latest
    container_name: codex-phpmyadmin
    restart: unless-stopped
    environment:
      PMA_HOST: database
      PMA_USER: codex_user
      PMA_PASSWORD: codex_password
    ports:
      - "8081:80"
    depends_on:
      - database
    networks:
      - codex

networks:
  codex:
    driver: bridge
