# Compose file untuk deploy fork custom ini (termasuk modul Customes/*) sebagai
# Portainer Stack berbasis Git repository.
#
# Cara pakai di Portainer:
#   1. Stacks > Add stack > Build method: Repository
#   2. Isi Repository URL + branch (mis. features/4agustus2026/feat/print-label-br atau master)
#   3. Compose path: docker-compose.portainer.yml
#   4. Isi bagian "Environment variables" di Portainer dengan minimal:
#        APP_KEY, APP_URL, DB_PASSWORD, MYSQL_ROOT_PASSWORD
#      (lihat .env.docker di root repo utk daftar lengkap variable yg tersedia)
#   5. Deploy the stack — Portainer akan build image dari Dockerfile repo ini.
#
# Catatan:
#   - `build:` hanya jalan di Docker standalone/agent environment, TIDAK didukung
#     di Portainer Swarm stack (Swarm tidak bisa build image).
#   - APP_KEY wajib diisi. Generate sekali dgn:
#       docker run --rm <image-yg-sudah-dibuild> php artisan key:generate --show
#     lalu tempel hasilnya (format base64:xxxx) ke Environment variables Portainer.

volumes:
  db_data:
  storage:

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    volumes:
      - storage:/var/lib/snipeit
    ports:
      - "${APP_PORT:-8000}:80"
    depends_on:
      db:
        condition: service_healthy
        restart: true
    environment:
      APP_ENV: ${APP_ENV:-production}
      APP_DEBUG: ${APP_DEBUG:-false}
      APP_KEY: ${APP_KEY}
      APP_URL: ${APP_URL}
      APP_TIMEZONE: ${APP_TIMEZONE:-UTC}
      APP_LOCALE: ${APP_LOCALE:-en-US}
      MAX_RESULTS: ${MAX_RESULTS:-500}

      PRIVATE_FILESYSTEM_DISK: ${PRIVATE_FILESYSTEM_DISK:-local}
      PUBLIC_FILESYSTEM_DISK: ${PUBLIC_FILESYSTEM_DISK:-local_public}

      DB_CONNECTION: mysql
      DB_HOST: db
      DB_PORT: 3306
      DB_DATABASE: ${DB_DATABASE:-snipeit}
      DB_USERNAME: ${DB_USERNAME:-snipeit}
      DB_PASSWORD: ${DB_PASSWORD}
      DB_PREFIX: ${DB_PREFIX:-null}
      DB_CHARSET: ${DB_CHARSET:-utf8mb4}
      DB_COLLATION: ${DB_COLLATION:-utf8mb4_unicode_ci}

      MAIL_MAILER: ${MAIL_MAILER:-smtp}
      MAIL_HOST: ${MAIL_HOST:-}
      MAIL_PORT: ${MAIL_PORT:-587}
      MAIL_USERNAME: ${MAIL_USERNAME:-}
      MAIL_PASSWORD: ${MAIL_PASSWORD:-}
      MAIL_FROM_ADDR: ${MAIL_FROM_ADDR:-}
      MAIL_FROM_NAME: ${MAIL_FROM_NAME:-Snipe-IT}
      MAIL_REPLYTO_ADDR: ${MAIL_REPLYTO_ADDR:-}
      MAIL_REPLYTO_NAME: ${MAIL_REPLYTO_NAME:-Snipe-IT}

      ALLOW_BACKUP_DELETE: ${ALLOW_BACKUP_DELETE:-false}
      ALLOW_DATA_PURGE: ${ALLOW_DATA_PURGE:-false}
      IMAGE_LIB: ${IMAGE_LIB:-gd}

      SESSION_LIFETIME: ${SESSION_LIFETIME:-12000}
      SECURE_COOKIES: ${SECURE_COOKIES:-false}
      LOG_CHANNEL: ${LOG_CHANNEL:-stderr}

  db:
    image: mariadb:11.5.2
    restart: unless-stopped
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-snipeit}
      MYSQL_USER: ${DB_USERNAME:-snipeit}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    healthcheck:
      # https://mariadb.com/kb/en/using-healthcheck-sh/#compose-file-example
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 5s
      timeout: 1s
      retries: 5
