mirror of
https://github.com/henry4682/linebot_finance.git
synced 2026-05-16 04:41:52 +00:00
This commit is contained in:
@@ -6,31 +6,38 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
redeploy:
|
redeploy:
|
||||||
runs-on: self-hosted # 請確認 Gitea Runner 標籤包含 self-hosted
|
runs-on: self-hosted # 你的 Runner 已經有這個標籤了,沒問題
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Preparation and Git Sync
|
||||||
# 如果是第一次運行,這步會自動處理目錄
|
|
||||||
run: |
|
run: |
|
||||||
|
# 建立目錄並進入
|
||||||
mkdir -p /home/ubuntu/apps/linebot_finance
|
mkdir -p /home/ubuntu/apps/linebot_finance
|
||||||
cd /home/ubuntu/apps/linebot_finance
|
cd /home/ubuntu/apps/linebot_finance
|
||||||
|
|
||||||
|
# 檢查是否已經有 .git,沒有就 clone,有就 reset
|
||||||
|
if [ ! -d ".git" ]; then
|
||||||
|
echo "🚚 正在初始化儲存庫..."
|
||||||
|
# 使用 http://localhost:3000 是因為你的 Runner 跟 Gitea 在同一台主機且用了 network host
|
||||||
|
git clone http://localhost:3000/henry4682/linebot_finance.git .
|
||||||
|
else
|
||||||
|
echo "🔄 正在更新現有儲存庫..."
|
||||||
|
git fetch origin main
|
||||||
|
git reset --hard origin/main
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Create .env file from Secrets
|
- name: Create .env file from Secrets
|
||||||
run: |
|
run: |
|
||||||
# 這裡使用單引號包裹變數,防止特殊字元導致語法出錯
|
# 直接指定絕對路徑寫入,最保險
|
||||||
echo '${{ secrets.ENV_FILE }}' > /home/ubuntu/apps/linebot_finance/.env
|
echo '${{ secrets.ENV_FILE }}' > /home/ubuntu/apps/linebot_finance/.env
|
||||||
chmod 600 /home/ubuntu/apps/linebot_finance/.env
|
chmod 600 /home/ubuntu/apps/linebot_finance/.env
|
||||||
echo ".env 檔案已由 Secrets 產生 🚀"
|
echo ".env 檔案已由 Secrets 產生 🚀"
|
||||||
|
|
||||||
- name: Pull and Restart Service
|
- name: Docker Build and Deploy
|
||||||
run: |
|
run: |
|
||||||
cd /home/ubuntu/apps/linebot_finance
|
cd /home/ubuntu/apps/linebot_finance
|
||||||
# 如果目錄還沒初始化過 Git,先進行初始化
|
# 執行 Docker Compose
|
||||||
if [ ! -d ".git" ]; then
|
|
||||||
git clone http://127.0.0.1:3000/henry4682/linebot_finance.git .
|
|
||||||
fi
|
|
||||||
git fetch origin main
|
|
||||||
git reset --hard origin/main
|
|
||||||
# 啟動 Line Bot
|
|
||||||
docker compose up -d --build --remove-orphans
|
docker compose up -d --build --remove-orphans
|
||||||
|
# 清理過期鏡像節省 Oracle 空間
|
||||||
docker image prune -f
|
docker image prune -f
|
||||||
|
echo "✅ 部署完成!"
|
||||||
Reference in New Issue
Block a user