This commit is contained in:
@@ -46,46 +46,50 @@ jobs:
|
|||||||
- name: Start v2ray-client (write + assert + verify + run + logs)
|
- name: Start v2ray-client (write + assert + verify + run + logs)
|
||||||
env:
|
env:
|
||||||
V2RAY_JSON: ${{ secrets.V2RAY_JSON }}
|
V2RAY_JSON: ${{ secrets.V2RAY_JSON }}
|
||||||
|
SOCKS_PORT: "11080"
|
||||||
|
HTTP_PORT: "18080"
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# 0) 强校验 Secret 是否非空
|
# 0) 强校验 Secret 是否非空
|
||||||
if [ -z "${V2RAY_JSON:-}" ]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 1) 写入配置到工作区
|
# 1) 写配置
|
||||||
mkdir -p "${GITHUB_WORKSPACE}/v2ray"
|
mkdir -p "${GITHUB_WORKSPACE}/v2ray"
|
||||||
# 注意用 printf,不要 echo -e,避免转义问题
|
|
||||||
printf '%s' "$V2RAY_JSON" > "${GITHUB_WORKSPACE}/v2ray/config.json"
|
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) 本机硬校验:存在、非空、可读、是普通文件
|
# 2) 强制端口为 11080/18080(与 BuildKit http_proxy 保持一致)
|
||||||
ls -l "${GITHUB_WORKSPACE}/v2ray" || true
|
|
||||||
test -f "${GITHUB_WORKSPACE}/v2ray/config.json"
|
|
||||||
test -s "${GITHUB_WORKSPACE}/v2ray/config.json"
|
|
||||||
# 可选:校验 JSON 格式(若 runner 没装 jq,可去掉)
|
|
||||||
if command -v jq >/dev/null 2>&1; then
|
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
|
fi
|
||||||
|
|
||||||
# 3) 用一次性容器检查“容器内是否能看到文件”(覆盖 entrypoint 才能用 sh)
|
# 3) 容器内可见性检查(注意:去掉了 ,z)
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
--network host \
|
--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 \
|
--entrypoint sh \
|
||||||
v2fly/v2fly-core:latest \
|
v2fly/v2fly-core:latest \
|
||||||
-lc 'echo "== inside container =="; ls -l /etc/v2ray; echo "---"; head -n2 /etc/v2ray/config.json || true'
|
-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 rm -f v2ray-client >/dev/null 2>&1 || true
|
||||||
docker run -d --name v2ray-client \
|
docker run -d --name v2ray-client \
|
||||||
--network host \
|
--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 \
|
v2fly/v2fly-core:latest \
|
||||||
run -c /etc/v2ray/config.json -format jsonv5
|
run -c /etc/v2ray/config.json
|
||||||
|
|
||||||
# 5) 健康检查;若退出则打印日志并失败
|
# 5) 健康检查 + 日志
|
||||||
sleep 1
|
sleep 1
|
||||||
if [ "$(docker inspect -f '{{.State.Running}}' v2ray-client 2>/dev/null)" != "true" ]; then
|
if [ "$(docker inspect -f '{{.State.Running}}' v2ray-client 2>/dev/null)" != "true" ]; then
|
||||||
echo "== v2ray-client exited; logs =="
|
echo "== v2ray-client exited; logs =="
|
||||||
@@ -93,8 +97,8 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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)
|
- name: Build Docker Image (host network; no Dockerfile change)
|
||||||
env:
|
env:
|
||||||
|
|||||||
Reference in New Issue
Block a user