test: bound Docker smoke host commands

This commit is contained in:
Peter Steinberger
2026-04-24 20:54:02 +01:00
parent 0e23107ffb
commit 037d12974c
3 changed files with 68 additions and 43 deletions

View File

@@ -19,6 +19,12 @@ ADMIN_PASSWORD="${OPENCLAW_OPENWEBUI_ADMIN_PASSWORD:-OpenWebUI-E2E-Password-$(da
NET_NAME="openclaw-openwebui-e2e-$$"
GW_NAME="openclaw-openwebui-gateway-$$"
OW_NAME="openclaw-openwebui-$$"
DOCKER_COMMAND_TIMEOUT="${OPENCLAW_OPENWEBUI_DOCKER_COMMAND_TIMEOUT:-60s}"
DOCKER_PULL_TIMEOUT="${OPENCLAW_OPENWEBUI_DOCKER_PULL_TIMEOUT:-300s}"
docker_cmd() {
timeout "$DOCKER_COMMAND_TIMEOUT" "$@"
}
OPENAI_API_KEY_VALUE="${OPENAI_API_KEY:-}"
if [[ "$OPENAI_API_KEY_VALUE" == "undefined" || "$OPENAI_API_KEY_VALUE" == "null" ]]; then
@@ -34,22 +40,22 @@ if [[ -z "$OPENAI_API_KEY_VALUE" ]]; then
fi
cleanup() {
docker rm -f "$OW_NAME" >/dev/null 2>&1 || true
docker rm -f "$GW_NAME" >/dev/null 2>&1 || true
docker network rm "$NET_NAME" >/dev/null 2>&1 || true
docker_cmd docker rm -f "$OW_NAME" >/dev/null 2>&1 || true
docker_cmd docker rm -f "$GW_NAME" >/dev/null 2>&1 || true
docker_cmd docker network rm "$NET_NAME" >/dev/null 2>&1 || true
}
trap cleanup EXIT
docker_e2e_build_or_reuse "$IMAGE_NAME" openwebui
echo "Pulling Open WebUI image: $OPENWEBUI_IMAGE"
docker pull "$OPENWEBUI_IMAGE" >/dev/null
timeout "$DOCKER_PULL_TIMEOUT" docker pull "$OPENWEBUI_IMAGE" >/dev/null
echo "Creating Docker network..."
docker network create "$NET_NAME" >/dev/null
docker_cmd docker network create "$NET_NAME" >/dev/null
echo "Starting gateway container..."
docker run -d \
docker_cmd docker run -d \
--name "$GW_NAME" \
--network "$NET_NAME" \
-e "OPENCLAW_GATEWAY_TOKEN=$TOKEN" \
@@ -115,10 +121,10 @@ EOF
echo "Waiting for gateway HTTP surface..."
gateway_ready=0
for _ in $(seq 1 240); do
if [ "$(docker inspect -f '{{.State.Running}}' "$GW_NAME" 2>/dev/null || echo false)" != "true" ]; then
if [ "$(docker_cmd docker inspect -f '{{.State.Running}}' "$GW_NAME" 2>/dev/null || echo false)" != "true" ]; then
break
fi
if docker exec "$GW_NAME" bash -lc "node --input-type=module -e '
if docker_cmd docker exec "$GW_NAME" bash -lc "node --input-type=module -e '
const res = await fetch(\"http://127.0.0.1:$PORT/v1/models\", {
headers: { authorization: \"Bearer $TOKEN\" },
}).catch(() => null);
@@ -132,16 +138,16 @@ done
if [ "$gateway_ready" -ne 1 ]; then
echo "Gateway failed to start"
docker inspect "$GW_NAME" --format '{{json .State}}' 2>/dev/null || true
if [ "$(docker inspect -f '{{.State.Running}}' "$GW_NAME" 2>/dev/null || echo false)" = "true" ]; then
docker exec "$GW_NAME" bash -lc 'tail -n 200 /tmp/openwebui-gateway.log' || true
docker_cmd docker inspect "$GW_NAME" --format '{{json .State}}' 2>/dev/null || true
if [ "$(docker_cmd docker inspect -f '{{.State.Running}}' "$GW_NAME" 2>/dev/null || echo false)" = "true" ]; then
docker_cmd docker exec "$GW_NAME" bash -lc 'tail -n 200 /tmp/openwebui-gateway.log' || true
fi
docker logs "$GW_NAME" 2>&1 | tail -n 200 || true
docker_cmd docker logs "$GW_NAME" 2>&1 | tail -n 200 || true
exit 1
fi
echo "Starting Open WebUI container..."
docker run -d \
docker_cmd docker run -d \
--name "$OW_NAME" \
--network "$NET_NAME" \
-e ENV=prod \
@@ -167,10 +173,10 @@ docker run -d \
echo "Waiting for Open WebUI..."
ow_ready=0
for _ in $(seq 1 240); do
if [ "$(docker inspect -f '{{.State.Running}}' "$OW_NAME" 2>/dev/null || echo false)" != "true" ]; then
if [ "$(docker_cmd docker inspect -f '{{.State.Running}}' "$OW_NAME" 2>/dev/null || echo false)" != "true" ]; then
break
fi
if docker exec "$GW_NAME" bash -lc "node --input-type=module -e '
if docker_cmd docker exec "$GW_NAME" bash -lc "node --input-type=module -e '
const res = await fetch(\"http://$OW_NAME:$WEBUI_PORT/\").catch(() => null);
process.exit(res && res.status < 500 ? 0 : 1);
' >/dev/null 2>&1"; then
@@ -182,17 +188,17 @@ done
if [ "$ow_ready" -ne 1 ]; then
echo "Open WebUI failed to start"
docker logs "$OW_NAME" 2>&1 | tail -n 200 || true
docker_cmd docker logs "$OW_NAME" 2>&1 | tail -n 200 || true
exit 1
fi
echo "Waiting for gateway model endpoint after Open WebUI startup..."
gateway_model_ready=0
for _ in $(seq 1 90); do
if [ "$(docker inspect -f '{{.State.Running}}' "$GW_NAME" 2>/dev/null || echo false)" != "true" ]; then
if [ "$(docker_cmd docker inspect -f '{{.State.Running}}' "$GW_NAME" 2>/dev/null || echo false)" != "true" ]; then
break
fi
if docker exec "$GW_NAME" bash -lc "node --input-type=module -e '
if docker_cmd docker exec "$GW_NAME" bash -lc "node --input-type=module -e '
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 8000);
try {
@@ -215,17 +221,17 @@ done
if [ "$gateway_model_ready" -ne 1 ]; then
echo "Gateway model endpoint did not stay reachable after Open WebUI startup"
docker inspect "$GW_NAME" --format '{{json .State}}' 2>/dev/null || true
if [ "$(docker inspect -f '{{.State.Running}}' "$GW_NAME" 2>/dev/null || echo false)" = "true" ]; then
docker exec "$GW_NAME" bash -lc 'tail -n 200 /tmp/openwebui-gateway.log' || true
docker_cmd docker inspect "$GW_NAME" --format '{{json .State}}' 2>/dev/null || true
if [ "$(docker_cmd docker inspect -f '{{.State.Running}}' "$GW_NAME" 2>/dev/null || echo false)" = "true" ]; then
docker_cmd docker exec "$GW_NAME" bash -lc 'tail -n 200 /tmp/openwebui-gateway.log' || true
fi
docker logs "$GW_NAME" 2>&1 | tail -n 200 || true
docker logs "$OW_NAME" 2>&1 | tail -n 200 || true
docker_cmd docker logs "$GW_NAME" 2>&1 | tail -n 200 || true
docker_cmd docker logs "$OW_NAME" 2>&1 | tail -n 200 || true
exit 1
fi
echo "Running Open WebUI -> OpenClaw smoke..."
if ! docker exec \
if ! docker_cmd docker exec \
-e "OPENWEBUI_BASE_URL=http://$OW_NAME:$WEBUI_PORT" \
-e "OPENWEBUI_ADMIN_EMAIL=$ADMIN_EMAIL" \
-e "OPENWEBUI_ADMIN_PASSWORD=$ADMIN_PASSWORD" \
@@ -237,13 +243,13 @@ if ! docker exec \
node /app/scripts/e2e/openwebui-probe.mjs >/tmp/openwebui-probe.log 2>&1; then
cat /tmp/openwebui-probe.log 2>/dev/null || true
echo "Open WebUI probe failed; gateway log tail:"
docker inspect "$GW_NAME" --format '{{json .State}}' 2>/dev/null || true
if [ "$(docker inspect -f '{{.State.Running}}' "$GW_NAME" 2>/dev/null || echo false)" = "true" ]; then
docker exec "$GW_NAME" bash -lc 'tail -n 200 /tmp/openwebui-gateway.log' || true
docker_cmd docker inspect "$GW_NAME" --format '{{json .State}}' 2>/dev/null || true
if [ "$(docker_cmd docker inspect -f '{{.State.Running}}' "$GW_NAME" 2>/dev/null || echo false)" = "true" ]; then
docker_cmd docker exec "$GW_NAME" bash -lc 'tail -n 200 /tmp/openwebui-gateway.log' || true
fi
docker logs "$GW_NAME" 2>&1 | tail -n 200 || true
docker_cmd docker logs "$GW_NAME" 2>&1 | tail -n 200 || true
echo "Open WebUI container logs:"
docker logs "$OW_NAME" 2>&1 | tail -n 200 || true
docker_cmd docker logs "$OW_NAME" 2>&1 | tail -n 200 || true
exit 1
fi