|
@@ -10,9 +10,32 @@ IMAGE="dsh-web:smoke"
|
|
|
CID="dsh-smoke"
|
|
CID="dsh-smoke"
|
|
|
|
|
|
|
|
cleanup() {
|
|
cleanup() {
|
|
|
|
|
+ # cleanup 失败不应掩盖主命令的退出码:bash EXIT trap 的函数返回值就是进程的最终
|
|
|
|
|
+ # exit code(覆盖 `exit N` 的 N)。trap 启动时 $? = 触发 trap 的命令退出码,
|
|
|
|
|
+ # 函数第一行捕获它,cleanup 内部失败用 warn 兜底,最后 return 这个 rc 把它冒出去
|
|
|
|
|
+ #
|
|
|
|
|
+ # Cleanup failures must not mask the main command's exit code: bash EXIT trap's
|
|
|
|
|
+ # function return value becomes the process's final exit code (overriding `exit N`).
|
|
|
|
|
+ # The trap fires with $? = the triggering command's exit code; we capture it on the
|
|
|
|
|
+ # first line, swallow internal cleanup failures into a warn, and `return` it so it
|
|
|
|
|
+ # propagates to Actions as the real failure rather than a silent success
|
|
|
|
|
+ local rc=$?
|
|
|
docker rm -f "$CID" >/dev/null 2>&1 || true
|
|
docker rm -f "$CID" >/dev/null 2>&1 || true
|
|
|
- [ -n "${SMOKE_HOME:-}" ] && rm -rf "$SMOKE_HOME" || true
|
|
|
|
|
|
|
+ if [ -n "${SMOKE_HOME:-}" ] && [ -d "$SMOKE_HOME" ]; then
|
|
|
|
|
+ # 先放宽权限再递归删:容器内 uid 1000 (node) 写下的子文件可能只对本人可写,
|
|
|
|
|
+ # runner (uid 1001) 在 sticky /tmp 下无法删;但若 SMOKE_PARENT 已经是 runner 自己的
|
|
|
|
|
+ # 非 sticky 目录,权限放宽足以应对权限位差异
|
|
|
|
|
+ #
|
|
|
|
|
+ # Loosen perms first then recurse: container-internal uid 1000 (node) may have left
|
|
|
|
|
+ # files only writable by themselves; on a sticky /tmp a uid-1001 runner can't drop
|
|
|
|
|
+ # those. If SMOKE_PARENT is already a non-sticky runner-owned dir, chmod is enough.
|
|
|
|
|
+ chmod -R u+w "$SMOKE_HOME" 2>/dev/null || true
|
|
|
|
|
+ rm -rf "$SMOKE_HOME" 2>/dev/null || warn "无法清理 SMOKE_HOME=$SMOKE_HOME(容器子文件权限/sticky 导致),手动 rm 即可"
|
|
|
|
|
+ fi
|
|
|
|
|
+ return "$rc" # 关键:把主命令退出码冒出去
|
|
|
|
|
+ # Critical: propagate the main command's exit code
|
|
|
}
|
|
}
|
|
|
|
|
+warn() { printf 'WARN: %s\n' "$*" >&2; }
|
|
|
trap cleanup EXIT
|
|
trap cleanup EXIT
|
|
|
cleanup
|
|
cleanup
|
|
|
|
|
|
|
@@ -28,7 +51,21 @@ echo "==> 启动容器冒烟"
|
|
|
# 预置假 x-cmd(x 可执行即跳过 entrypoint 首启 300s 下载)
|
|
# 预置假 x-cmd(x 可执行即跳过 entrypoint 首启 300s 下载)
|
|
|
#
|
|
#
|
|
|
# Pre-seed a fake x-cmd (an executable x skips the entrypoint's 300s first-run download)
|
|
# Pre-seed a fake x-cmd (an executable x skips the entrypoint's 300s first-run download)
|
|
|
-SMOKE_HOME="$(mktemp -d)"
|
|
|
|
|
|
|
+#
|
|
|
|
|
+# SMOKE_PARENT 选择:必须是非 sticky 目录。容器内 dsh/caddy 以 uid 1000 (node) 写入
|
|
|
|
|
+# bind mount 的子文件,runner 是 uid 1001;sticky /tmp + 跨 uid → cleanup 时 EPERM。
|
|
|
|
|
+# 优先用 GitHub Actions 提供的 RUNNER_TEMP(runner 独占,非 sticky),否则用
|
|
|
|
|
+# 系统 TMPDIR(部分发行版已重定向到 /run/user/<uid>),否则回退 $HOME
|
|
|
|
|
+# (Linux home 不 sticky,macOS 也只有 /tmp 有 sticky)。$HOME 兜底保留本地跑的可用性
|
|
|
|
|
+#
|
|
|
|
|
+# SMOKE_PARENT must be non-sticky: container dsh/caddy runs as uid 1000 (node) and
|
|
|
|
|
+# writes into the bind-mount, while the runner is uid 1001; sticky /tmp + cross-uid
|
|
|
|
|
+# triggers EPERM on cleanup. Prefer RUNNER_TEMP (runner-exclusive, non-sticky), then
|
|
|
|
|
+# TMPDIR (some distros point it at /run/user/<uid>), then $HOME (Linux home is not
|
|
|
|
|
+# sticky; macOS only has sticky on /tmp). $HOME fallback keeps local runs working.
|
|
|
|
|
+SMOKE_PARENT="${RUNNER_TEMP:-${TMPDIR:-$HOME}}"
|
|
|
|
|
+mkdir -p "$SMOKE_PARENT"
|
|
|
|
|
+SMOKE_HOME="$(mktemp -d -p "$SMOKE_PARENT" smoke-XXXXXX)"
|
|
|
mkdir -p "$SMOKE_HOME/.x-cmd.root/bin"
|
|
mkdir -p "$SMOKE_HOME/.x-cmd.root/bin"
|
|
|
printf '#!/bin/sh\nexit 0\n' > "$SMOKE_HOME/.x-cmd.root/bin/x"
|
|
printf '#!/bin/sh\nexit 0\n' > "$SMOKE_HOME/.x-cmd.root/bin/x"
|
|
|
docker run -d --name "$CID" \
|
|
docker run -d --name "$CID" \
|
|
@@ -40,20 +77,32 @@ docker run -d --name "$CID" \
|
|
|
PORT="$(docker port "$CID" 3081 | head -n1 | sed 's/.*://')"
|
|
PORT="$(docker port "$CID" 3081 | head -n1 | sed 's/.*://')"
|
|
|
echo " 容器 $CID 已启动,映射端口 $PORT"
|
|
echo " 容器 $CID 已启动,映射端口 $PORT"
|
|
|
|
|
|
|
|
-echo "==> 等待服务就绪(最多 120s)"
|
|
|
|
|
|
|
+echo "==> 等待服务就绪(最多 240s)"
|
|
|
# 仅 200 视为就绪:502(Caddy 已起但 dsh 未就绪)与 000(未监听)都继续等;
|
|
# 仅 200 视为就绪:502(Caddy 已起但 dsh 未就绪)与 000(未监听)都继续等;
|
|
|
# 401 是 Caddy basic auth 层拒绝、不经过反代,也不能代表 dsh 就绪
|
|
# 401 是 Caddy basic auth 层拒绝、不经过反代,也不能代表 dsh 就绪
|
|
|
#
|
|
#
|
|
|
# Only 200 means ready: 502 (Caddy up but dsh not yet) and 000 (not listening) keep waiting;
|
|
# Only 200 means ready: 502 (Caddy up but dsh not yet) and 000 (not listening) keep waiting;
|
|
|
# 401 is rejected at the Caddy basic-auth layer without touching the proxy, so it proves nothing
|
|
# 401 is rejected at the Caddy basic-auth layer without touching the proxy, so it proves nothing
|
|
|
|
|
+#
|
|
|
|
|
+# 阈值从 120s 提到 240s:0.1.2-rc.1 在 GitHub Actions runner 上首启需 ~150s
|
|
|
|
|
+# (x-cmd 80MB 下载 + dsh web bundles 懒加载),120s 反复误报上游慢。240s 留一倍余量,
|
|
|
|
|
+# 真挂的场景仍会超时但能区分「慢」vs「挂」
|
|
|
|
|
+#
|
|
|
|
|
+# Threshold raised 120s→240s: dsh 0.1.2-rc.1 first boot on GitHub Actions runner
|
|
|
|
|
+# takes ~150s (80MB x-cmd download + dsh web bundles lazy load). 120s kept misfiring
|
|
|
|
|
+# on upstream slowness; 240s leaves 1× headroom while still failing on real hangs
|
|
|
READY=0
|
|
READY=0
|
|
|
-for _ in $(seq 1 60); do
|
|
|
|
|
|
|
+LAST_CODE=000
|
|
|
|
|
+START_TS="$(date +%s)"
|
|
|
|
|
+for _ in $(seq 1 120); do
|
|
|
CODE="$(curl -s -u admin:smoketest -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PORT/" || true)"
|
|
CODE="$(curl -s -u admin:smoketest -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PORT/" || true)"
|
|
|
|
|
+ LAST_CODE="$CODE"
|
|
|
if [ "$CODE" = "200" ]; then READY=1; break; fi
|
|
if [ "$CODE" = "200" ]; then READY=1; break; fi
|
|
|
sleep 2
|
|
sleep 2
|
|
|
done
|
|
done
|
|
|
if [ "$READY" != 1 ]; then
|
|
if [ "$READY" != 1 ]; then
|
|
|
- echo "错误:服务 120s 内未就绪" >&2
|
|
|
|
|
|
|
+ ELAPSED=$(( $(date +%s) - START_TS ))
|
|
|
|
|
+ echo "错误:服务 ${ELAPSED}s 内未就绪(最后一次 HTTP code=$LAST_CODE)" >&2
|
|
|
docker logs "$CID" 2>&1 | tail -30 >&2
|
|
docker logs "$CID" 2>&1 | tail -30 >&2
|
|
|
exit 1
|
|
exit 1
|
|
|
fi
|
|
fi
|