# Baskit Ops — local development stack.
# Postgres runs in a container (data persisted in a named volume).
# The app runs the same production image, with source bind-mounted for
# live editing and migrations run on boot.

services:
  db:
    image: postgres:16-alpine
    container_name: baskit_db
    environment:
      POSTGRES_DB: ${DB_DATABASE:-baskit_ops}
      POSTGRES_USER: ${DB_USERNAME:-baskit}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-baskit_secret}
    ports:
      - "${DB_PORT_HOST:-55432}:5432"
    volumes:
      - baskit_pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME:-baskit} -d ${DB_DATABASE:-baskit_ops}"]
      interval: 5s
      timeout: 5s
      retries: 10

  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: baskit_app
    depends_on:
      db:
        condition: service_healthy
    # Plain, shell-safe names (no dots): entrypoint maps these to CI4 dotted .env keys.
    environment:
      CI_ENVIRONMENT: ${CI_ENVIRONMENT:-development}
      RUN_MIGRATIONS: "true"
      APP_BASEURL: ${APP_BASEURL:-http://localhost:8080/}
      DB_HOST: db
      DB_NAME: ${DB_DATABASE:-baskit_ops}
      DB_USER: ${DB_USERNAME:-baskit}
      DB_PASS: ${DB_PASSWORD:-baskit_secret}
      DB_DRIVER: Postgre
      DB_PORT: "5432"
      ENCRYPTION_KEY: ${ENCRYPTION_KEY:-}
      INGEST_SERVICE_KEY: ${INGEST_SERVICE_KEY:-dev-ingest-key-3f9c2a}
      INGEST_ALLOWED_IPS: ${INGEST_ALLOWED_IPS:-}
      JWT_SECRET: ${JWT_SECRET:-development-picker-jwt-secret-change-before-production}
      JWT_ACCESS_TTL: ${JWT_ACCESS_TTL:-900}
      JWT_REFRESH_TTL: ${JWT_REFRESH_TTL:-2592000}
      EMAIL_PROTOCOL: ${EMAIL_PROTOCOL:-smtp}
      SMTP_HOST: ${SMTP_HOST:-mailpit}
      SMTP_USER: ${SMTP_USER:-}
      SMTP_PASS: ${SMTP_PASS:-}
      SMTP_PORT: ${SMTP_PORT:-1025}
      SMTP_TIMEOUT: ${SMTP_TIMEOUT:-10}
      SMTP_CRYPTO: ${SMTP_CRYPTO:-}
      EMAIL_FROM: ${EMAIL_FROM:-no-reply@baskit.local}
      EMAIL_FROM_NAME: ${EMAIL_FROM_NAME:-Baskit Ops}
    ports:
      - "${APP_PORT_HOST:-8080}:80"
    volumes:
      # Live-edit source in dev; writable is left inside the container
      - ./app:/var/www/html/app
      - ./public:/var/www/html/public
      - ./work_scripts:/var/www/html/work_scripts:ro
      - ./docker/php/dev.ini:/usr/local/etc/php/conf.d/zzz-dev.ini:ro

  # Lightweight DB browser for development (http://localhost:8081)
  adminer:
    image: adminer:latest
    container_name: baskit_adminer
    depends_on:
      - db
    ports:
      - "${ADMINER_PORT_HOST:-8081}:8080"
    profiles: ["tools"]

  mailpit:
    image: axllent/mailpit:latest
    container_name: baskit_mailpit
    ports:
      - "${MAILPIT_UI_PORT_HOST:-8025}:8025"
    profiles: ["tools"]

volumes:
  baskit_pgdata:
