From ef9b987653896dd1713b751d386aa00f6b8d3890 Mon Sep 17 00:00:00 2001 From: SpecialX <47072643+wangxiner55@users.noreply.github.com> Date: Wed, 25 Feb 2026 18:03:32 +0800 Subject: [PATCH] fix-deploy-network --- .gitea/workflows/ci.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 08c15ff..fb6bd16 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -142,6 +142,43 @@ jobs: container: image: dockerreg.eazygame.cn/node-with-docker:22 steps: + - name: 🌐 Setup Network (Dynamic) + run: | + # 1. 动态获取 Docker 网关 IP + # 尝试多种方式获取网关 IP + + GATEWAY_IP="" + + # 尝试使用 ip route (如果可用) + if command -v ip >/dev/null 2>&1; then + GATEWAY_IP=$(ip route show | grep default | awk '{print $3}') + fi + + # 如果 ip 命令不可用,尝试 hostname -I 推断 + if [ -z "$GATEWAY_IP" ]; then + CURRENT_IP=$(hostname -I 2>/dev/null | awk '{print $1}') + if [ -n "$CURRENT_IP" ]; then + GATEWAY_IP=$(echo "$CURRENT_IP" | sed 's/\.[0-9]*$/.1/') + fi + fi + + # 兜底 + if [ -z "$GATEWAY_IP" ]; then + echo "Warning: Could not detect gateway IP, using fallback 172.17.0.1" + GATEWAY_IP="172.17.0.1" + fi + + echo "Detected Docker Gateway: $GATEWAY_IP" + + # 2. 配置 Host 解析 (解决 gittea.eazygame.cn 无法访问的问题) + # 注意:需要容器内有 root 权限 + if [ "$(id -u)" -eq 0 ]; then + echo "$GATEWAY_IP gittea.eazygame.cn" >> /etc/hosts + cat /etc/hosts + else + echo "Warning: Not root, cannot modify /etc/hosts" + fi + - name: Download artifacts uses: actions/download-artifact@v3 with: