Skip to content

Instantly share code, notes, and snippets.

@lesovsky
Last active December 31, 2023 15:42
Show Gist options
  • Save lesovsky/488f19674a929b7cb3965caf9e91175e to your computer and use it in GitHub Desktop.
Save lesovsky/488f19674a929b7cb3965caf9e91175e to your computer and use it in GitHub Desktop.
docker-compose with postgresql replication (no volumes, no scripts)
image: golang:1.21.0
stages:
- test
tests/integration:
stage: test
parallel:
matrix:
- VERSION:
- "16-alpine3.18"
# - "15-alpine3.18"
# - "14-alpine3.18"
# - "13-alpine3.18"
# - "12-alpine3.18"
# - "11-alpine3.18"
# - "10-alpine3.16" # there is no image with -alpine3.18
# - "9.6"
# - "9.5"
services:
- name: postgres:${VERSION}
alias: postgres
command:
- bash
- -c
- echo -n -e "#!/bin/bash\necho \"host replication all all trust\" >>/var/lib/postgresql/data/pg_hba.conf\npsql -U postgres -c \"SELECT pg_reload_conf()\"" > /docker-entrypoint-initdb.d/hba.sh; chmod 755 /docker-entrypoint-initdb.d/hba.sh; docker-entrypoint.sh postgres -c 'shared_preload_libraries="pg_stat_statements"'
- name: postgres:${VERSION}
alias: standby
command:
- bash
- -c
- until pg_isready -h postgres; do sleep 1; done && pg_basebackup -P -R -X stream -c fast -h postgres -U postgres -D /var/lib/postgresql/data; docker-entrypoint.sh postgres
variables:
FF_NETWORK_PER_BUILD: "true"
POSTGRES_HOST_AUTH_METHOD: trust
image: golang:1.21.0-alpine3.18
before_script:
- apk add git curl make procps postgresql-client
- while [ $(psql -qAtX -h postgres -U postgres -c 'SELECT count(1) FROM pg_stat_replication') -eq 0 ]; do sleep 1; done
- psql -h postgres -U postgres -d postgres -c "TABLE pg_stat_replication"
- make build
script:
- ./build/otel-collector --config config_ci_primary.yml &> primary.out &
- while [ $(curl -s -o /dev/null -w "%{http_code}" 127.0.0.1:8889/metrics) -ne 200 ] ; do sleep 1; done
- curl -s 127.0.0.1:8889/metrics |grep -oE '^postgresql_[a-z]+' |sort |uniq -c |sort -rnk1
- /usr/bin/pkill -15 -f otel-collector || echo "process not found, ok"
# add the same tests against standby
artifacts:
paths:
- ./primary.out
version: "3.9"
services:
primary:
image: postgres:15rc1
ports:
- "15432:5432"
environment:
POSTGRES_HOST_AUTH_METHOD: trust
command:
- bash
- -c
- echo -n -e "#!/bin/bash\necho \"host replication all all trust\" >>/var/lib/postgresql/data/pg_hba.conf\npsql -U postgres -c \"SELECT pg_reload_conf()\"" > /docker-entrypoint-initdb.d/test.sh; chmod 755 /docker-entrypoint-initdb.d/test.sh; docker-entrypoint.sh postgres
standby:
image: postgres:15rc1
ports:
- "15433:5432"
environment:
POSTGRES_HOST_AUTH_METHOD: trust
command:
- bash
- -c
- until pg_isready -h primary; do sleep 1; done && pg_basebackup -P -R -X stream -c fast -h primary -U postgres -D /var/lib/postgresql/data; docker-entrypoint.sh postgres
depends_on: [ primary ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment