services:
  postgres:
    image: postgres:16-alpine
    container_name: aegisone-postgres
    network_mode: host
    environment:
      POSTGRES_DB: aegisone
      POSTGRES_USER: aegisone
      POSTGRES_PASSWORD: aegisone_pass
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./sql/schema_postgresql.sql:/docker-entrypoint-initdb.d/01_schema.sql
      - ./sql/seed_data.sql:/docker-entrypoint-initdb.d/02_seed.sql
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U aegisone -h localhost"]
      interval: 10s
      timeout: 5s
      retries: 5

  app:
    build:
      context: .
      network: host
    container_name: aegisone-app
    network_mode: host
    environment:
      DATABASE_URL: postgresql+asyncpg://aegisone:aegisone_pass@localhost:5432/aegisone
      SECRET_KEY: ${SECRET_KEY:-change-me-to-random-string}
      SESSION_TTL: 3600
      APP_ENV: production
      LOG_LEVEL: info
      PORTAINER_URL: ${PORTAINER_URL:-http://81.177.141.34:9001}
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - ./docs:/app/docs
      - ./permissions:/app/permissions
      - ./uploads:/app/uploads
      - ./CHANGELOG.md:/app/CHANGELOG.md
      - ./version.txt:/app/version.txt
    restart: unless-stopped

volumes:
  pgdata:
