Skip to content

Commit b5a59e0

Browse files
authored
refactor(docker): consolidate E2E scenario helpers (#117359)
* refactor(docker): consolidate E2E scenario helpers * fix(ci): retain release harness entry * test(docker): complete package helper fixture
1 parent 9a29304 commit b5a59e0

19 files changed

Lines changed: 458 additions & 1190 deletions

‎.github/actions/docker-e2e-plan/action.yml‎

Lines changed: 0 additions & 172 deletions
This file was deleted.

‎config/knip.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const repositoryScriptEntries = [
2121
"scripts/check-package-dist-imports.mjs!",
2222
"scripts/dev/ios-node-e2e.ts!",
2323
"scripts/diffs-shiki-curated.ts!",
24+
// Reusable Docker workflows invoke this from the downloaded .release-harness tree.
25+
"scripts/docker-e2e.mjs!",
2426
"scripts/e2e/lib/browser-cdp-snapshot/assert-snapshot.mjs!",
2527
"scripts/e2e/lib/browser-cdp-snapshot/fixture-server.mjs!",
2628
"scripts/e2e/lib/bundled-plugin-install-uninstall/runtime-smoke.mjs!",

‎scripts/lib/docker-e2e-package.sh‎

Lines changed: 2 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -7,146 +7,13 @@
77
DOCKER_E2E_PACKAGE_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
88
ROOT_DIR="${ROOT_DIR:-$(cd "$DOCKER_E2E_PACKAGE_LIB_DIR/../.." && pwd)}"
99

10-
if ! declare -F docker_e2e_docker_run_with_resource_diagnostics >/dev/null 2>&1; then
11-
source "$DOCKER_E2E_PACKAGE_LIB_DIR/docker-e2e-resource-diagnostics.sh"
12-
fi
13-
1410
if ! declare -F run_logged >/dev/null 2>&1; then
1511
source "$DOCKER_E2E_PACKAGE_LIB_DIR/docker-e2e-logs.sh"
1612
fi
17-
if ! declare -F docker_e2e_docker_cmd >/dev/null 2>&1; then
13+
if ! declare -F docker_e2e_docker_cmd >/dev/null 2>&1 || \
14+
! declare -F docker_e2e_docker_run_cmd >/dev/null 2>&1; then
1815
source "$DOCKER_E2E_PACKAGE_LIB_DIR/docker-e2e-container.sh"
1916
fi
20-
if ! declare -F docker_e2e_docker_run_resource_args >/dev/null 2>&1; then
21-
docker_e2e_resource_limits_disabled() {
22-
case "${OPENCLAW_DOCKER_E2E_DISABLE_RESOURCE_LIMITS:-}" in
23-
1 | true | TRUE | yes | YES | on | ON)
24-
return 0
25-
;;
26-
esac
27-
return 1
28-
}
29-
30-
docker_e2e_resource_value_disabled() {
31-
case "${1:-}" in
32-
"" | 0 | none | NONE | off | OFF | false | FALSE)
33-
return 0
34-
;;
35-
esac
36-
return 1
37-
}
38-
39-
docker_e2e_detect_available_cpus() {
40-
if [ -n "${OPENCLAW_DOCKER_E2E_AVAILABLE_CPUS:-}" ]; then
41-
printf '%s\n' "$OPENCLAW_DOCKER_E2E_AVAILABLE_CPUS"
42-
return 0
43-
fi
44-
if command -v nproc >/dev/null 2>&1; then
45-
nproc
46-
return 0
47-
fi
48-
if command -v getconf >/dev/null 2>&1; then
49-
getconf _NPROCESSORS_ONLN
50-
return 0
51-
fi
52-
return 1
53-
}
54-
55-
docker_e2e_resolve_cpus() {
56-
local requested="$1"
57-
local available=""
58-
available="$(docker_e2e_detect_available_cpus 2>/dev/null || true)"
59-
if [[ "$requested" =~ ^[0-9]+$ ]] && [[ "$available" =~ ^[0-9]+$ ]] && [ "$requested" -gt "$available" ]; then
60-
printf '%s\n' "$available"
61-
return 0
62-
fi
63-
printf '%s\n' "$requested"
64-
}
65-
66-
docker_e2e_run_arg_present() {
67-
local option="$1"
68-
shift
69-
local arg
70-
for arg in "$@"; do
71-
if [ "$arg" = "$option" ] || [[ "$arg" == "$option="* ]]; then
72-
return 0
73-
fi
74-
case "$option:$arg" in
75-
--memory:-m | --memory:-m=*)
76-
return 0
77-
;;
78-
esac
79-
done
80-
return 1
81-
}
82-
83-
docker_e2e_resolve_pids_limit() {
84-
local pids_limit="$1"
85-
if [[ ! "$pids_limit" =~ ^[0-9]+$ ]] || (( 10#$pids_limit < 1 )); then
86-
echo "invalid OPENCLAW_DOCKER_E2E_PIDS_LIMIT: $pids_limit" >&2
87-
return 2
88-
fi
89-
printf '%s\n' "$((10#$pids_limit))"
90-
}
91-
92-
docker_e2e_docker_run_resource_args() {
93-
DOCKER_E2E_RUN_RESOURCE_ARGS=()
94-
if docker_e2e_resource_limits_disabled; then
95-
return 0
96-
fi
97-
98-
local memory="${OPENCLAW_DOCKER_E2E_MEMORY:-8g}"
99-
local cpus="${OPENCLAW_DOCKER_E2E_CPUS:-16}"
100-
local pids_limit="${OPENCLAW_DOCKER_E2E_PIDS_LIMIT:-2048}"
101-
cpus="$(docker_e2e_resolve_cpus "$cpus")"
102-
103-
if ! docker_e2e_resource_value_disabled "$memory" && ! docker_e2e_run_arg_present --memory "$@"; then
104-
DOCKER_E2E_RUN_RESOURCE_ARGS+=(--memory "$memory")
105-
fi
106-
if ! docker_e2e_resource_value_disabled "$cpus" && ! docker_e2e_run_arg_present --cpus "$@"; then
107-
DOCKER_E2E_RUN_RESOURCE_ARGS+=(--cpus "$cpus")
108-
fi
109-
if ! docker_e2e_resource_value_disabled "$pids_limit" && ! docker_e2e_run_arg_present --pids-limit "$@"; then
110-
pids_limit="$(docker_e2e_resolve_pids_limit "$pids_limit")" || return $?
111-
DOCKER_E2E_RUN_RESOURCE_ARGS+=(--pids-limit "$pids_limit")
112-
fi
113-
}
114-
fi
115-
if ! declare -F docker_e2e_timeout_cmd >/dev/null 2>&1; then
116-
docker_e2e_timeout_cmd() {
117-
local timeout_value="$1"
118-
shift
119-
local timeout_bin=""
120-
if command -v timeout >/dev/null 2>&1; then
121-
timeout_bin="timeout"
122-
elif command -v gtimeout >/dev/null 2>&1; then
123-
timeout_bin="gtimeout"
124-
fi
125-
if [ -n "$timeout_bin" ]; then
126-
if "$timeout_bin" --kill-after=1s 1s true >/dev/null 2>&1; then
127-
"$timeout_bin" --kill-after=30s "$timeout_value" "$@"
128-
else
129-
"$timeout_bin" "$timeout_value" "$@"
130-
fi
131-
return
132-
fi
133-
echo "timeout command not found; cannot bound Docker run after ${timeout_value}" >&2
134-
return 127
135-
}
136-
fi
137-
if ! declare -F docker_e2e_docker_run_cmd >/dev/null 2>&1; then
138-
docker_e2e_docker_run_cmd() {
139-
if [ "${1:-}" = "run" ]; then
140-
shift
141-
docker_e2e_docker_run_resource_args "$@" || return $?
142-
docker_e2e_docker_run_with_resource_diagnostics \
143-
"${DOCKER_COMMAND_TIMEOUT:-${OPENCLAW_DOCKER_E2E_RUN_TIMEOUT:-3600s}}" \
144-
"$@"
145-
return
146-
fi
147-
docker_e2e_timeout_cmd "${DOCKER_COMMAND_TIMEOUT:-${OPENCLAW_DOCKER_E2E_RUN_TIMEOUT:-3600s}}" docker "$@"
148-
}
149-
fi
15017

15118
docker_e2e_abs_path() {
15219
local file="$1"

0 commit comments

Comments
 (0)