#!/bin/bash
# eCert MBIP — Production Deploy Script
# Dipanggil oleh webhook selepas git push ke GitHub
set -e

PROJECT_DIR="/srv/ecert"
LOG="$PROJECT_DIR/deploy.log"

log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG"; }

log "=== Deploy dimulakan ==="

cd "$PROJECT_DIR"

log "git pull..."
git pull origin master

log "migrate database..."
docker exec ecert_app php artisan migrate --force

log "optimize cache..."
docker exec ecert_app php artisan optimize

log "restart queue worker..."
docker restart ecert_queue

log "=== Deploy selesai ==="
