| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #!/usr/bin/env bash
- #
- # packaging/compat.sh - mixed-version check against a RELEASED version, both ways.
- #
- # packaging/compat.sh <old-version> e.g. packaging/compat.sh 2.14.0
- #
- # 1. this tree's CLIENT against the released <old-version> SERVER
- # (tests/load_test/test_server_info.cpp, phase `old`, plus `server-info`
- # from this tree's CLI);
- # 2. the released <old-version> CLIENT (its CLI and library, from the .debs)
- # against this tree's SERVER.
- #
- # Run it before every one-sided release (packaging/build.sh --only client|server):
- # the side you do not release stays at its old version on every host, so this
- # is the combination those hosts will actually run.
- #
- # Needs: docker, a built tree (packaging/dev.sh build), and the released .debs
- # in a smartbotics-deb-repo checkout ($DEB_REPO_DIR, default: next to this one).
- # Everything runs in throwaway containers on their own network namespaces.
- set -euo pipefail
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
- ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
- OLD="${1:?usage: packaging/compat.sh <old-version>}"
- DEB_REPO_DIR="${DEB_REPO_DIR:-$(dirname "$ROOT")/smartbotics-deb-repo}"
- POOL="$DEB_REPO_DIR/repo/pool/trixie/main"
- DEV_IMAGE="${BASE_IMAGE_NAME:-smartbotic-db-build-base:debian13}"
- REV="${DEB_REVISION:-1}"
- for p in smartbotic-database libsmartbotic-db-client smartbotic-db-cli; do
- [[ -f "$POOL/${p}_${OLD}-${REV}_amd64.deb" ]] || {
- echo "missing $POOL/${p}_${OLD}-${REV}_amd64.deb"; exit 1; }
- done
- [[ -x "$ROOT/build/service/smartbotic-database" ]] || {
- echo "no build: run packaging/dev.sh build first"; exit 1; }
- WORK="$ROOT/build/compat"
- mkdir -p "$WORK"
- OLD_SRV=sbdb-compat-oldsrv
- NEW_SRV=sbdb-compat-newsrv
- cleanup() { docker rm -f "$OLD_SRV" "$NEW_SRV" >/dev/null 2>&1 || true; }
- trap cleanup EXIT
- cleanup
- cat > "$WORK/config.json" <<'CFG'
- {"storage":{"data_directory":"/tmp/sbdb-data","bind_address":"127.0.0.1","rpc_port":9030,
- "encryption":{"enabled":false},"migrations":{"enabled":false},"replication":{"enabled":false}}}
- CFG
- wait_ready() {
- for _ in $(seq 1 240); do
- docker logs "$1" 2>&1 | grep -q "Notified systemd: READY" && return 0
- docker inspect -f '{{.State.Running}}' "$1" 2>/dev/null | grep -q true || break
- sleep 1
- done
- echo "server in $1 did not become ready:"; docker logs "$1" 2>&1 | tail -20; return 1
- }
- FAILED=0
- echo "=== 1. client $(cat "$ROOT/VERSION") (this tree) -> server $OLD (released) ==="
- docker run -d --name "$OLD_SRV" -v "$POOL:/pool:ro" -v "$WORK/config.json:/c.json:ro" \
- debian:trixie bash -c "
- apt-get update -qq >/dev/null &&
- apt-get install -y -qq /pool/smartbotic-database_${OLD}-${REV}_amd64.deb \
- /pool/libsmartbotic-db-client_${OLD}-${REV}_amd64.deb >/dev/null 2>&1 &&
- exec smartbotic-database --config /c.json" >/dev/null
- wait_ready "$OLD_SRV"
- docker run --rm -u "$(id -u):$(id -g)" -e HOME=/tmp -v "$ROOT:$ROOT" -w "$ROOT" "$DEV_IMAGE" \
- g++ -std=c++20 -O1 -o build/compat/t tests/load_test/test_server_info.cpp \
- -Iclient/include -Ibuild/client -Lbuild/client -lsmartbotic-db-client -lspdlog -lfmt -pthread
- in_old_net() {
- docker run --rm -u "$(id -u):$(id -g)" -e HOME=/tmp --network "container:$OLD_SRV" \
- -v "$ROOT:$ROOT" -w "$ROOT" -e LD_LIBRARY_PATH="$ROOT/build/client" "$DEV_IMAGE" "$@"
- }
- in_old_net build/compat/t old 127.0.0.1:9030 2>&1 | grep -v '\[error\]\|\[info\]' || FAILED=1
- in_old_net build/cli/smartbotic-db-cli --address 127.0.0.1:9030 server-info 2>&1 | grep -v '\[info\]' \
- | tee "$WORK/server-info-old.txt"
- grep -q "predates 2.15.0" "$WORK/server-info-old.txt" || {
- # A released server new enough to answer is fine too; it must name itself.
- grep -q "server: $OLD" "$WORK/server-info-old.txt" || { echo "FAIL: server-info"; FAILED=1; }
- }
- docker rm -f "$OLD_SRV" >/dev/null
- echo ""
- echo "=== 2. client $OLD (released) -> server $(cat "$ROOT/VERSION") (this tree) ==="
- docker run -d --name "$NEW_SRV" -u "$(id -u):$(id -g)" -e HOME=/tmp -v "$ROOT:$ROOT" -w "$ROOT" \
- -v "$WORK/config.json:/c.json:ro" "$DEV_IMAGE" \
- build/service/smartbotic-database --config /c.json >/dev/null
- wait_ready "$NEW_SRV"
- cat > "$WORK/old-client.sh" <<'EOS'
- #!/usr/bin/env bash
- # Inside debian:trixie: the released CLI and library against this tree's server.
- set -u
- apt-get update -qq >/dev/null
- apt-get install -y -qq "/pool/libsmartbotic-db-client_${OLD}-${REV}_amd64.deb" \
- "/pool/smartbotic-db-cli_${OLD}-${REV}_amd64.deb" >/dev/null 2>&1 || { echo "FAIL: install"; exit 1; }
- # CLI packages before 2.15.0 did not declare liblmdb0 / libssl3t64, so alone
- # (without the server package) the CLI could not start. Say so, then supply
- # them so the protocol check below still means something.
- if ! smartbotic-db-cli --version >/dev/null 2>&1; then
- echo "note: the released $OLD CLI does not start on its own (undeclared libraries); installing them"
- apt-get install -y -qq liblmdb0 libssl3t64 >/dev/null 2>&1
- fi
- fail=0
- # The command's own exit code decides; output is kept for the grep checks.
- cli() { smartbotic-db-cli --address 127.0.0.1:9030 --project compat "$@" > /tmp/out 2>&1; }
- check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; sed 's/^/ /' /tmp/out | tail -3; fail=1; fi; }
- smartbotic-db-cli --version | head -2
- check "upsert" 'cli upsert things t1 "{\"k\":\"a\",\"n\":1}"'
- check "get" 'cli get things t1 && grep -q "\"k\"" /tmp/out'
- check "find --eq" 'cli find things --eq k a && grep -q t1 /tmp/out'
- check "count" 'cli count things && grep -q 1 /tmp/out'
- check "index-create" 'cli index-create things k'
- check "indexes" 'cli indexes things && grep -q "k " /tmp/out'
- check "collections" 'cli collections && grep -q things /tmp/out'
- check "remove" 'cli remove things t1'
- check "count after" 'cli count things && grep -q 0 /tmp/out'
- check "status" 'cli status && grep -qi "read-only" /tmp/out'
- exit $fail
- EOS
- chmod +x "$WORK/old-client.sh"
- docker run --rm --network "container:$NEW_SRV" -e OLD="$OLD" -e REV="$REV" \
- -v "$POOL:/pool:ro" -v "$WORK/old-client.sh:/old-client.sh:ro" debian:trixie bash /old-client.sh \
- || FAILED=1
- echo ""
- if [[ $FAILED -ne 0 ]]; then echo "COMPAT FAILED against $OLD"; exit 1; fi
- echo "OK - compatible with $OLD in both directions"
|