|
| 1 | +#!/bin/bash |
| 2 | +# Self-contained PostGIS reproduction test. |
| 3 | +# Spins up postgis/postgis via docker compose, exposes it as the POSTGIS |
| 4 | +# Sling connection, runs the pipeline, then tears the container down. |
| 5 | +# |
| 6 | +# Usage: bash run_docker_test.sh |
| 7 | +# Requires: Docker (with compose v2), a built sling binary at cmd/sling/sling |
| 8 | +set -e |
| 9 | + |
| 10 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 11 | +SLING_CLI_DIR="$(cd "$SCRIPT_DIR/../../../../.." && pwd)" |
| 12 | +CMD_DIR="$SLING_CLI_DIR/cmd/sling" |
| 13 | +SLING_BIN="$CMD_DIR/sling" |
| 14 | + |
| 15 | +if [ ! -x "$SLING_BIN" ]; then |
| 16 | + echo "Building sling binary..." |
| 17 | + (cd "$CMD_DIR" && go build .) |
| 18 | +fi |
| 19 | + |
| 20 | +cleanup() { |
| 21 | + echo "=== Tearing down PostGIS container ===" |
| 22 | + docker compose -f "$SCRIPT_DIR/docker-compose.yaml" down -v --remove-orphans >/dev/null 2>&1 || true |
| 23 | +} |
| 24 | +trap cleanup EXIT |
| 25 | + |
| 26 | +echo "=== Starting PostGIS container ===" |
| 27 | +docker compose -f "$SCRIPT_DIR/docker-compose.yaml" up -d --wait |
| 28 | + |
| 29 | +# The postgis image bootstraps once on first start: postgres comes up, runs the |
| 30 | +# init SQL that loads the extensions, then shuts postgres down and restarts it. |
| 31 | +# pg_isready / a single SELECT can succeed during the init phase only to be |
| 32 | +# refused seconds later. Wait until the bootstrap log line appears and then |
| 33 | +# require N consecutive successful SQL probes from the host. |
| 34 | +echo "=== Waiting for PostGIS bootstrap to finish ===" |
| 35 | +for i in $(seq 1 60); do |
| 36 | + if docker logs sling-test-postgis 2>&1 | grep -q "database system is ready to accept connections" \ |
| 37 | + && docker logs sling-test-postgis 2>&1 | grep -q "PostgreSQL init process complete"; then |
| 38 | + break |
| 39 | + fi |
| 40 | + if [ "$i" = "60" ]; then |
| 41 | + echo "ERROR: PostGIS init did not finish in time" |
| 42 | + docker logs sling-test-postgis | tail -40 |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + sleep 1 |
| 46 | +done |
| 47 | + |
| 48 | +echo "=== Waiting for stable SQL connections from host ===" |
| 49 | +stable=0 |
| 50 | +for i in $(seq 1 60); do |
| 51 | + if docker exec sling-test-postgis psql -U postgres -d postgis_test -tAc "SELECT 1" >/dev/null 2>&1; then |
| 52 | + stable=$((stable + 1)) |
| 53 | + if [ "$stable" -ge 3 ]; then |
| 54 | + echo "PostGIS stable." |
| 55 | + break |
| 56 | + fi |
| 57 | + else |
| 58 | + stable=0 |
| 59 | + fi |
| 60 | + if [ "$i" = "60" ]; then |
| 61 | + echo "ERROR: PostGIS did not become stable in time" |
| 62 | + docker logs sling-test-postgis | tail -40 |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + sleep 1 |
| 66 | +done |
| 67 | + |
| 68 | +# Expose container as the POSTGIS Sling connection for this run only. |
| 69 | +export POSTGIS='postgres://postgres:postgres@127.0.0.1:55432/postgis_test?sslmode=disable' |
| 70 | + |
| 71 | +echo "=== Running PostGIS pipeline test ===" |
| 72 | +"$SLING_BIN" run -d -p "$SCRIPT_DIR/p.41.postgis_geometry.yaml" |
| 73 | + |
| 74 | +echo "=== PostGIS reproduction test completed ===" |
0 commit comments