Files
EventHubBack/scripts/run-stand-api-tests.sh
T
aleksey 046e936eab fix(ci): reuse ApiTests image in e2e instead of blind rebuild.
e2e pulled/reused eventhub-tests from test job or registry; plain buildkit logs if rebuild needed. Root cause of #342 e2e cancel: quiet rebuild + prune + timeout.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 22:57:50 +03:00

109 lines
3.8 KiB
Bash

#!/usr/bin/env bash
# Full API CT suite against live stand (remote) + smoke-core on stand host.
# Usage: run-stand-api-tests.sh <ift|stage>
# Requires: ADMIN_* from load-stand-api-env.sh; SSH_* for smoke-core on stand.
set -euo pipefail
STAND="${1:?stand: ift|stage}"
case "${STAND}" in
ift)
API_HOST="${API_HOST:-https://api.ift.eventhub.local}"
ADMIN_API_HOST="${ADMIN_API_HOST:-https://admin-api.ift.eventhub.local}"
WS_HOST="${WS_HOST:-wss://ws.ift.eventhub.local}"
ADMIN_WS_HOST="${ADMIN_WS_HOST:-wss://admin-ws.ift.eventhub.local}"
DEVOPS_SMOKE="/opt/eventhub-ift/devops/scripts/smoke-core.sh"
;;
stage)
API_HOST="${API_HOST:-https://api.stage.eventhub.local}"
ADMIN_API_HOST="${ADMIN_API_HOST:-https://admin-api.stage.eventhub.local}"
WS_HOST="${WS_HOST:-wss://ws.stage.eventhub.local}"
ADMIN_WS_HOST="${ADMIN_WS_HOST:-wss://admin-ws.stage.eventhub.local}"
DEVOPS_SMOKE="/opt/eventhub-stage/devops/scripts/smoke-core.sh"
;;
*)
echo "Unknown stand: ${STAND}"
exit 1
;;
esac
if [[ -n "${SSH_HOST:-}" && -n "${SSH_USER:-}" && -n "${SSH_KEY:-}" ]]; then
KEY="$(mktemp)"
printf '%s\n' "${SSH_KEY}" > "${KEY}"
chmod 600 "${KEY}"
echo "=== smoke-core on ${STAND} (via SSH) ==="
ssh -i "${KEY}" -o BatchMode=yes -o StrictHostKeyChecking=accept-new \
"${SSH_USER}@${SSH_HOST}" "bash ${DEVOPS_SMOKE} ${STAND}"
rm -f "${KEY}"
else
echo "::warning::SSH_* not set — skip smoke-core on stand host"
fi
echo "=== API CT remote (${STAND}) ==="
echo " API_HOST=${API_HOST}"
echo " ADMIN_API_HOST=${ADMIN_API_HOST}"
echo " WS_HOST=${WS_HOST}"
echo " ADMIN_WS_HOST=${ADMIN_WS_HOST}"
IMAGE="eventhub-api-tests:local"
REG_IMAGE=""
if [[ -n "${GITHUB_SHA:-}" ]]; then
IMAGE="eventhub-api-tests:sha-${GITHUB_SHA:0:12}"
REG_IMAGE="${REGISTRY:-git.sabilin.com/eventhub}/eventhub-api-tests:sha-${GITHUB_SHA:0:12}"
fi
echo "=== ensure API test image (${IMAGE}) ==="
have_image=0
if docker image inspect "${IMAGE}" >/dev/null 2>&1; then
echo " local image present: ${IMAGE}"
have_image=1
elif docker image inspect eventhub-tests:latest >/dev/null 2>&1; then
# act/hostexecutor: test job уже собрал тот же Dockerfile
docker tag eventhub-tests:latest "${IMAGE}"
echo " reused local eventhub-tests:latest → ${IMAGE}"
have_image=1
elif [[ -n "${REG_IMAGE}" ]]; then
if [[ -n "${REGISTRY_USER:-}" && -n "${REGISTRY_PASSWORD:-}" ]]; then
echo "${REGISTRY_PASSWORD}" | docker login git.sabilin.com -u "${REGISTRY_USER}" --password-stdin >/dev/null
fi
if docker pull "${REG_IMAGE}"; then
docker tag "${REG_IMAGE}" "${IMAGE}"
echo " pulled ${REG_IMAGE}"
have_image=1
else
echo " pull failed — will rebuild"
fi
fi
if [[ "${have_image}" -ne 1 ]]; then
# plain: иначе BUILDKIT_PROGRESS=quiet прячет причину падения rebar3
export BUILDKIT_PROGRESS="${BUILDKIT_PROGRESS:-plain}"
bash scripts/retry-docker-build.sh 5 60 -- \
docker buildx build \
--network=host \
--progress=plain \
--file docker/ApiTests.Dockerfile \
--tag "${IMAGE}" \
--load \
--provenance=false \
--sbom=false \
.
fi
docker run --rm --network=host \
-e CT_MODE=remote \
-e "API_HOST=${API_HOST}" \
-e "ADMIN_API_HOST=${ADMIN_API_HOST}" \
-e "WS_HOST=${WS_HOST}" \
-e "ADMIN_WS_HOST=${ADMIN_WS_HOST}" \
-e "ADMIN_SUPER_EMAIL=${ADMIN_SUPER_EMAIL:-}" \
-e "ADMIN_SUPER_PASSWORD=${ADMIN_SUPER_PASSWORD:-}" \
-e "ADMIN_EMAIL=${ADMIN_EMAIL:-}" \
-e "ADMIN_PASSWORD=${ADMIN_PASSWORD:-}" \
-e "ADMIN_MODER_EMAIL=${ADMIN_MODER_EMAIL:-}" \
-e "ADMIN_MODER_PASSWORD=${ADMIN_MODER_PASSWORD:-}" \
-e "ADMIN_SUPPORT_EMAIL=${ADMIN_SUPPORT_EMAIL:-}" \
-e "ADMIN_SUPPORT_PASSWORD=${ADMIN_SUPPORT_PASSWORD:-}" \
"${IMAGE}"
echo "=== API CT passed (${STAND}) ==="