compat.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/env bash
  2. #
  3. # packaging/compat.sh - mixed-version check against a RELEASED version, both ways.
  4. #
  5. # packaging/compat.sh <old-version> e.g. packaging/compat.sh 2.14.0
  6. #
  7. # 1. this tree's CLIENT against the released <old-version> SERVER
  8. # (tests/load_test/test_server_info.cpp, phase `old`, plus `server-info`
  9. # from this tree's CLI);
  10. # 2. the released <old-version> CLIENT (its CLI and library, from the .debs)
  11. # against this tree's SERVER.
  12. #
  13. # Run it before every one-sided release (packaging/build.sh --only client|server):
  14. # the side you do not release stays at its old version on every host, so this
  15. # is the combination those hosts will actually run.
  16. #
  17. # Needs: docker, a built tree (packaging/dev.sh build), and the released .debs
  18. # in a smartbotics-deb-repo checkout ($DEB_REPO_DIR, default: next to this one).
  19. # Everything runs in throwaway containers on their own network namespaces.
  20. set -euo pipefail
  21. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  22. ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
  23. OLD="${1:?usage: packaging/compat.sh <old-version>}"
  24. DEB_REPO_DIR="${DEB_REPO_DIR:-$(dirname "$ROOT")/smartbotics-deb-repo}"
  25. POOL="$DEB_REPO_DIR/repo/pool/trixie/main"
  26. DEV_IMAGE="${BASE_IMAGE_NAME:-smartbotic-db-build-base:debian13}"
  27. REV="${DEB_REVISION:-1}"
  28. for p in smartbotic-database libsmartbotic-db-client smartbotic-db-cli; do
  29. [[ -f "$POOL/${p}_${OLD}-${REV}_amd64.deb" ]] || {
  30. echo "missing $POOL/${p}_${OLD}-${REV}_amd64.deb"; exit 1; }
  31. done
  32. [[ -x "$ROOT/build/service/smartbotic-database" ]] || {
  33. echo "no build: run packaging/dev.sh build first"; exit 1; }
  34. WORK="$ROOT/build/compat"
  35. mkdir -p "$WORK"
  36. OLD_SRV=sbdb-compat-oldsrv
  37. NEW_SRV=sbdb-compat-newsrv
  38. cleanup() { docker rm -f "$OLD_SRV" "$NEW_SRV" >/dev/null 2>&1 || true; }
  39. trap cleanup EXIT
  40. cleanup
  41. cat > "$WORK/config.json" <<'CFG'
  42. {"storage":{"data_directory":"/tmp/sbdb-data","bind_address":"127.0.0.1","rpc_port":9030,
  43. "encryption":{"enabled":false},"migrations":{"enabled":false},"replication":{"enabled":false}}}
  44. CFG
  45. wait_ready() {
  46. for _ in $(seq 1 240); do
  47. docker logs "$1" 2>&1 | grep -q "Notified systemd: READY" && return 0
  48. docker inspect -f '{{.State.Running}}' "$1" 2>/dev/null | grep -q true || break
  49. sleep 1
  50. done
  51. echo "server in $1 did not become ready:"; docker logs "$1" 2>&1 | tail -20; return 1
  52. }
  53. FAILED=0
  54. echo "=== 1. client $(cat "$ROOT/VERSION") (this tree) -> server $OLD (released) ==="
  55. docker run -d --name "$OLD_SRV" -v "$POOL:/pool:ro" -v "$WORK/config.json:/c.json:ro" \
  56. debian:trixie bash -c "
  57. apt-get update -qq >/dev/null &&
  58. apt-get install -y -qq /pool/smartbotic-database_${OLD}-${REV}_amd64.deb \
  59. /pool/libsmartbotic-db-client_${OLD}-${REV}_amd64.deb >/dev/null 2>&1 &&
  60. exec smartbotic-database --config /c.json" >/dev/null
  61. wait_ready "$OLD_SRV"
  62. docker run --rm -u "$(id -u):$(id -g)" -e HOME=/tmp -v "$ROOT:$ROOT" -w "$ROOT" "$DEV_IMAGE" \
  63. g++ -std=c++20 -O1 -o build/compat/t tests/load_test/test_server_info.cpp \
  64. -Iclient/include -Ibuild/client -Lbuild/client -lsmartbotic-db-client -lspdlog -lfmt -pthread
  65. in_old_net() {
  66. docker run --rm -u "$(id -u):$(id -g)" -e HOME=/tmp --network "container:$OLD_SRV" \
  67. -v "$ROOT:$ROOT" -w "$ROOT" -e LD_LIBRARY_PATH="$ROOT/build/client" "$DEV_IMAGE" "$@"
  68. }
  69. in_old_net build/compat/t old 127.0.0.1:9030 2>&1 | grep -v '\[error\]\|\[info\]' || FAILED=1
  70. in_old_net build/cli/smartbotic-db-cli --address 127.0.0.1:9030 server-info 2>&1 | grep -v '\[info\]' \
  71. | tee "$WORK/server-info-old.txt"
  72. grep -q "predates 2.15.0" "$WORK/server-info-old.txt" || {
  73. # A released server new enough to answer is fine too; it must name itself.
  74. grep -q "server: $OLD" "$WORK/server-info-old.txt" || { echo "FAIL: server-info"; FAILED=1; }
  75. }
  76. docker rm -f "$OLD_SRV" >/dev/null
  77. echo ""
  78. echo "=== 2. client $OLD (released) -> server $(cat "$ROOT/VERSION") (this tree) ==="
  79. docker run -d --name "$NEW_SRV" -u "$(id -u):$(id -g)" -e HOME=/tmp -v "$ROOT:$ROOT" -w "$ROOT" \
  80. -v "$WORK/config.json:/c.json:ro" "$DEV_IMAGE" \
  81. build/service/smartbotic-database --config /c.json >/dev/null
  82. wait_ready "$NEW_SRV"
  83. cat > "$WORK/old-client.sh" <<'EOS'
  84. #!/usr/bin/env bash
  85. # Inside debian:trixie: the released CLI and library against this tree's server.
  86. set -u
  87. apt-get update -qq >/dev/null
  88. apt-get install -y -qq "/pool/libsmartbotic-db-client_${OLD}-${REV}_amd64.deb" \
  89. "/pool/smartbotic-db-cli_${OLD}-${REV}_amd64.deb" >/dev/null 2>&1 || { echo "FAIL: install"; exit 1; }
  90. # CLI packages before 2.15.0 did not declare liblmdb0 / libssl3t64, so alone
  91. # (without the server package) the CLI could not start. Say so, then supply
  92. # them so the protocol check below still means something.
  93. if ! smartbotic-db-cli --version >/dev/null 2>&1; then
  94. echo "note: the released $OLD CLI does not start on its own (undeclared libraries); installing them"
  95. apt-get install -y -qq liblmdb0 libssl3t64 >/dev/null 2>&1
  96. fi
  97. fail=0
  98. # The command's own exit code decides; output is kept for the grep checks.
  99. cli() { smartbotic-db-cli --address 127.0.0.1:9030 --project compat "$@" > /tmp/out 2>&1; }
  100. check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; sed 's/^/ /' /tmp/out | tail -3; fail=1; fi; }
  101. smartbotic-db-cli --version | head -2
  102. check "upsert" 'cli upsert things t1 "{\"k\":\"a\",\"n\":1}"'
  103. check "get" 'cli get things t1 && grep -q "\"k\"" /tmp/out'
  104. check "find --eq" 'cli find things --eq k a && grep -q t1 /tmp/out'
  105. check "count" 'cli count things && grep -q 1 /tmp/out'
  106. check "index-create" 'cli index-create things k'
  107. check "indexes" 'cli indexes things && grep -q "k " /tmp/out'
  108. check "collections" 'cli collections && grep -q things /tmp/out'
  109. check "remove" 'cli remove things t1'
  110. check "count after" 'cli count things && grep -q 0 /tmp/out'
  111. check "status" 'cli status && grep -qi "read-only" /tmp/out'
  112. exit $fail
  113. EOS
  114. chmod +x "$WORK/old-client.sh"
  115. docker run --rm --network "container:$NEW_SRV" -e OLD="$OLD" -e REV="$REV" \
  116. -v "$POOL:/pool:ro" -v "$WORK/old-client.sh:/old-client.sh:ro" debian:trixie bash /old-client.sh \
  117. || FAILED=1
  118. echo ""
  119. if [[ $FAILED -ne 0 ]]; then echo "COMPAT FAILED against $OLD"; exit 1; fi
  120. echo "OK - compatible with $OLD in both directions"