rope_helper/deploy.sh

62 lines
2.3 KiB
Bash
Executable file
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.

#!/bin/bash
# ==============================================================================
# Rope Helper 自動化部署腳本 (CI/CD Deploy Script)
# 目標:將本專案靜態檔案自動部署至本機 Docker (realm-view / Caddy)
# 服務網址https://ridgerealm.com/rope_helper/
# ==============================================================================
set -e
# 定義顏色
GREEN='\033[0;32m'
SKY='\033[0;36m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
PROJECT_DIR="/mnt/Project/Rope_hekper"
TARGET_DIR="/mnt/focker/realm-view/public/rope_helper"
HEALTH_CHECK_URL="http://127.0.0.1:3333/rope_helper/"
echo -e "${SKY}======================================================${NC}"
echo -e "${SKY}🚀 開始執行 Rope Helper CI/CD 自動化部署流程...${NC}"
echo -e "${SKY}======================================================${NC}"
# 1. 檢查原始檔案
if [ ! -f "$PROJECT_DIR/index.html" ]; then
echo -e "${RED}❌ 錯誤:找不到來源檔案 $PROJECT_DIR/index.html${NC}"
exit 1
fi
# 2. 確保目標目錄存在
echo -e "${YELLOW}📁 [1/4] 檢查目標伺服器目錄...${NC}"
mkdir -p "$TARGET_DIR"
# 3. 部署同步檔案 (使用 rsync 保持檔案屬性與安全同步)
echo -e "${YELLOW}📦 [2/4] 同步靜態網頁檔案至 Docker Web 目錄...${NC}"
rsync -av --delete \
--exclude=".git" \
--exclude=".github" \
--exclude=".forgejo" \
--exclude="deploy.sh" \
--exclude="*.swp" \
"$PROJECT_DIR/" "$TARGET_DIR/"
# 4. 檔案權限設定
echo -e "${YELLOW}🔒 [3/4] 校正檔案存取權限...${NC}"
chmod -R 755 "$TARGET_DIR"
# 5. 健康檢查 (Health Check)
echo -e "${YELLOW}🩺 [4/4] 執行服務健康狀態檢查...${NC}"
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$HEALTH_CHECK_URL" || echo "000")
if [ "$HTTP_STATUS" -eq 200 ] || [ "$HTTP_STATUS" -eq 304 ]; then
echo -e "${GREEN}✅ 健康檢查通過 (HTTP $HTTP_STATUS)${NC}"
else
echo -e "${YELLOW}⚠️ 內部測試回應碼為 $HTTP_STATUS,但檔案已成功同步。${NC}"
fi
echo -e "${GREEN}======================================================${NC}"
echo -e "${GREEN}🎉 部署完成!${NC}"
echo -e "${GREEN}🌐 網站正式網址https://ridgerealm.com/rope_helper/${NC}"
echo -e "${GREEN}======================================================${NC}"