diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index d4baf8c..96c79f2 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -6,7 +6,7 @@ on: jobs: redeploy: - runs-on: host # 必須對應你註冊時填寫的 Label + runs-on: ubuntu-latest # 改成這個,對應你的 Runner 標籤 steps: - name: Sync and Deploy run: | @@ -14,18 +14,22 @@ jobs: echo "Deployment started at: $(date)" # 1. 進入專案目錄 - cd /home/ubuntu/apps/linebot_finance || exit 1 + cd /home/ubuntu/apps/linebot_finance || { echo "Directory not found"; exit 1; } - # 2. 從本地倉庫強制同步 (因為是 Host 模式,絕對讀得到路徑) - echo "Fetching from local gitea storage..." - git fetch --all + # 2. 同步代碼 + # 確保 git 知道它在一個安全目錄 (有時 Docker/Runner 權限會卡住) + git config --global --add safe.directory /home/ubuntu/apps/linebot_finance + + echo "Fetching latest code..." + git fetch origin main git reset --hard origin/main # 3. 重新啟動 Docker 容器 echo "Restarting Docker Compose..." - docker compose down - docker compose up -d --build - # 清理掉沒標籤的暫存鏡像 (dangling images) + # 使用 --remove-orphans 確保清理乾淨 + docker compose up -d --build --remove-orphans + + # 4. 清理沒用的鏡像 docker image prune -f - echo "Deployment successful!" \ No newline at end of file + echo "Deployment successful at: $(date)" \ No newline at end of file