# Shiplet — Fastify + Podman example
# Generated by: npx shiplet init --template fastify --runtime podman --yes
#
# Podman notes:
#   • Rootless by default — no daemon needed
#   • Uses podman compose (≥4.7) or podman-compose
#   • "host.docker.internal" resolved via extra_hosts
#   • Healthchecks use same syntax as Docker Compose
#
# Usage:
#   SHIPLET_RUNTIME=podman shiplet up -d
#   shiplet shell
#   shiplet npm install
#   shiplet db mongo            # opens mongosh
#   shiplet db redis            # opens redis-cli
#   shiplet logs -f app

name: shiplet-fastify

services:
  # ── Application ─────────────────────────────────────────────────────────────
  app:
    build:
      context: .
      dockerfile: .shiplet/Dockerfile
      args:
        NODE_VERSION: "22"
        PACKAGE_MANAGER: "npm"
        TZ: "UTC"
    image: shiplet-fastify/app
    extra_hosts:
      - "host.docker.internal:host-gateway"
    ports:
      - "${APP_PORT:-3000}:3000"
      - "${SWAGGER_PORT:-3001}:3001"
    volumes:
      - ".:/var/www/html"
      - "shiplet_node_modules:/var/www/html/node_modules"
    networks:
      - shiplet
    environment:
      NODE_ENV:       "${NODE_ENV:-development}"
      TZ:             "${TZ:-UTC}"
      MONGODB_URI:    "mongodb://${MONGO_USER:-shiplet}:${MONGO_PASSWORD:-secret}@mongo:27017/${MONGO_DB:-app}?authSource=admin"
      REDIS_URL:      "redis://redis:6379"
      JWT_SECRET:     "${JWT_SECRET:-dev-secret-change-in-prod}"
      S3_ENDPOINT:    "http://minio:9000"
      S3_ACCESS_KEY:  "${MINIO_ROOT_USER:-shiplet}"
      S3_SECRET_KEY:  "${MINIO_ROOT_PASSWORD:-secretsecret}"
      S3_BUCKET:      "${MINIO_BUCKET:-uploads}"
      SMTP_HOST:      "mailpit"
      SMTP_PORT:      "1025"
    depends_on:
      mongo:
        condition: service_healthy
      redis:
        condition: service_healthy
    command: npm run dev
    restart: unless-stopped
    tty: true
    stdin_open: true

  # ── MongoDB ──────────────────────────────────────────────────────────────────
  mongo:
    image: "mongo:7"
    environment:
      MONGO_INITDB_ROOT_USERNAME: "${MONGO_USER:-shiplet}"
      MONGO_INITDB_ROOT_PASSWORD: "${MONGO_PASSWORD:-secret}"
      MONGO_INITDB_DATABASE:      "${MONGO_DB:-app}"
    ports:
      - "${MONGO_PORT:-27017}:27017"
    volumes:
      - "mongo_data:/data/db"
      - "./.shiplet/mongo/init.js:/docker-entrypoint-initdb.d/init.js:ro"
    networks:
      - shiplet
    healthcheck:
      test: ["CMD", "mongosh", "--quiet", "--eval", "db.adminCommand('ping')"]
      interval: 10s
      timeout: 5s
      retries: 10

  # ── Redis ────────────────────────────────────────────────────────────────────
  redis:
    image: "redis:7-alpine"
    command: redis-server --save 60 1 --loglevel warning
    ports:
      - "${REDIS_PORT:-6379}:6379"
    volumes:
      - "redis_data:/data"
    networks:
      - shiplet
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      retries: 10

  # ── MinIO (S3-compatible object storage) ──────────────────────────────────────
  minio:
    image: "minio/minio"
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER:     "${MINIO_ROOT_USER:-shiplet}"
      MINIO_ROOT_PASSWORD: "${MINIO_ROOT_PASSWORD:-secretsecret}"
    ports:
      - "${MINIO_PORT:-9000}:9000"
      - "${MINIO_CONSOLE_PORT:-9001}:9001"
    volumes:
      - "minio_data:/data"
    networks:
      - shiplet
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 10s
      retries: 5

  # ── Mailpit ───────────────────────────────────────────────────────────────────
  mailpit:
    image: "axllent/mailpit"
    ports:
      - "${MAILPIT_SMTP_PORT:-1025}:1025"
      - "${MAILPIT_UI_PORT:-8025}:8025"
    networks:
      - shiplet

  # ── Mongo Express (Mongo GUI) ──────────────────────────────────────────────
  mongo-express:
    image: "mongo-express"
    ports:
      - "${MONGO_EXPRESS_PORT:-8081}:8081"
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: "${MONGO_USER:-shiplet}"
      ME_CONFIG_MONGODB_ADMINPASSWORD: "${MONGO_PASSWORD:-secret}"
      ME_CONFIG_MONGODB_URL:           "mongodb://${MONGO_USER:-shiplet}:${MONGO_PASSWORD:-secret}@mongo:27017/"
      ME_CONFIG_BASICAUTH:             "false"
    networks:
      - shiplet
    depends_on:
      - mongo

volumes:
  shiplet_node_modules:
    driver: local
  mongo_data:
    driver: local
  redis_data:
    driver: local
  minio_data:
    driver: local

networks:
  shiplet:
    driver: bridge
