From e9b23e32744c8cd396ebb664a5c9862ebbee2250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E6=9C=94?= <565183519@qq.com> Date: Thu, 28 May 2026 23:46:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=20CI/CD=20workflow=20?= =?UTF-8?q?=E4=B8=AD=E6=B7=BB=E5=8A=A0=20desk-demo=20=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E6=AD=A5=E9=AA=A4=EF=BC=88Nginx=20/desk/=20location=20+=20?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=96=87=E4=BB=B6=20+=20=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci-and-deploy.yaml | 84 +++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/.gitea/workflows/ci-and-deploy.yaml b/.gitea/workflows/ci-and-deploy.yaml index f89bb5b..901af2e 100644 --- a/.gitea/workflows/ci-and-deploy.yaml +++ b/.gitea/workflows/ci-and-deploy.yaml @@ -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 '