-
Notifications
You must be signed in to change notification settings - Fork 0
Add PostgreSQL functional tests with real containers in CI #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,51 @@ services: | |
| aliases: | ||
| - proxysql | ||
|
|
||
| pgprimary: | ||
| image: postgres:17 | ||
| hostname: pgprimary | ||
| environment: | ||
| POSTGRES_PASSWORD: testpass | ||
| POSTGRES_USER: postgres | ||
| volumes: | ||
| - ./postgres/init-primary.sh:/docker-entrypoint-initdb.d/init.sh | ||
| ports: | ||
| - "15432:5432" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U postgres"] | ||
| interval: 5s | ||
| timeout: 3s | ||
| retries: 30 | ||
| networks: | ||
| orchnet: | ||
| aliases: | ||
| - pgprimary | ||
|
|
||
| pgstandby1: | ||
| image: postgres:17 | ||
| hostname: pgstandby1 | ||
| environment: | ||
| POSTGRES_PASSWORD: testpass | ||
| PGUSER: postgres | ||
| PGPASSWORD: repl_pass | ||
| volumes: | ||
| - ./postgres/init-standby.sh:/init-standby.sh | ||
| entrypoint: ["/bin/bash", "/init-standby.sh"] | ||
| depends_on: | ||
| pgprimary: | ||
| condition: service_healthy | ||
| ports: | ||
| - "15433:5432" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U postgres"] | ||
| interval: 5s | ||
| timeout: 3s | ||
| retries: 30 | ||
| networks: | ||
| orchnet: | ||
| aliases: | ||
| - pgstandby1 | ||
|
|
||
|
Comment on lines
+115
to
+139
|
||
| orchestrator: | ||
| image: ubuntu:24.04 | ||
| hostname: orchestrator | ||
|
|
@@ -122,6 +167,36 @@ services: | |
| aliases: | ||
| - orchestrator | ||
|
|
||
| orchestrator-pg: | ||
| image: ubuntu:24.04 | ||
| hostname: orchestrator-pg | ||
| volumes: | ||
| - ../../bin/orchestrator:/usr/local/bin/orchestrator:ro | ||
| - ../../resources:/orchestrator/resources:ro | ||
| - ./orchestrator-pg-test.conf.json:/orchestrator/orchestrator.conf.json:ro | ||
| command: > | ||
| bash -c " | ||
| apt-get update -qq && apt-get install -y -qq curl sqlite3 > /dev/null 2>&1 && | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running |
||
| rm -f /tmp/orchestrator-pg-test.sqlite3 && | ||
| cd /orchestrator && | ||
| orchestrator -config orchestrator.conf.json http | ||
| " | ||
| ports: | ||
| - "3098:3098" | ||
| depends_on: | ||
| pgprimary: | ||
| condition: service_healthy | ||
| healthcheck: | ||
| test: ["CMD", "curl", "-sf", "http://localhost:3098/api/clusters"] | ||
| interval: 5s | ||
| timeout: 3s | ||
| retries: 60 | ||
| start_period: 15s | ||
| networks: | ||
| orchnet: | ||
| aliases: | ||
| - orchestrator-pg | ||
|
|
||
| networks: | ||
| orchnet: | ||
| driver: bridge | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "Debug": true, | ||
| "ListenAddress": ":3098", | ||
| "ProviderType": "postgresql", | ||
| "PostgreSQLTopologyUser": "orchestrator", | ||
| "PostgreSQLTopologyPassword": "orch_pass", | ||
| "PostgreSQLSSLMode": "disable", | ||
| "MySQLOrchestratorHost": "", | ||
| "MySQLOrchestratorPort": 0, | ||
| "BackendDB": "sqlite", | ||
| "SQLite3DataFile": "/tmp/orchestrator-pg-test.sqlite3", | ||
| "DiscoverByShowSlaveHosts": false, | ||
| "InstancePollSeconds": 5, | ||
| "RecoveryPeriodBlockSeconds": 10, | ||
| "RecoverMasterClusterFilters": [".*"], | ||
| "RecoverIntermediateMasterClusterFilters": [".*"], | ||
| "AutoPseudoGTID": false, | ||
| "PrometheusEnabled": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/bin/bash | ||
| # Initialize PostgreSQL primary for functional tests. | ||
| # This script runs inside the postgres Docker entrypoint (initdb phase). | ||
|
|
||
| set -e | ||
|
|
||
| # ---- WAL / replication settings ---- | ||
| cat >> "$PGDATA/postgresql.conf" <<EOF | ||
| wal_level = replica | ||
| max_wal_senders = 10 | ||
| wal_keep_size = 256MB | ||
| hot_standby = on | ||
| listen_addresses = '*' | ||
| EOF | ||
|
|
||
| # ---- pg_hba: allow replication and orchestrator connections ---- | ||
| cat >> "$PGDATA/pg_hba.conf" <<EOF | ||
| # Allow replication connections from any host in the Docker network | ||
| host replication repl all md5 | ||
| # Allow orchestrator monitoring user | ||
| host all orchestrator all md5 | ||
| EOF | ||
|
|
||
| # ---- Create users ---- | ||
| psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname postgres <<-EOSQL | ||
| -- Replication user | ||
| CREATE ROLE repl WITH REPLICATION LOGIN PASSWORD 'repl_pass'; | ||
|
|
||
| -- Orchestrator monitoring user | ||
| CREATE ROLE orchestrator WITH LOGIN PASSWORD 'orch_pass'; | ||
| GRANT pg_monitor TO orchestrator; | ||
| -- Allow orchestrator to promote standbys and reload config | ||
| ALTER ROLE orchestrator SUPERUSER; | ||
| EOSQL | ||
|
Comment on lines
+29
to
+34
|
||
|
|
||
| echo "Primary initialization complete." | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||
| #!/bin/bash | ||||||
| # Initialize a PostgreSQL standby via pg_basebackup from the primary. | ||||||
| # This script replaces the default entrypoint for standby containers. | ||||||
|
|
||||||
| set -e | ||||||
|
|
||||||
| PGDATA="/var/lib/postgresql/data" | ||||||
| PRIMARY_HOST="pgprimary" | ||||||
| PRIMARY_PORT=5432 | ||||||
|
|
||||||
| echo "Waiting for primary to accept connections..." | ||||||
| until pg_isready -h "$PRIMARY_HOST" -p "$PRIMARY_PORT" -U postgres; do | ||||||
|
||||||
| until pg_isready -h "$PRIMARY_HOST" -p "$PRIMARY_PORT" -U postgres; do | |
| until pg_isready -h "$PRIMARY_HOST" -p "$PRIMARY_PORT" -U repl; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the
pgstandby1service the libpq environment variables are inconsistent (PGUSER: postgresbutPGPASSWORD: repl_pass). This can break readiness checks / any libpq client defaults, and it makes the intended authentication unclear. SetPGUSER/PGPASSWORDto the same account you expect to use (e.g.,PGUSER: replwithPGPASSWORD: repl_pass, or keeppostgreswithtestpass).