Files
star-erp/.gitea/workflows/deploy-demo.yaml
sky121113 747f70865d
Some checks failed
ERP-Deploy-Demo / deploy-demo (push) Failing after 24s
ERP-Deploy-Production / deploy-production (push) Successful in 58s
修正 CI/CD 部署後 npm run build 殘留的 public/hot 導致 Vite HMR 及 CORS 報錯問題
2026-02-23 16:02:40 +08:00

101 lines
3.6 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: ERP-Deploy-Demo
on:
push:
branches:
- demo
jobs:
deploy-demo:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
github-server-url: https://gitea.taiwan-star.com.tw
repository: ${{ github.repository }}
- name: Step 1 - Push Code to Demo
run: |
apt-get update && apt-get install -y rsync openssh-client
mkdir -p ~/.ssh
echo "${{ secrets.DEMO_SSH_KEY }}" > ~/.ssh/id_rsa_demo
chmod 600 ~/.ssh/id_rsa_demo
rsync -avz --delete \
--exclude='.git' \
--exclude='node_modules' \
--exclude='vendor' \
--exclude='storage' \
--exclude='.env' \
--exclude='public/build' \
-e "ssh -p 2227 -i ~/.ssh/id_rsa_demo -o StrictHostKeyChecking=no" \
./ root@220.132.7.82:/var/www/star-erp-demo/
rm ~/.ssh/id_rsa_demo
- name: Step 2 - Check if Rebuild Needed
id: check_rebuild
uses: appleboy/ssh-action@master
with:
host: 220.132.7.82
port: 2227
username: root
key: ${{ secrets.DEMO_SSH_KEY }}
script: |
cd /var/www/star-erp-demo
if git diff --name-only HEAD~1 HEAD 2>/dev/null | grep -qE '(Dockerfile|compose\.yaml|docker-compose\.yaml)'; then
echo "REBUILD_NEEDED=true"
else
echo "REBUILD_NEEDED=false"
fi
- name: Step 3 - Container Up & Health Check
uses: appleboy/ssh-action@master
with:
host: 220.132.7.82
port: 2227
username: root
key: ${{ secrets.DEMO_SSH_KEY }}
script: |
cd /var/www/star-erp-demo
chown -R 1000:1000 .
if git diff --name-only HEAD~1 HEAD 2>/dev/null | grep -qE '(Dockerfile|compose\.yaml|docker-compose\.yaml)'; then
echo "🔄 偵測到 Docker 相關檔案變更,執行完整重建..."
WWWGROUP=1000 WWWUSER=1000 docker compose up -d --build --wait
else
echo "⚡ 無 Docker 檔案變更,僅重載服務..."
if ! docker ps --format '{{.Names}}' | grep -q 'star-erp-laravel'; then
echo "容器未運行,正在啟動..."
WWWGROUP=1000 WWWUSER=1000 docker compose up -d --wait
else
echo "容器已運行,跳過 docker compose直接進行程式碼部署..."
fi
fi
echo "容器狀態:" && docker ps --filter "name=star-erp-laravel"
- name: Step 4 - Composer & NPM Build
uses: appleboy/ssh-action@master
with:
host: 220.132.7.82
port: 2227
username: root
key: ${{ secrets.DEMO_SSH_KEY }}
script: |
docker exec -u 1000:1000 -w /var/www/html star-erp-laravel sh -c "
composer install --no-dev --optimize-autoloader --no-interaction &&
npm install &&
npm run build &&
rm -f public/hot &&
php artisan storage:link &&
php artisan migrate --force &&
php artisan tenants:migrate --force &&
php artisan db:seed --force &&
php artisan tenants:run db:seed --option=\"class=PermissionSeeder\" --option=\"force=true\" &&
php artisan permission:cache-reset &&
php artisan optimize:clear &&
php artisan optimize &&
php artisan view:cache
"
docker exec star-erp-laravel chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache