π Deploy Laravel + Vue Lebih Cepat dengan Bash Script (Alternatif CI/CD)
Hai, saya Eko, Web Developer dan pengguna laravel. Kali ini saya akan berbagi pengalaman tentang proses Deploy aplikasi di server production. Alih-alih menggunakan CI/CD saya memilih alternatif lain yaitu βBash Scriptβ
Kenapa saya pilih Bash Script?
Karena malas setup CI/CD, cari yang simple dan just work. Siapkan scriptnya, run script, beres.
Memang setup CI/CD adalah investasi jangka panjang, ribet di awal setelahnya sudah otomatis jalan.
π Buat file script
Section titled βπ Buat file scriptβMisalnya:
/home/user/scripts/deploy-app.shπ§ Full Script Deploy (Versi Generic)
Section titled βπ§ Full Script Deploy (Versi Generic)β#!/bin/bash
APP_DIR="/var/www/my-awesome-app"BRANCH="main"LOCKFILE="/tmp/deploy-app.lock"LOGFILE="/home/user/scripts/deploy-app.log"
set -e
if [ -f "$LOCKFILE" ]; then echo "Deploy sedang berjalan!" exit 1fi
trap "rm -f $LOCKFILE" EXITtouch $LOCKFILE
exec > >(tee -i $LOGFILE)exec 2>&1
echo "π Deploy started at $(date)"
cd $APP_DIR
echo "π₯ Pull latest code..."git pull origin $BRANCH
echo "π¦ Install PHP dependencies..."composer install --no-dev --optimize-autoloader
echo "π¦ Install JS dependencies..."pnpm install --frozen-lockfile
echo "π Build frontend..."pnpm build
echo "π Run migration..."php artisan migrate --force
echo "βοΈ Clear cache..."php artisan optimize:clear
echo "β‘ Optimize..."php artisan optimize
echo "π Reset permission cache..."php artisan permission:cache-reset
echo "β° Run scheduler..."php artisan schedule:run
echo "π Restart supervisor..."sudo supervisorctl restart all
echo "β
Deploy selesai $(date)"π§ Setup
Section titled βπ§ Setupβ1. Beri permission
Section titled β1. Beri permissionβchmod +x /home/user/scripts/deploy-app.sh2. Jalankan
Section titled β2. Jalankanβ/home/user/scripts/deploy-app.shDan semua berjalan dengan aman.
Oh ya ada tips lagi biar lebih gampang, yaitu tambahkan alias:
Tambahkan alias:
alias deploy-app="/home/user/scripts/deploy-app.sh"Sekarang cukup:
deploy-app