From 77410eca8ae7088852b4225c6b54a4d58e58b19a Mon Sep 17 00:00:00 2001 From: hotwa Date: Tue, 30 Sep 2025 21:43:09 +0800 Subject: [PATCH] test3 --- .gitea/workflows/build-and-push.yml | 38 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/.gitea/workflows/build-and-push.yml b/.gitea/workflows/build-and-push.yml index c84ee7f..684b4f8 100644 --- a/.gitea/workflows/build-and-push.yml +++ b/.gitea/workflows/build-and-push.yml @@ -46,46 +46,50 @@ jobs: - name: Start v2ray-client (write + assert + verify + run + logs) env: V2RAY_JSON: ${{ secrets.V2RAY_JSON }} + SOCKS_PORT: "11080" + HTTP_PORT: "18080" run: | set -euo pipefail # 0) 强校验 Secret 是否非空 if [ -z "${V2RAY_JSON:-}" ]; then - echo "ERROR: V2RAY_JSON is empty or not set. Check your repository Secrets." >&2 + echo "ERROR: V2RAY_JSON is empty or not set." >&2 exit 1 fi - # 1) 写入配置到工作区 + # 1) 写配置 mkdir -p "${GITHUB_WORKSPACE}/v2ray" - # 注意用 printf,不要 echo -e,避免转义问题 printf '%s' "$V2RAY_JSON" > "${GITHUB_WORKSPACE}/v2ray/config.json" + command -v jq >/dev/null 2>&1 && jq . "${GITHUB_WORKSPACE}/v2ray/config.json" >/dev/null - # 2) 本机硬校验:存在、非空、可读、是普通文件 - ls -l "${GITHUB_WORKSPACE}/v2ray" || true - test -f "${GITHUB_WORKSPACE}/v2ray/config.json" - test -s "${GITHUB_WORKSPACE}/v2ray/config.json" - # 可选:校验 JSON 格式(若 runner 没装 jq,可去掉) + # 2) 强制端口为 11080/18080(与 BuildKit http_proxy 保持一致) if command -v jq >/dev/null 2>&1; then - jq . "${GITHUB_WORKSPACE}/v2ray/config.json" >/dev/null + jq --argjson sp "$SOCKS_PORT" --argjson hp "$HTTP_PORT" \ + '.inbounds |= map( + if .protocol=="socks" and .port then .port=$sp + else if .protocol=="http" and .port then .port=$hp + else . end end + )' "${GITHUB_WORKSPACE}/v2ray/config.json" \ + > "${GITHUB_WORKSPACE}/v2ray/config.tmp" && mv "${GITHUB_WORKSPACE}/v2ray/config.tmp" "${GITHUB_WORKSPACE}/v2ray/config.json" fi - # 3) 用一次性容器检查“容器内是否能看到文件”(覆盖 entrypoint 才能用 sh) + # 3) 容器内可见性检查(注意:去掉了 ,z) docker run --rm \ --network host \ - --mount type=bind,src=${GITHUB_WORKSPACE}/v2ray,dst=/etc/v2ray,ro,z \ + --mount type=bind,src=${GITHUB_WORKSPACE}/v2ray,dst=/etc/v2ray,readonly \ --entrypoint sh \ v2fly/v2fly-core:latest \ -lc 'echo "== inside container =="; ls -l /etc/v2ray; echo "---"; head -n2 /etc/v2ray/config.json || true' - # 4) 启动真实服务 + # 4) 启动(注意:去掉了 ,z) docker rm -f v2ray-client >/dev/null 2>&1 || true docker run -d --name v2ray-client \ --network host \ - --mount type=bind,src=${GITHUB_WORKSPACE}/v2ray,dst=/etc/v2ray,ro,z \ + --mount type=bind,src=${GITHUB_WORKSPACE}/v2ray,dst=/etc/v2ray,readonly \ v2fly/v2fly-core:latest \ - run -c /etc/v2ray/config.json -format jsonv5 + run -c /etc/v2ray/config.json - # 5) 健康检查;若退出则打印日志并失败 + # 5) 健康检查 + 日志 sleep 1 if [ "$(docker inspect -f '{{.State.Running}}' v2ray-client 2>/dev/null)" != "true" ]; then echo "== v2ray-client exited; logs ==" @@ -93,8 +97,8 @@ jobs: exit 1 fi - # 6)(可选)打印挂载确认 - docker inspect -f '{{range .Mounts}}{{println .Type .Source "->" .Destination}}{{end}}' v2ray-client + docker inspect -f '{{range .Mounts}}{{println .Type " " .Source "->" .Destination}}{{end}}' v2ray-client + - name: Build Docker Image (host network; no Dockerfile change) env: