# =============================================================================
# LOCAL development stack for the EFET backend — replaces Lando.
#
#   docker compose up -d --build          # app + db + mailhog
#   open http://localhost:8080/admin      # backoffice
#   open http://localhost:8025            # MailHog (catches outgoing mail)
#   docker compose --profile assets up -d node   # optional: watch/compile assets
#
# The container reads the bind-mounted .env for app secrets (APP_KEY, recaptcha,
# ...). The values below are set as real env vars and, thanks to Laravel's
# immutable dotenv, take precedence over .env for infra hostnames only — so the
# existing .env keeps working unchanged.
# =============================================================================
services:
  app:
    build:
      context: .
      target: dev
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      APP_ENV: local
      APP_DEBUG: "true"
      AUTO_MIGRATE: "false"          # run migrations manually in dev
      DB_HOST: db
      DB_PORT: "3306"
      DB_DATABASE: base_cms_db
      DB_USERNAME: lando
      DB_PASSWORD: lando
      MAIL_DRIVER: smtp
      MAIL_HOST: mailhog
      MAIL_PORT: "1025"
    volumes:
      - .:/var/www/html
    ports:
      - "8080:80"

  db:
    image: mysql:8.0
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: base_cms_db
      MYSQL_USER: lando
      MYSQL_PASSWORD: lando
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - db_data:/var/lib/mysql
    ports:
      - "3307:3306"                  # same host port Lando used
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-proot"]
      interval: 10s
      timeout: 5s
      retries: 15

  mailhog:
    image: mailhog/mailhog
    restart: unless-stopped
    ports:
      - "8025:8025"                  # web UI; SMTP on 1025 within the network

  # Optional: compile the legacy laravel-mix assets in watch mode.
  # Enable with:  docker compose --profile assets up -d node
  # node:16 on purpose — webpack 4 crashes on Node 17+ (ERR_OSSL_EVP_UNSUPPORTED).
  # Remember to commit public/js + public/css: they are shipped as-is on deploy.
  node:
    image: node:16
    working_dir: /app
    volumes:
      - .:/app
    command: sh -c "yarn install && yarn watch"
    profiles: ["assets"]

volumes:
  db_data:
