This commit is contained in:
77
.gitea/workflows/deploy.yml
Normal file
77
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,77 @@
|
||||
name: Deploy to Production
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Deploy to server
|
||||
run: |
|
||||
echo "🚀 Deploying to /var/www/services/sena_db_api"
|
||||
echo "📁 Current directory: $(pwd)"
|
||||
echo "📁 GITHUB_WORKSPACE: $GITHUB_WORKSPACE"
|
||||
ls -la
|
||||
|
||||
# Create directory if it doesn't exist
|
||||
mkdir -p /var/www/services/sena_db_api
|
||||
|
||||
# Copy files to destination (runner đã mount /var/www)
|
||||
rsync -av --delete \
|
||||
--exclude 'node_modules' \
|
||||
--exclude '.git' \
|
||||
--exclude '.gitea' \
|
||||
--exclude 'logs' \
|
||||
--exclude 'uploads' \
|
||||
--exclude 'runner-data' \
|
||||
--exclude '.env' \
|
||||
--exclude 'docker-compose.runner.yml' \
|
||||
--exclude 'setup-runner.sh' \
|
||||
$GITHUB_WORKSPACE/ /var/www/services/sena_db_api/
|
||||
|
||||
echo "✅ Files copied successfully"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cd /var/www/services/sena_db_api
|
||||
echo "📦 Installing dependencies with pnpm..."
|
||||
pnpm install --production
|
||||
echo "✅ Dependencies installed"
|
||||
|
||||
- name: Create required directories
|
||||
run: |
|
||||
cd /var/www/services/sena_db_api
|
||||
mkdir -p logs uploads data
|
||||
echo "✅ Directories created"
|
||||
|
||||
- name: Restart PM2 service
|
||||
run: |
|
||||
echo "🔄 Restarting PM2 service..."
|
||||
|
||||
# Tạo trigger file để PM2 watcher restart service
|
||||
touch /var/www/services/sena_db_api/.pm2-restart-trigger
|
||||
|
||||
# Đợi watcher xử lý (tối đa 10s)
|
||||
for i in {1..5}; do
|
||||
if [ ! -f /var/www/services/sena_db_api/.pm2-restart-trigger ]; then
|
||||
echo "✅ PM2 service restarted"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "⚠️ Trigger file created, PM2 will restart shortly"
|
||||
|
||||
- name: Deployment completed
|
||||
run: |
|
||||
echo "✅ Deployment completed successfully!"
|
||||
echo "📍 Location: /var/www/services/sena_db_api"
|
||||
echo "🔧 PM2 service will restart within 2 seconds"
|
||||
Reference in New Issue
Block a user