feat: 在 CI/CD workflow 中添加 desk-demo 部署步骤(Nginx /desk/ location + 静态文件 + 验证)
This commit is contained in:
parent
46e5bb4f6c
commit
e9b23e3274
@ -130,6 +130,90 @@ jobs:
|
||||
echo "✅ 静态文件已同步"
|
||||
ls -la /var/www/guanghulab/
|
||||
|
||||
- name: 部署 Desk Demo + Nginx 配置
|
||||
run: |
|
||||
echo "═══ 部署 Desk Demo /desk/ ═══"
|
||||
DESK_DIR="/var/www/guanghulab/desk"
|
||||
mkdir -p "$DESK_DIR"
|
||||
cp /data/guanghulab/repo/desk-demo/index.html "$DESK_DIR/index.html"
|
||||
chown -R www-data:www-data "$DESK_DIR" 2>/dev/null || true
|
||||
chmod 755 "$DESK_DIR"
|
||||
chmod 644 "$DESK_DIR/index.html"
|
||||
echo "✅ desk-demo 文件已部署"
|
||||
ls -la "$DESK_DIR"
|
||||
|
||||
# 配置 Nginx /desk/ location
|
||||
echo "═══ 配置 Nginx ═══"
|
||||
NGINX_CONF="/etc/nginx/sites-available/guanghulab-cvm"
|
||||
|
||||
if [ ! -f "$NGINX_CONF" ]; then
|
||||
# 可能在 sites-enabled 或 conf.d 中
|
||||
NGINX_CONF=$(grep -rl "guanghulab" /etc/nginx/sites-enabled/ 2>/dev/null | head -1)
|
||||
fi
|
||||
if [ ! -f "$NGINX_CONF" ]; then
|
||||
NGINX_CONF=$(grep -rl "guanghulab" /etc/nginx/conf.d/ 2>/dev/null | head -1)
|
||||
fi
|
||||
if [ ! -f "$NGINX_CONF" ]; then
|
||||
NGINX_CONF="/etc/nginx/nginx.conf"
|
||||
fi
|
||||
|
||||
echo "📄 使用 Nginx 配置文件: $NGINX_CONF"
|
||||
|
||||
if grep -q "location /desk/" "$NGINX_CONF" 2>/dev/null; then
|
||||
echo "⚠️ /desk/ location 已存在,跳过添加"
|
||||
else
|
||||
echo "📝 添加 /desk/ location..."
|
||||
# 在 Forgejo proxy location / 之前插入 desk location
|
||||
sed -i '/location \/ {/,/}/ {
|
||||
/location \/ {/i\
|
||||
# Desk Demo 大桌子小桌子 (/desk/)\
|
||||
location /desk/ {\
|
||||
alias /var/www/guanghulab/desk/;\
|
||||
index index.html;\
|
||||
try_files $uri $uri/ /desk/index.html;\
|
||||
}\
|
||||
\
|
||||
}' "$NGINX_CONF" 2>/dev/null || {
|
||||
# 如果 sed 失败,使用更简单的方式
|
||||
awk '/# ─── Forgejo/{print " # Desk Demo (/desk/)\n location /desk/ {\n alias /var/www/guanghulab/desk/;\n index index.html;\n try_files $uri $uri/ /desk/index.html;\n }\n"}1' "$NGINX_CONF" > /tmp/nginx_new.conf
|
||||
cp /tmp/nginx_new.conf "$NGINX_CONF"
|
||||
}
|
||||
echo "✅ /desk/ location 已添加"
|
||||
fi
|
||||
|
||||
# 显示相关配置
|
||||
echo "═══ desk 相关 Nginx 配置 ═══"
|
||||
grep -n -A5 "desk" "$NGINX_CONF" || echo "(无 desk 相关内容)"
|
||||
|
||||
# 测试并重载
|
||||
echo "═══ 测试 Nginx 配置 ═══"
|
||||
if nginx -t 2>&1; then
|
||||
echo "✅ Nginx 配置测试通过"
|
||||
systemctl reload nginx
|
||||
echo "✅ Nginx 已重载"
|
||||
else
|
||||
echo "❌ Nginx 配置测试失败,回滚..."
|
||||
# 回滚:移除 desk location
|
||||
grep -v "location /desk/" "$NGINX_CONF" > /tmp/nginx_rollback.conf
|
||||
cp /tmp/nginx_rollback.conf "$NGINX_CONF"
|
||||
nginx -t && systemctl reload nginx
|
||||
echo "⚠️ 已回滚 Nginx 配置"
|
||||
fi
|
||||
|
||||
- name: 验证 Desk Demo 部署
|
||||
run: |
|
||||
sleep 2
|
||||
echo "═══ 验证 /desk/ ═══"
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1/desk/)
|
||||
echo "HTTP 状态码: $HTTP_CODE"
|
||||
TITLE=$(curl -s http://127.0.0.1/desk/ | grep -o '<title>[^<]*</title>' | head -1)
|
||||
echo "页面标题: $TITLE"
|
||||
if echo "$TITLE" | grep -q "大桌子小桌子"; then
|
||||
echo "✅ Desk Demo 部署成功!"
|
||||
else
|
||||
echo "⚠️ 页面标题可能不匹配,但 /desk/ 已可访问"
|
||||
fi
|
||||
|
||||
- name: 部署验证
|
||||
run: |
|
||||
sleep 3
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user