version: "3.8"

# NMC Knowledge Base — Outline (Self-Hosted)
# Spun up Apr 2, 2026
# Docs: https://app.getoutline.com/s/hosting
#
# To start:  docker compose up -d
# To stop:   docker compose down
# To wipe:   docker compose down -v  (DESTROYS ALL DATA)
# Logs:      docker compose logs -f outline

services:

  # ── Outline web app ─────────────────────────────────────────────────────────
  outline:
    image: outlinewiki/outline:0.80.2
    container_name: nmc-outline
    restart: unless-stopped
    ports:
      - "3300:3000"
    env_file: .env
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
      storage:
        condition: service_started
    volumes:
      - outline-data:/var/lib/outline/data
    networks:
      - outline-net

  # ── PostgreSQL ───────────────────────────────────────────────────────────────
  postgres:
    image: postgres:15-alpine
    container_name: nmc-outline-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: outline
      POSTGRES_USER: outline
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - pg-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U outline"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - outline-net

  # ── Redis ────────────────────────────────────────────────────────────────────
  redis:
    image: redis:7-alpine
    container_name: nmc-outline-redis
    restart: unless-stopped
    command: redis-server --requirepass ${REDIS_PASSWORD}
    volumes:
      - redis-data:/data
    networks:
      - outline-net

  # ── MinIO (S3-compatible file storage) ───────────────────────────────────────
  storage:
    image: minio/minio:latest
    container_name: nmc-outline-storage
    restart: unless-stopped
    command: server /data --console-address ":9001"
    ports:
      - "9000:9000"   # S3 API
      - "9001:9001"   # MinIO web console (optional, access via localhost)
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
    volumes:
      - minio-data:/data
    networks:
      - outline-net

  # ── MinIO bucket init (runs once, then exits) ────────────────────────────────
  createbuckets:
    image: minio/mc:latest
    container_name: nmc-outline-createbuckets
    depends_on:
      - storage
    entrypoint: >
      /bin/sh -c "
        sleep 5;
        mc alias set local http://storage:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD};
        mc mb --ignore-existing local/outline;
        mc anonymous set download local/outline;
        exit 0;
      "
    networks:
      - outline-net

volumes:
  outline-data:
  pg-data:
  redis-data:
  minio-data:

networks:
  outline-net:
    driver: bridge
