# Shopnex + Postgres, for Dokploy (Compose service) or any `docker compose up -d`.
# Pulls the prebuilt image, so nothing is built on the server.
# Set the variables below in Dokploy's Environment tab, or in a .env file next to this one.
# Dokploy: add the domain under Domains with service `shopnex` and port 3000; it handles HTTPS.
services:
  shopnex:
    image: ghcr.io/shopnex-ai/shopnex:latest
    pull_policy: always
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      DATABASE_URL: postgres://shopnex:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@db:5432/shopnex
      APP_URL: ${APP_URL:?set APP_URL, e.g. https://shop.example.com}
      BETTER_AUTH_URL: ${APP_URL}
      # Optional: generated once and kept on the data volume when empty
      BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET:-}
      TENANCY_MODE: single
      DEFAULT_SHOP_NAME: ${DEFAULT_SHOP_NAME:-My Shop}
    volumes:
      - shopnex-data:/data
    expose:
      - "3000"
    healthcheck:
      test: ["CMD", "node", "-e", "fetch('http://localhost:3000/admin/login').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"]
      interval: 30s
      timeout: 5s
      start_period: 60s

  db:
    image: postgres:17
    restart: unless-stopped
    environment:
      POSTGRES_USER: shopnex
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: shopnex
    volumes:
      - db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U shopnex"]
      interval: 5s
      timeout: 5s
      retries: 10

volumes:
  shopnex-data:
  db-data:
