Run isolated PostgreSQL and RustFS tests in Gitea CI
This commit is contained in:
+12
-22
@@ -1,27 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
# Only new, disposable containers; no production connection settings are consumed.
|
||||
export COMPOSE_PROJECT_NAME="btcdata-archive-test-$$"
|
||||
# Only disposable containers; no production connection settings or published ports.
|
||||
export COMPOSE_PROJECT_NAME="btcdata-archive-test-${GITHUB_RUN_ID:-$$}-${GITHUB_RUN_ATTEMPT:-1}"
|
||||
compose=(docker compose -f tests/integration/compose.yaml)
|
||||
trap '"${compose[@]}" down -v' EXIT
|
||||
"${compose[@]}" up -d
|
||||
export TEST_PGHOST=127.0.0.1 TEST_PGPORT=15432 TEST_PGUSER=postgres TEST_PGPASSWORD=disposable-test
|
||||
export TEST_S3_ENDPOINT_URL=http://127.0.0.1:19000
|
||||
export TEST_S3_ACCESS_KEY=disposable-test TEST_S3_SECRET_KEY=disposable-test-secret
|
||||
python - <<'PY'
|
||||
import os, time
|
||||
import boto3, psycopg
|
||||
from botocore.config import Config
|
||||
for attempt in range(90):
|
||||
try:
|
||||
with psycopg.connect(host=os.environ['TEST_PGHOST'], port=os.environ['TEST_PGPORT'], user='postgres', password='disposable-test', dbname='postgres', connect_timeout=2):
|
||||
pass
|
||||
boto3.client('s3', endpoint_url=os.environ['TEST_S3_ENDPOINT_URL'], aws_access_key_id='disposable-test', aws_secret_access_key='disposable-test-secret', region_name='us-east-1', config=Config(connect_timeout=2, read_timeout=2, retries={'max_attempts': 0}, s3={'addressing_style': 'path'})).list_buckets()
|
||||
break
|
||||
except Exception:
|
||||
time.sleep(2)
|
||||
else:
|
||||
raise SystemExit('disposable PostgreSQL/RustFS did not become ready')
|
||||
PY
|
||||
python -m pytest -q tests/integration
|
||||
"${compose[@]}" up -d postgres rustfs
|
||||
"${compose[@]}" create --no-deps tests
|
||||
runner="$("${compose[@]}" ps -aq tests)"
|
||||
# CI's workspace is inside its job container, not on the Docker host. Copy only
|
||||
# test inputs; never bind-mount the workspace or copy .env, .git, or production secrets.
|
||||
COPYFILE_DISABLE=1 tar -cf - requirements-test.lock src tests sql \
|
||||
scripts/archive-old-weeks.sh scripts/list-archives.sh scripts/wait-test-infrastructure.py \
|
||||
| docker cp - "$runner:/app"
|
||||
docker start --attach "$runner"
|
||||
exit "$(docker inspect --format '{{.State.ExitCode}}' "$runner")"
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
"""Wait only for explicitly configured disposable integration services."""
|
||||
import os
|
||||
import time
|
||||
|
||||
import boto3
|
||||
from botocore.config import Config
|
||||
import psycopg
|
||||
|
||||
|
||||
for attempt in range(90):
|
||||
try:
|
||||
with psycopg.connect(host=os.environ['TEST_PGHOST'], port=os.environ['TEST_PGPORT'],
|
||||
user=os.environ['TEST_PGUSER'], password=os.environ['TEST_PGPASSWORD'],
|
||||
dbname='postgres', connect_timeout=2):
|
||||
pass
|
||||
boto3.client('s3', endpoint_url=os.environ['TEST_S3_ENDPOINT_URL'],
|
||||
aws_access_key_id=os.environ['TEST_S3_ACCESS_KEY'],
|
||||
aws_secret_access_key=os.environ['TEST_S3_SECRET_KEY'], region_name='us-east-1',
|
||||
config=Config(connect_timeout=2, read_timeout=2, retries={'max_attempts': 0},
|
||||
s3={'addressing_style': 'path'})).list_buckets()
|
||||
break
|
||||
except Exception as error:
|
||||
last_error = type(error).__name__
|
||||
time.sleep(2)
|
||||
else:
|
||||
raise SystemExit('Disposable PostgreSQL/RustFS did not become ready: ' + last_error)
|
||||
Reference in New Issue
Block a user