# ─────────────────────────────────────────────────────────────────────────────
# Nexus Repository Manager OSS — single pull-through mirror for everything
# ─────────────────────────────────────────────────────────────────────────────
# FIRST-TIME SETUP (run once after starting):
#   docker compose -f docker-compose.mirror.yml up -d
#   ./mirrors/nexus/provision.sh          # creates all proxy repos + enables anon access
#
# Endpoints (after provisioning):
#   UI     →  http://SERVER_IP:8081       (admin / see provision.sh output)
#   NuGet  →  http://SERVER_IP:8081/repository/nuget-proxy/index.json
#   npm    →  http://SERVER_IP:8081/repository/npm-proxy/
#   Docker →  http://SERVER_IP:5000        (add to /etc/docker/daemon.json)
#
# Memory: needs ~2 GB JVM heap — recommended on a server with 4 GB+ total RAM.
# Adjust INSTALL4J_ADD_VM_PARAMS below if your server has more/less RAM.
# ─────────────────────────────────────────────────────────────────────────────

services:
  nexus:
    image: sonatype/nexus3:latest
    container_name: meezi-mirror-nexus
    restart: unless-stopped
    environment:
      # Heap: Xmx = max Java heap. MaxDirectMemorySize = off-heap (blob cache).
      # Total Nexus RAM ≈ Xmx + MaxDirectMemorySize + ~512 MB OS/JVM overhead.
      # 4 GB server: values below  (2 GB heap + 1 GB off-heap + 512 MB overhead ≈ 3.5 GB)
      # 8 GB server: -Xms1g -Xmx4g -XX:MaxDirectMemorySize=2g
      INSTALL4J_ADD_VM_PARAMS: "-Xms512m -Xmx2g -XX:MaxDirectMemorySize=1g -Djava.util.prefs.userRoot=/nexus-data/javaprefs"
    volumes:
      - nexus-data:/nexus-data
    ports:
      - "8081:8081"   # Web UI + NuGet + npm REST API
      - "5000:5000"   # Docker Hub proxy  (docker-hub-proxy repo  httpPort: 5000)
      - "5002:5002"   # MCR proxy         (mcr-proxy repo          httpPort: 5002)
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:8081/service/rest/v1/status"]
      interval: 30s
      timeout: 15s
      retries: 10
      start_period: 120s   # Nexus JVM startup takes ~2 min on first boot

volumes:
  nexus-data:
    name: meezi-mirror-nexus-data
