Files
pages/tools/ci/test-postgres.sh
T
Anya Tokugawa 940a9137b4
Build and publish container images / images (push) Successful in 14m5s
Release container images / release (push) Successful in 15s
fix(ci): allow synthetic executable fixtures on PostgreSQL test tmpfs
2026-11-15 06:01:35 +09:00

42 lines
1.7 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# Synthetic data only. Share the PostgreSQL network namespace so neither
# published ports nor a newly allocated Docker subnet are needed.
suffix="${GITHUB_RUN_ID:-local}-$$-${RANDOM}"
postgres="pageswiki-postgres-test-${suffix}"
tests="pageswiki-postgres-go-${suffix}"
test_image="pageswiki-postgres-test:${suffix}"
cleanup() {
docker rm -fv "$tests" "$postgres" >/dev/null 2>&1 || true
docker image rm "$test_image" >/dev/null 2>&1 || true
}
trap cleanup EXIT
docker build --target source --tag "$test_image" .
docker run --detach --name "$postgres" --network none \
--env POSTGRES_DB=pageswiki_test \
--env POSTGRES_PASSWORD=pageswiki-synthetic-ci-only \
"${PAGESWIKI_CI_POSTGRES_IMAGE:-postgres:17}"
ready=false
for ((attempt=0; attempt<30; attempt++)); do
if docker exec "$postgres" pg_isready -U postgres -d pageswiki_test >/dev/null 2>&1; then
ready=true
break
fi
sleep 1
done
if [[ "$ready" != true ]]; then
echo 'Synthetic PostgreSQL did not become ready' >&2
exit 1
fi
# Docker --tmpfs defaults to noexec, unlike the Dockerfile test stage's
# BuildKit tmpfs. Test helpers put synthetic pdfinfo/7z executables in TMPDIR.
# Keep execution enabled only in this disposable test container's scratch.
docker run --rm --name "$tests" --network "container:$postgres" \
--tmpfs /test-tmp:rw,exec,size=2147483648 \
--env TMPDIR=/test-tmp --env GOTMPDIR=/tmp \
--env GOPROXY=off --env GOSUMDB=off \
--env PAGESWIKI_TEST_POSTGRES_DSN='postgres://postgres:pageswiki-synthetic-ci-only@127.0.0.1:5432/pageswiki_test?sslmode=disable' \
"$test_image" sh -ec 'cp /bin/busybox /test-tmp/busybox; /test-tmp/busybox true; exec go test -p 1 ./...'