Files
clean-architecture-backend-…/scripts/ci/redis-topology.sh
T
DongHyeonka 74b0599f12 fix(ci): Redis topology 스크립트가 데몬 호스트 주소를 바르게 읽는다
redis-topology.sh는 job 컨테이너의 기본 게이트웨이(=Docker 데몬 호스트)를
/proc/net/route에서 awk로 읽었다. awk는 "0x.." 문자열을 0으로 읽어 주소가
0.0.0.0이 됐고, 포워더가 자기 자신에게 이어 붙어 "Too many open files"로
main.yml 수동 실행(run 52)의 redis-topology 11행이 모두 실패했다.

python3로 little-endian 16진수를 바르게 바꾸고, 주소가 없거나 0.0.0.0이면
그 자리에서 실패한다.

검증: 노트북에서 같은 계산이 기본 게이트웨이를 낸다. runner 재실행은
다음 main.yml 수동 실행에서.
2026-11-09 06:56:38 +09:00

75 lines
3.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# One Redis topology lane against a real server: start the Compose topology, run the leaves'
# `redisTopologyTest` for it, print the evidence manifest, stop the topology. Called by the
# `redis-topology` nightly job of .gitea/workflows/main.yml (one call per matrix row); a person can
# run the same line on a machine with Docker.
#
# bash scripts/ci/redis-topology.sh <standalone|sentinel|cluster|tls> <redis version>
#
# The lanes are explicitOnly: they need the endpoint this script passes, so no stage runs them
# (docs/redis/support-matrix.md records which lane produced which evidence). Each Gradle task fails
# closed on its own account: an unknown mode, a missing endpoint, a lane with no tagged test class
# and a run that executed zero tests are all errors.
set -euo pipefail
topology=${1:?topology}
version=${2:?redis version}
cd "$(dirname "${BASH_SOURCE[0]}")/../.."
compose=(docker compose -f "src/adapter/outbound/redis-sdk/compose/${topology}/compose.yml")
forwarder=''
stop() {
[ -z "${forwarder}" ] || kill "${forwarder}" 2>/dev/null || true
"${compose[@]}" down -v
}
trap stop EXIT
runtime=:adapter:outbound:redis-runtime:redisTopologyTest
sdk=:adapter:outbound:redis-sdk:redisTopologyTest
semantic=:adapter:outbound:cache-redis:redisTopologyTest
extra=()
case "${topology}" in
standalone) port=6379; ports=(6379); tasks=("${runtime}" "${sdk}" "${semantic}") ;;
sentinel) port=27010; ports=(7010 7011 27010 27011 27012); tasks=("${runtime}" "${sdk}"); extra=(-Predis.topology.master=skeleton) ;;
cluster) port=7100; ports=(7100 7101 7102 7103 7104 7105); tasks=("${runtime}" "${sdk}" "${semantic}") ;;
tls) port=6390; ports=(6390); tasks=("${runtime}") ;;
*) echo "redis-topology: unknown topology ${topology}" >&2; exit 2 ;;
esac
REDIS_VERSION=${version} "${compose[@]}" up -d --wait
# Inside a CI job container the Docker daemon's ports are on the daemon host, not on localhost, and
# the lanes are built around localhost (cluster redirects announce 127.0.0.1, the TLS certificate
# names localhost). Forward them, so the lane runs exactly as it does on a workstation.
if [ -f /.dockerenv ]; then
# The default gateway of the job's network is the daemon host. /proc/net/route stores it as
# little-endian hex; awk reads "0x.." as 0 and would point the forwarder at itself.
daemon_host=$(python3 -c 'import socket, struct
for line in open("/proc/net/route").readlines()[1:]:
fields = line.split()
if fields[1] == "00000000":
print(socket.inet_ntoa(struct.pack("<L", int(fields[2], 16))))
break')
[ -n "${daemon_host}" ] && [ "${daemon_host}" != 0.0.0.0 ] \
|| { echo "redis-topology: no default gateway to reach the Docker daemon host" >&2; exit 1; }
python3 scripts/ci/forward-ports.py "${daemon_host}" "${ports[@]}" &
forwarder=$!
sleep 1
fi
# The tag says 7.4; the digest says which 7.4. Evidence that names only the tag cannot be reproduced
# once the tag moves, so a run that cannot name its digest has nothing to certify.
digest=$(docker image inspect --format '{{index .RepoDigests 0}}' "redis:${version}")
[ -n "${digest}" ] || { echo "redis-topology: no repository digest for redis:${version}" >&2; exit 1; }
if [ "${topology}" = tls ]; then
trust=$(mktemp "${RUNNER_TEMP:-/tmp}/redis-lane-ca.XXXXXX")
"${compose[@]}" cp redis:/tls/ca.crt "${trust}"
extra=(-Predis.topology.trust-material="${trust}")
fi
(cd src && ./gradlew "${tasks[@]}" --continue \
-Predis.topology.host=localhost -Predis.topology.port="${port}" -Predis.topology.mode="${topology}" \
"${extra[@]}")
printf 'evidence: commit=%s run=%s topology=%s redis_version=%s image_digest=%s\n' \
"$(git rev-parse HEAD)" "${GITHUB_RUN_ID:-local}" "${topology}" "${version}" "${digest}"