# Shiplet — Express + Docker example
# Generated by: npx shiplet init --template express --runtime docker --yes
#
# Usage:
#   shiplet up -d          Start everything
#   shiplet shell          Shell into app
#   shiplet npm install    Install dependencies
#   shiplet db             Open psql CLI
#   shiplet logs -f        Follow logs

name: shiplet-express

services:
  # ── Application ─────────────────────────────────────────────────────────────
  app:
    build:
      context: .
      dockerfile: .shiplet/Dockerfile
      args:
        NODE_VERSION: "20"
        PACKAGE_MANAGER: "npm"
        TZ: "UTC"
    image: shiplet-express/app
    extra_hosts:
      - "host.docker.internal:host-gateway"
    ports:
      - "${APP_PORT:-3000}:3000"
    volumes:
      - ".:/var/www/html"
      - "shiplet_node_modules:/var/www/html/node_modules"
    networks:
      - shiplet
    environment:
      NODE_ENV:     "${NODE_ENV:-development}"
      TZ:           "${TZ:-UTC}"
      DATABASE_URL: "postgresql://${POSTGRES_USER:-shiplet}:${POSTGRES_PASSWORD:-secret}@postgres:5432/${POSTGRES_DB:-app}"
      REDIS_URL:    "redis://redis:6379"
      SMTP_HOST:    "mailpit"
      SMTP_PORT:    "1025"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    command: npm run dev
    restart: unless-stopped
    tty: true
    stdin_open: true

  # ── PostgreSQL ───────────────────────────────────────────────────────────────
  postgres:
    image: "postgres:16-alpine"
    environment:
      POSTGRES_USER:     "${POSTGRES_USER:-shiplet}"
      POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:-secret}"
      POSTGRES_DB:       "${POSTGRES_DB:-app}"
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    volumes:
      - "postgres_data:/var/lib/postgresql/data"
      - "./.shiplet/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql:ro"
    networks:
      - shiplet
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-shiplet}"]
      interval: 5s
      timeout: 5s
      retries: 10

  # ── Redis ────────────────────────────────────────────────────────────────────
  redis:
    image: "redis:7-alpine"
    ports:
      - "${REDIS_PORT:-6379}:6379"
    networks:
      - shiplet
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      retries: 10

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

  # ── Adminer (DB GUI) ─────────────────────────────────────────────────────────
  adminer:
    image: "adminer"
    ports:
      - "${ADMINER_PORT:-8080}:8080"
    networks:
      - shiplet

volumes:
  shiplet_node_modules:
    driver: local
  postgres_data:
    driver: local

networks:
  shiplet:
    driver: bridge
