Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .github/workflows/spockbench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ jobs:
--build-arg PGVER=${{ matrix.pgver }} \
-t spock -f tests/docker/Dockerfile-step-1.el9 .

- name: Start docker
run: |
cd ${GITHUB_WORKSPACE}/tests/docker/
echo PG_VER=${{ matrix.pgver }} >> pgedge.env
docker compose up

- name: Check spockbench output
run: |
cd ${GITHUB_WORKSPACE}/tests/docker
./check-outputs.sh

- name: Run regression tests
run: |
REG_CT_NAME="spock-regress-${{ matrix.pgver }}-${{ github.run_id }}-${{ github.run_attempt }}"
Expand Down Expand Up @@ -104,14 +115,3 @@ jobs:
if-no-files-found: ignore
retention-days: 7

- name: Start docker
run: |
cd ${GITHUB_WORKSPACE}/tests/docker/
echo PG_VER=${{ matrix.pgver }} >> pgedge.env
docker compose up

- name: Check spockbench output
run: |
cd ${GITHUB_WORKSPACE}/tests/docker
./check-outputs.sh

3 changes: 3 additions & 0 deletions tests/docker/Dockerfile-step-1.el9
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM ghcr.io/pgedge/base-test-image:latest

# Base image already has Rocky Linux, PostgreSQL, and pgedge installed
# We only need to compile Spock extension against the existing PostgreSQL
# Base image ends as USER pgedge, but we need root for installation
USER root

Expand All @@ -10,6 +12,7 @@ ENV PGVER=$PGVER
ENV PATH="/home/pgedge/pgedge/pg${PGVER}/bin:${PATH}"
ENV LD_LIBRARY_PATH="/home/pgedge/pgedge/pg${PGVER}/lib:${LD_LIBRARY_PATH}"
ENV PG_CONFIG="/home/pgedge/pgedge/pg${PGVER}/bin/pg_config"
ENV SPOCK_SOURCE_DIR="/home/pgedge/spock"

# Copy spock source code and set proper ownership
COPY . /home/pgedge/spock
Expand Down
62 changes: 61 additions & 1 deletion tests/docker/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
# see [pgedge-docker repo](https://github.com/pgedge/pgedge-docker) repo for container guidance
# Docker infrastructure for the Spock testing

This document describes how the Docker infrastructure is organized, how to use it for
testing locally and as a part of a GitHub Actions workflow.

## Structure

The Spock Docker environment provides one `stable` image cached by the URL ghcr.io/pgedge/base-test-image:latest and a `floating` one, created on the fly during the tests.

The `stable` image is created according to the `Dockerfile-base.el9` file and should be built manually by the `cache-base-image.yml` workflow. It contains a Rocky Linux image with a complete set of libraries necessary for the Postgres build and passing regression and TAP tests. This image does not define an entry point.

The `floating` image is defined by the `Dockerfile-step-1.el9` file and is intended to be used in tests. This image defines a default `tests/docker/entrypoint.sh` entry point.

### Main parameters of the `stable` image
* Base OS: Rocky Linux 9
* Default user: `pgedge` (with sudo privileges, password: `asdf`)
* Current working directory: `/home/pgedge`
* SSH keys: id_ed25519 and corresponding id_ed25519.pub in the folder `~/.ssh` are provided (authorized for passwordless SSH as pgedge user)
* Includes complete PostgreSQL build dependencies (LLVM, ICU, SSL, etc.)
* Testing tools: Perl Test::More, SSH server/client configured

### Main parameters of the `floating` image
* Based on the `stable` image
* Build arguments:
* `PGVER` - PostgreSQL major version to build (e.g., 15, 16, 17, 18)
* `MAKE_JOBS=4` - number of parallel make jobs (default: 4)
* Default user: `pgedge`
* Current working directory: `/home/pgedge`
* PostgreSQL installation:
* Source: Cloned from official PostgreSQL GitHub repository (latest stable tag for specified major version)
* Location: `/home/pgedge/postgres` (source code)
* Install prefix: `/home/pgedge/pgedge/pg${PGVER}`
* Patches: Spock-specific patches from `/home/pgedge/spock/patches/${PGVER}/` are applied before compilation
* Build configuration: Debug mode enabled (`-g -O0`), with TAP tests, LLVM, assertions, dtrace, and full extension support
* pgEdge CLI tool:
* Installed via `https://pgedge-download.s3.amazonaws.com/REPO/install.py`
* Location: `/home/pgedge/pgedge/pgedge`
* Spock extension:
* Source: Copied from build context to `/home/pgedge/spock`
* Compiled and installed against the patched PostgreSQL
* Environment variables:
* `PGVER` - PostgreSQL major version
* `PATH` - includes `/home/pgedge/pgedge/pg${PGVER}/bin`
* `LD_LIBRARY_PATH` - includes `/home/pgedge/pgedge/pg${PGVER}/lib`
* `PG_CONFIG` - points to `/home/pgedge/pgedge/pg${PGVER}/bin/pg_config`
* Test scripts: All `tests/docker/*.sh` scripts available in `/home/pgedge/`
* Default entrypoint: `/home/pgedge/entrypoint.sh`

## Usage

Each test type - regression, TAP tests, spockbech or any new one must employ the `Dockerfile-step-1` docker image in tests. An instance initialisation and launch commands must be implemented in an entry point. If test builds custom environment (like regression or TAP tests) it have to define separate docker entry point.

For example, `tests/docker/run-spock-regress.sh` is an entry point for regression tests; `tests/tap/run_tests.sh` is an entry point for TAP tests. In opposite, spockbench creates three-node infrastructure based on the `docker/tests/docker-compose.yml` script and default entry point.

## Notes

* If you need an extra package, add it to the `Dockerfile-base.el9` file, updating the library list. Afterwards, re-run the workflow to rebuild the image.

## References

* See the [pgedge-docker repo](https://github.com/pgedge/pgedge-docker) for container guidance
27 changes: 26 additions & 1 deletion tests/docker/check-outputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@ set -euo pipefail

containers=$(docker ps -aq --filter "label=com.docker.compose.project=tests");

if [ -z "$containers" ]; then
echo "FAIL: No containers found with label 'com.docker.compose.project=tests'"
exit 1
fi

for cid in $containers; do
name=$(docker inspect -f '{{ .Name }}' "$cid" | sed 's|/||')
exit_code=$(docker inspect -f '{{ .State.ExitCode }}' "$cid")

# Check exit code
if [ "$exit_code" -ne 0 ]; then
name=$(docker inspect -f '{{ .Name }}' "$cid" | sed 's|/||')
echo "FAIL: Container '$name' exited with code $exit_code"
docker logs "$cid" 2>&1 | tail -50
exit 1
fi

# Check PostgreSQL logs for errors
if docker exec "$cid" test -d /home/pgedge/pgedge/data 2>/dev/null; then
pg_log=$(docker exec "$cid" find /home/pgedge/pgedge/data -name "postgresql-*.log" -o -name "*.log" 2>/dev/null | head -1)
if [ -n "$pg_log" ]; then
error_count=$(docker exec "$cid" grep -i "ERROR:" "$pg_log" 2>/dev/null | grep -v "ERROR: relation.*does not exist" | wc -l || echo 0)
if [ "$error_count" -gt 0 ]; then
echo "FAIL: Container '$name' has $error_count ERROR(s) in PostgreSQL logs"
docker exec "$cid" grep -i "ERROR:" "$pg_log" | grep -v "ERROR: relation.*does not exist" | tail -20
exit 1
fi
fi
fi

echo "✓ Container '$name' passed all checks"
done

echo "✓ All containers passed validation"
90 changes: 78 additions & 12 deletions tests/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,100 @@ function wait_for_pg()
done
}

. /home/pgedge/pgedge/pg$PGVER/pg$PGVER.env
ls -la /home/pgedge/
ls -la /home/pgedge/pgedge
. pg${PG_VER}/pg${PG_VER}.env
echo 'export LD_LIBRARY_PATH=/home/pgedge/pgedge/pg${PG_VER}/lib:$LD_LIBRARY_PATH' >> /home/pgedge/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/lib64:$LD_LIBRARY_PATH' >> /home/pgedge/.bashrc
echo 'export PATH=/home/pgedge/pgedge/pg${PG_VER}/bin:$PATH' >> /home/pgedge/.bashrc
. /home/pgedge/.bashrc

echo "==========Installing Spockbench=========="
cd ~/spockbench
sudo python3 setup.py install

cd ~/pgedge
sed -i '/log_min_messages/s/^#//g' data/pg$PGVER/postgresql.conf
sed -i -e '/log_min_messages =/ s/= .*/= debug1/' data/pg$PGVER/postgresql.conf
./pgedge restart

wait_for_pg
# Initialize PostgreSQL if not already done
if [ ! -d "data/pg$PGVER" ]; then
echo "==========Initializing PostgreSQL $PGVER=========="

# Initialize the database cluster
pg${PGVER}/bin/initdb -D data/pg${PGVER} --encoding=UTF8 --locale=C

# Configure PostgreSQL with settings from regress-postgresql.conf
cat >> data/pg${PGVER}/postgresql.conf <<EOF

# Spock configuration
shared_preload_libraries = 'spock'
wal_level = logical
max_wal_senders = 20
max_replication_slots = 20
max_worker_processes = 20
track_commit_timestamp = on
max_locks_per_transaction = 1000

# Connection settings
#unix_socket_directories = '/tmp'
listen_addresses = '*'
port = 5432

# Logging
log_line_prefix = '[%m] [%p] [%d] '
log_min_messages = debug1

# Performance (for testing)
fsync = off

# Spock settings
spock.synchronous_commit = true
EOF

# Configure pg_hba.conf for network access
cat >> data/pg${PGVER}/pg_hba.conf <<EOF

# Allow replication connections
host replication all 0.0.0.0/0 trust
host all all 0.0.0.0/0 trust
EOF

# Start PostgreSQL
pg${PGVER}/bin/pg_ctl -D data/pg${PGVER} -l data/pg${PGVER}/logfile.log start

wait_for_pg

# Create database and user
export DBUSER=${DBUSER:-pgedge}
export DBNAME=${DBNAME:-demo}

pg${PGVER}/bin/createuser -h /tmp -s $DBUSER 2>/dev/null || true
pg${PGVER}/bin/createdb -h /tmp -O $DBUSER $DBNAME 2>/dev/null || true

echo "==========PostgreSQL $PGVER initialized successfully=========="
else
# PostgreSQL already initialized, just start it
pg${PGVER}/bin/pg_ctl -D data/pg${PGVER} -l data/pg${PGVER}/logfile.log start
wait_for_pg
fi

# Ensure environment variables are set
export DBUSER=${DBUSER:-pgedge}
export DBNAME=${DBNAME:-demo}

psql -h /tmp -U $DBUSER -d $DBNAME -c "drop extension spock;"
psql -h /tmp -U $DBUSER -d $DBNAME -c "drop schema public cascade;"
psql -h /tmp -U $DBUSER -d $DBNAME -c "create schema public;"
psql -h /tmp -U $DBUSER -d $DBNAME -c "create extension spock;"
# This code executes on a fresh system that means we have a clean Postgres
# instance.
psql -h /tmp -U $DBUSER -d $DBNAME -c "CREATE EXTENSION spock;"

./pgedge restart
# Restart PostgreSQL to apply all settings
pg${PGVER}/bin/pg_ctl -D data/pg${PGVER} restart -l data/pg${PGVER}/logfile.log

wait_for_pg

echo "==========Assert Spock version is the latest=========="
expected_line=$(grep '#define SPOCK_VERSION' /home/pgedge/spock/spock.h)
expected_line=$(grep '#define SPOCK_VERSION' ${SPOCK_SOURCE_DIR}/include/spock.h)
expected_version=$(echo "$expected_line" | grep -oP '"\K[0-9]+\.[0-9]+\.[0-9]+')
expected_major=${expected_version%%.*}
actual_version=$(psql -U $DBUSER -d $DBNAME -X -t -A -c "select spock.spock_version()")
actual_version=$(psql -U $DBUSER -d $DBNAME -X -t -A -c "SELECT spock.spock_version()")
actual_major=${actual_version%%.*}

if (( actual_major >= expected_major )); then
Expand Down
2 changes: 1 addition & 1 deletion tests/docker/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

#set -euo pipefail
set -euo pipefail

peer_names=$1

Expand Down
Loading