# Anagram Finder — self-hosting stack.
#
# Copy .env.example to .env, set APP_KEY and the database passwords, then:
#   docker compose up -d
#
# The app binds to 127.0.0.1 only. Put a reverse proxy in front of it for
# anything public-facing, and set APP_URL to the address people will use.

services:
  app:
    image: forge.lvl0.xyz/anagram-finder/web:latest
    container_name: anagram_app
    restart: unless-stopped
    ports:
      - "127.0.0.1:8000:8000"
    environment:
      APP_NAME: "Anagram Finder"
      APP_ENV: production
      APP_DEBUG: "false"
      APP_KEY: "${APP_KEY}"
      APP_URL: "${APP_URL:-http://localhost:8000}"
      DB_CONNECTION: mariadb
      DB_HOST: db
      DB_PORT: "3306"
      DB_DATABASE: "${DB_DATABASE:-anagram}"
      DB_USERNAME: "${DB_USERNAME:-anagram}"
      DB_PASSWORD: "${DB_PASSWORD}"
      SESSION_DRIVER: database
      CACHE_STORE: database
      QUEUE_CONNECTION: database
    # A plain dependency, not condition: service_healthy — podman-compose 1.5.0
    # hangs waiting on that. The app's start script polls for the database itself.
    depends_on:
      - db
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:8000/up"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - anagram

  db:
    image: mariadb:11
    container_name: anagram_db
    restart: unless-stopped
    environment:
      MARIADB_DATABASE: "${DB_DATABASE:-anagram}"
      MARIADB_USER: "${DB_USERNAME:-anagram}"
      MARIADB_PASSWORD: "${DB_PASSWORD}"
      MARIADB_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
    volumes:
      - db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    networks:
      - anagram

networks:
  anagram:
    driver: bridge

volumes:
  db_data:
