-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
postgres-entrypoint.sh
executable file
·46 lines (39 loc) · 1.43 KB
/
postgres-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# This script replaces the default docker entrypoint for postgres in the
# development environment.
# Its job is to ensure postgres is properly configured to support the
# Change Data Capture pipeline (by setting access permissions and installing
# the replication plugin we use for CDC). Unfortunately the default
# Postgres image does not allow this level of configurability so we need
# to do it this way in order not to have to publish and maintain our own
# Postgres image.
#
# This then, at the end, transfers control to the default entrypoint.
set -e
prep_init_db() {
cp /opt/sentry/init_hba.sh /docker-entrypoint-initdb.d/init_hba.sh
}
cdc_setup_hba_conf() {
# Ensure pg-hba is properly configured to allow connections
# to the replication slots.
PG_HBA="$PGDATA/pg_hba.conf"
if [ ! -f "$PG_HBA" ]; then
echo "DB not initialized. Postgres will take care of pg_hba"
elif [ "$(grep -c -E "^host\s+replication" "$PGDATA"/pg_hba.conf)" != 0 ]; then
echo "Replication config already present in pg_hba. Not changing anything."
else
# Execute the same script we run on DB initialization
/opt/sentry/init_hba.sh
fi
}
bind_wal2json() {
# Copy the file in the right place
cp /opt/sentry/wal2json/wal2json.so $(pg_config --pkglibdir)/wal2json.so
}
echo "Setting up Change Data Capture"
prep_init_db
if [ "$1" = 'postgres' ]; then
cdc_setup_hba_conf
bind_wal2json
fi
exec /usr/local/bin/docker-entrypoint.sh "$@"