add CI CD setup

This commit is contained in:
Lutfi Hakim 2026-04-12 11:12:07 +07:00
parent dcf125fae0
commit 995aab004d
1 changed files with 46 additions and 0 deletions

46
.github/workflows/deploy.yml vendored Normal file
View File

@ -0,0 +1,46 @@
name: Auto Deploy Mancontani
on:
push:
branches:
- main
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Deployment Logic Mancontani
run: |
cd /www/wwwroot/mancontani
# 1. Ambil ID commit lama untuk deteksi perubahan
OLD_COMMIT=$(git rev-parse HEAD)
# 2. Tarik kode terbaru
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/sayasilvi/web-pertanian.git
git fetch -4 --all
git reset --hard origin/main
# 3. Ambil ID commit baru
NEW_COMMIT=$(git rev-parse HEAD)
# 4. Build dependencies (Container temporary)
docker run --rm -v $(pwd):/app -w /app composer:2 install --no-interaction --prefer-dist --optimize-autoloader --ignore-platform-reqs
# 5. Perbaikan permission untuk user www/docker (PUID 33)
# Sekalian fix untuk storage dan cache biar aman
chown -R 33:33 vendor/ storage/ bootstrap/cache/
chmod -R 775 storage/ bootstrap/cache/
# 6. Refresh cache Laravel
# REVISI: Menggunakan docker exec langsung ke nama container yang sedang jalan
docker exec mancontani-php-container php artisan optimize:clear
# 7. Deteksi otomatis migrasi database
if [ "$OLD_COMMIT" != "$NEW_COMMIT" ] && git diff --name-only $OLD_COMMIT $NEW_COMMIT | grep -q "^database/migrations/"; then
echo "🚀 Perubahan database terdeteksi! Menjalankan migrate..."
docker exec mancontani-php-container php artisan migrate --force
else
echo "✅ Tidak ada file migrasi baru. Skip migrate."
fi