tt
Some checks failed
Koori-ERP-Demo-Deploy / sync-update (push) Failing after 2s

This commit is contained in:
2026-01-05 17:06:04 +08:00
parent 6ecb513bb0
commit cda5650962
2 changed files with 70 additions and 37 deletions

View File

@@ -0,0 +1,60 @@
name: Koori-ERP-Demo-Deploy
on:
push:
branches:
- main
jobs:
sync-update:
runs-on: demo-server
steps:
# - name: 1. Checkout New Code
# uses: actions/checkout@v3
# with:
# github-server-url: http://192.168.0.103:3000
# repository: ${{ gitea.repository }}
- name: 1. Checkout New Code
run: |
# 進入工作目錄並直接用 git 抓 code完全不需要 Node
rm -rf ./*
git clone -b demo http://server:3000/${{ gitea.repository }}.git .
- name: 2. Sync Files to Running Container
run: |
# A. 執行複製
cp .env.example .env
sed -i "s|APP_KEY=.*|APP_KEY=${{ secrets.APP_KEY }}|g" .env
# B. 確保容器環境是最新的
# --wait 會確保容器真的跑起來了才執行下一步
docker compose -p koori-erp up -d --build --force-recreate --wait
# C. 執行精簡化複製 (關鍵優化!)
# 排除 .git, node_modules, vendor 這三大黑洞
tar --exclude='.git' \
--exclude='node_modules' \
--exclude='vendor' \
-cf - . | docker exec -i koori-erp-laravel.test-1 tar -xf - -C /var/www/html
- name: 3. Refresh Backend (Only if needed)
run: |
# 執行 Composer (確保你有加新套件的話會抓到)
docker exec -w /var/www/html koori-erp-laravel.test-1 composer install --optimize-autoloader
# 同步資料庫欄位 (如果你有改 Migration 的話)
docker exec koori-erp-laravel.test-1 php artisan migrate --force
- name: 4. Build New React Assets
run: |
# 既然你改了前端,就要在容器內重新跑一次打包
docker exec -w /var/www/html koori-erp-laravel.test-1 npm install
docker exec -w /var/www/html koori-erp-laravel.test-1 npm run build
- name: 5. Final Permission Fix
run: |
# 統一修正權限
docker exec koori-erp-laravel.test-1 chown -R 1000:1000 /var/www/html
docker exec koori-erp-laravel.test-1 chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
- name: 6. Clear Old Cache
run: |
# 讓 Laravel 重新讀取最新的路由與設定
docker exec koori-erp-laravel.test-1 php artisan view:clear
docker exec koori-erp-laravel.test-1 php artisan config:clear
docker exec koori-erp-laravel.test-1 php artisan route:clear

View File

@@ -15,46 +15,19 @@ jobs:
# repository: ${{ gitea.repository }}
- name: 1. Checkout New Code
run: |
# 進入工作目錄並直接用 git 抓 code完全不需要 Node
rm -rf ./*
git clone -b demo http://server:3000/${{ gitea.repository }}.git .
cd ~/koori-erp
git pull origin main # 直接在宿主機更新
- name: 2. Sync Files to Running Container
- name: 2. Restart Containers
run: |
# A. 執行複製
cd ~/koori-erp
cp .env.example .env
sed -i "s|APP_KEY=.*|APP_KEY=${{ secrets.APP_KEY }}|g" .env
# B. 確保容器環境是最新的
# --wait 會確保容器真的跑起來了才執行下一步
docker compose -p koori-erp up -d --build --force-recreate --wait
docker compose -p koori-erp up -d --force-recreate --wait
# 檔案會自動同步,不需要 tar 複製!
# C. 執行精簡化複製 (關鍵優化!)
# 排除 .git, node_modules, vendor 這三大黑洞
tar --exclude='.git' \
--exclude='node_modules' \
--exclude='vendor' \
-cf - . | docker exec -i koori-erp-laravel.test-1 tar -xf - -C /var/www/html
- name: 3. Refresh Backend (Only if needed)
- name: 3. Install Dependencies
run: |
# 執行 Composer (確保你有加新套件的話會抓到)
docker exec -w /var/www/html koori-erp-laravel.test-1 composer install --optimize-autoloader
# 同步資料庫欄位 (如果你有改 Migration 的話)
docker exec koori-erp-laravel.test-1 php artisan migrate --force
- name: 4. Build New React Assets
run: |
# 既然你改了前端,就要在容器內重新跑一次打包
docker exec -w /var/www/html koori-erp-laravel.test-1 composer install --no-dev
docker exec -w /var/www/html koori-erp-laravel.test-1 npm install
docker exec -w /var/www/html koori-erp-laravel.test-1 npm run build
- name: 5. Final Permission Fix
run: |
# 統一修正權限
docker exec koori-erp-laravel.test-1 chown -R 1000:1000 /var/www/html
docker exec koori-erp-laravel.test-1 chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
- name: 6. Clear Old Cache
run: |
# 讓 Laravel 重新讀取最新的路由與設定
docker exec koori-erp-laravel.test-1 php artisan view:clear
docker exec koori-erp-laravel.test-1 php artisan config:clear
docker exec koori-erp-laravel.test-1 php artisan route:clear