Skip to content
Merged
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
2 changes: 1 addition & 1 deletion 12/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN yum -y module enable postgresql:12 && \
INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="rsync tar gettext nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \
INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
Expand Down
2 changes: 1 addition & 1 deletion 12/root/usr/bin/run-postgresql-slave
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ generate_passwd_file
generate_postgresql_config

wait_for_postgresql_master
export MASTER_FQDN=$(postgresql_master_addr)
export MASTER_FQDN=${POSTGRESQL_MASTER_IP}
initialize_replica

unset_env_vars
Expand Down
23 changes: 3 additions & 20 deletions 12/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,6 @@ function unset_env_vars() {
unset POSTGRESQL_{DATABASE,USER,PASSWORD,ADMIN_PASSWORD}
}

# postgresql_master_addr lookups the 'postgresql-master' DNS and get list of the available
# endpoints. Each endpoint is a PostgreSQL container with the 'master' PostgreSQL running.
function postgresql_master_addr() {
local service_name=${POSTGRESQL_MASTER_SERVICE_NAME:-postgresql-master}
local endpoints=$(dig ${service_name} A +search | grep ";${service_name}" | cut -d ';' -f 2 2>/dev/null)
# FIXME: This is for debugging (docker run)
if [ -v POSTGRESQL_MASTER_IP ]; then
endpoints=${POSTGRESQL_MASTER_IP:-}
fi
if [ -z "$endpoints" ]; then
>&2 echo "Failed to resolve PostgreSQL master IP address"
exit 3
fi
echo -n "$(echo $endpoints | cut -d ' ' -f 1)"
}

# Converts the version in format x.y or x.y.z to a number.
version2number ()
{
Expand Down Expand Up @@ -290,12 +274,11 @@ function set_pgdata ()

function wait_for_postgresql_master() {
while true; do
master_fqdn=$(postgresql_master_addr)
echo "Waiting for PostgreSQL master (${master_fqdn}) to accept connections ..."
echo "Waiting for PostgreSQL master (${POSTGRESQL_MASTER_IP}) to accept connections ..."
if [ -v POSTGRESQL_ADMIN_PASSWORD ]; then
PGPASSWORD=${POSTGRESQL_ADMIN_PASSWORD} psql "postgresql://postgres@${master_fqdn}" -c "SELECT 1;" && return 0
PGPASSWORD=${POSTGRESQL_ADMIN_PASSWORD} psql "postgresql://postgres@${POSTGRESQL_MASTER_IP}" -c "SELECT 1;" && return 0
else
PGPASSWORD=${POSTGRESQL_PASSWORD} psql "postgresql://${POSTGRESQL_USER}@${master_fqdn}/${POSTGRESQL_DATABASE}" -c "SELECT 1;" && return 0
PGPASSWORD=${POSTGRESQL_PASSWORD} psql "postgresql://${POSTGRESQL_USER}@${POSTGRESQL_MASTER_IP}/${POSTGRESQL_DATABASE}" -c "SELECT 1;" && return 0
fi
sleep 1
done
Expand Down
2 changes: 1 addition & 1 deletion 13/Dockerfile.c9s
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN { yum -y module enable postgresql:13 || :; } && \
INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="rsync tar gettext nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \
INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
Expand Down
2 changes: 1 addition & 1 deletion 13/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN yum -y module enable postgresql:13 && \
INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="rsync tar gettext nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \
INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
Expand Down
2 changes: 1 addition & 1 deletion 13/root/usr/bin/run-postgresql-slave
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ generate_passwd_file
generate_postgresql_config

wait_for_postgresql_master
export MASTER_FQDN=$(postgresql_master_addr)
export MASTER_FQDN=${POSTGRESQL_MASTER_IP}
initialize_replica

unset_env_vars
Expand Down
23 changes: 3 additions & 20 deletions 13/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,6 @@ function unset_env_vars() {
unset POSTGRESQL_{DATABASE,USER,PASSWORD,ADMIN_PASSWORD}
}

# postgresql_master_addr lookups the 'postgresql-master' DNS and get list of the available
# endpoints. Each endpoint is a PostgreSQL container with the 'master' PostgreSQL running.
function postgresql_master_addr() {
local service_name=${POSTGRESQL_MASTER_SERVICE_NAME:-postgresql-master}
local endpoints=$(dig ${service_name} A +search | grep ";${service_name}" | cut -d ';' -f 2 2>/dev/null)
# FIXME: This is for debugging (docker run)
if [ -v POSTGRESQL_MASTER_IP ]; then
endpoints=${POSTGRESQL_MASTER_IP:-}
fi
if [ -z "$endpoints" ]; then
>&2 echo "Failed to resolve PostgreSQL master IP address"
exit 3
fi
echo -n "$(echo $endpoints | cut -d ' ' -f 1)"
}

# Converts the version in format x.y or x.y.z to a number.
version2number ()
{
Expand Down Expand Up @@ -290,12 +274,11 @@ function set_pgdata ()

function wait_for_postgresql_master() {
while true; do
master_fqdn=$(postgresql_master_addr)
echo "Waiting for PostgreSQL master (${master_fqdn}) to accept connections ..."
echo "Waiting for PostgreSQL master (${POSTGRESQL_MASTER_IP}) to accept connections ..."
if [ -v POSTGRESQL_ADMIN_PASSWORD ]; then
PGPASSWORD=${POSTGRESQL_ADMIN_PASSWORD} psql "postgresql://postgres@${master_fqdn}" -c "SELECT 1;" && return 0
PGPASSWORD=${POSTGRESQL_ADMIN_PASSWORD} psql "postgresql://postgres@${POSTGRESQL_MASTER_IP}" -c "SELECT 1;" && return 0
else
PGPASSWORD=${POSTGRESQL_PASSWORD} psql "postgresql://${POSTGRESQL_USER}@${master_fqdn}/${POSTGRESQL_DATABASE}" -c "SELECT 1;" && return 0
PGPASSWORD=${POSTGRESQL_PASSWORD} psql "postgresql://${POSTGRESQL_USER}@${POSTGRESQL_MASTER_IP}/${POSTGRESQL_DATABASE}" -c "SELECT 1;" && return 0
fi
sleep 1
done
Expand Down
2 changes: 1 addition & 1 deletion 15/Dockerfile.c9s
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN { yum -y module enable postgresql:15 || :; } && \
INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="rsync tar gettext nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \
INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
Expand Down
2 changes: 1 addition & 1 deletion 15/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# This image must forever use UID 26 for postgres user so our volumes are
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql15-server postgresql15-contrib nss_wrapper postgresql15-upgrade procps-ng util-linux" && \
RUN INSTALL_PKGS="rsync tar gettext postgresql15-server postgresql15-contrib nss_wrapper postgresql15-upgrade procps-ng util-linux" && \
INSTALL_PKGS+=" findutils xz" && \
INSTALL_PKGS+=" postgresql15-pgaudit" && \
dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
Expand Down
2 changes: 1 addition & 1 deletion 15/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN yum -y module enable postgresql:15 && \
INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="rsync tar gettext nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \
INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
Expand Down
2 changes: 1 addition & 1 deletion 15/root/usr/bin/run-postgresql-slave
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ generate_passwd_file
generate_postgresql_config

wait_for_postgresql_master
export MASTER_FQDN=$(postgresql_master_addr)
export MASTER_FQDN=${POSTGRESQL_MASTER_IP}
initialize_replica

unset_env_vars
Expand Down
23 changes: 3 additions & 20 deletions 15/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,6 @@ function unset_env_vars() {
unset POSTGRESQL_{DATABASE,USER,PASSWORD,ADMIN_PASSWORD}
}

# postgresql_master_addr lookups the 'postgresql-master' DNS and get list of the available
# endpoints. Each endpoint is a PostgreSQL container with the 'master' PostgreSQL running.
function postgresql_master_addr() {
local service_name=${POSTGRESQL_MASTER_SERVICE_NAME:-postgresql-master}
local endpoints=$(dig ${service_name} A +search | grep ";${service_name}" | cut -d ';' -f 2 2>/dev/null)
# FIXME: This is for debugging (docker run)
if [ -v POSTGRESQL_MASTER_IP ]; then
endpoints=${POSTGRESQL_MASTER_IP:-}
fi
if [ -z "$endpoints" ]; then
>&2 echo "Failed to resolve PostgreSQL master IP address"
exit 3
fi
echo -n "$(echo $endpoints | cut -d ' ' -f 1)"
}

# Converts the version in format x.y or x.y.z to a number.
version2number ()
{
Expand Down Expand Up @@ -290,12 +274,11 @@ function set_pgdata ()

function wait_for_postgresql_master() {
while true; do
master_fqdn=$(postgresql_master_addr)
echo "Waiting for PostgreSQL master (${master_fqdn}) to accept connections ..."
echo "Waiting for PostgreSQL master (${POSTGRESQL_MASTER_IP}) to accept connections ..."
if [ -v POSTGRESQL_ADMIN_PASSWORD ]; then
PGPASSWORD=${POSTGRESQL_ADMIN_PASSWORD} psql "postgresql://postgres@${master_fqdn}" -c "SELECT 1;" && return 0
PGPASSWORD=${POSTGRESQL_ADMIN_PASSWORD} psql "postgresql://postgres@${POSTGRESQL_MASTER_IP}" -c "SELECT 1;" && return 0
else
PGPASSWORD=${POSTGRESQL_PASSWORD} psql "postgresql://${POSTGRESQL_USER}@${master_fqdn}/${POSTGRESQL_DATABASE}" -c "SELECT 1;" && return 0
PGPASSWORD=${POSTGRESQL_PASSWORD} psql "postgresql://${POSTGRESQL_USER}@${POSTGRESQL_MASTER_IP}/${POSTGRESQL_DATABASE}" -c "SELECT 1;" && return 0
fi
sleep 1
done
Expand Down
2 changes: 1 addition & 1 deletion 16/Dockerfile.c10s
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# This image must forever use UID 26 for postgres user so our volumes are
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN INSTALL_PKGS="rsync tar gettext-envsubst bind-utils nss_wrapper-libs glibc-locale-source xz" && \
RUN INSTALL_PKGS="rsync tar gettext-envsubst nss_wrapper-libs glibc-locale-source xz" && \
PSQL_PKGS="postgresql16-server postgresql16-contrib postgresql16-upgrade" && \
INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS $PSQL_PKGS && \
Expand Down
2 changes: 1 addition & 1 deletion 16/Dockerfile.c9s
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN { yum -y module enable postgresql:16 || :; } && \
INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="rsync tar gettext nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \
INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
Expand Down
2 changes: 1 addition & 1 deletion 16/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# This image must forever use UID 26 for postgres user so our volumes are
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper " && \
RUN INSTALL_PKGS="rsync tar gettext postgresql-server postgresql-contrib nss_wrapper " && \
INSTALL_PKGS+=" procps-ng util-linux postgresql-upgrade" && \
INSTALL_PKGS+=" findutils xz" && \
INSTALL_PKGS+=" pgaudit" && \
Expand Down
2 changes: 1 addition & 1 deletion 16/Dockerfile.rhel10
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# This image must forever use UID 26 for postgres user so our volumes are
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN INSTALL_PKGS="rsync tar gettext-envsubst bind-utils nss_wrapper-libs glibc-locale-source xz" && \
RUN INSTALL_PKGS="rsync tar gettext-envsubst nss_wrapper-libs glibc-locale-source xz" && \
PSQL_PKGS="postgresql16-server postgresql16-contrib" && \
INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \
INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \
Expand Down
2 changes: 1 addition & 1 deletion 16/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN yum -y module enable postgresql:16 && \
INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="rsync tar gettext nss_wrapper-libs postgresql-server postgresql-contrib" && \
INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \
INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
Expand Down
2 changes: 1 addition & 1 deletion 16/root/usr/bin/run-postgresql-slave
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ generate_passwd_file
generate_postgresql_config

wait_for_postgresql_master
export MASTER_FQDN=$(postgresql_master_addr)
export MASTER_FQDN=${POSTGRESQL_MASTER_IP}
initialize_replica

unset_env_vars
Expand Down
23 changes: 3 additions & 20 deletions 16/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,6 @@ function unset_env_vars() {
unset POSTGRESQL_{DATABASE,USER,PASSWORD,ADMIN_PASSWORD}
}

# postgresql_master_addr lookups the 'postgresql-master' DNS and get list of the available
# endpoints. Each endpoint is a PostgreSQL container with the 'master' PostgreSQL running.
function postgresql_master_addr() {
local service_name=${POSTGRESQL_MASTER_SERVICE_NAME:-postgresql-master}
local endpoints=$(dig ${service_name} A +search | grep ";${service_name}" | cut -d ';' -f 2 2>/dev/null)
# FIXME: This is for debugging (docker run)
if [ -v POSTGRESQL_MASTER_IP ]; then
endpoints=${POSTGRESQL_MASTER_IP:-}
fi
if [ -z "$endpoints" ]; then
>&2 echo "Failed to resolve PostgreSQL master IP address"
exit 3
fi
echo -n "$(echo $endpoints | cut -d ' ' -f 1)"
}

# Converts the version in format x.y or x.y.z to a number.
version2number ()
{
Expand Down Expand Up @@ -290,12 +274,11 @@ function set_pgdata ()

function wait_for_postgresql_master() {
while true; do
master_fqdn=$(postgresql_master_addr)
echo "Waiting for PostgreSQL master (${master_fqdn}) to accept connections ..."
echo "Waiting for PostgreSQL master (${POSTGRESQL_MASTER_IP}) to accept connections ..."
if [ -v POSTGRESQL_ADMIN_PASSWORD ]; then
PGPASSWORD=${POSTGRESQL_ADMIN_PASSWORD} psql "postgresql://postgres@${master_fqdn}" -c "SELECT 1;" && return 0
PGPASSWORD=${POSTGRESQL_ADMIN_PASSWORD} psql "postgresql://postgres@${POSTGRESQL_MASTER_IP}" -c "SELECT 1;" && return 0
else
PGPASSWORD=${POSTGRESQL_PASSWORD} psql "postgresql://${POSTGRESQL_USER}@${master_fqdn}/${POSTGRESQL_DATABASE}" -c "SELECT 1;" && return 0
PGPASSWORD=${POSTGRESQL_PASSWORD} psql "postgresql://${POSTGRESQL_USER}@${POSTGRESQL_MASTER_IP}/${POSTGRESQL_DATABASE}" -c "SELECT 1;" && return 0
fi
sleep 1
done
Expand Down
4 changes: 2 additions & 2 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
{{ spec.repo_enable_reason }}
{% endif %}
{% if spec.prod == "c10s" or spec.prod == "rhel10" %}
RUN INSTALL_PKGS="rsync tar gettext-envsubst bind-utils nss_wrapper-libs glibc-locale-source xz" && \
RUN INSTALL_PKGS="rsync tar gettext-envsubst nss_wrapper-libs glibc-locale-source xz" && \
PSQL_PKGS="{{ spec.pkgs }}" && \
{% elif spec.prod == "rhel9" and spec.version == "13" %} \
RUN INSTALL_PKGS="rsync tar gettext bind9.18-utils nss_wrapper-libs {{ spec.pkgs }}" && \
Expand All @@ -63,7 +63,7 @@ RUN {{ spec.environment_setup }}
INSTALL_PKGS="rsync tar gettext bind9.18-utils nss_wrapper-libs {{ spec.pkgs }}" && \
{% else %}
RUN {{ spec.environment_setup }}
INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper-libs {{ spec.pkgs }}" && \
INSTALL_PKGS="rsync tar gettext nss_wrapper-libs {{ spec.pkgs }}" && \
{% endif %}
{% if spec.version not in ["9.6", "10", "11"] %}
INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \
Expand Down
4 changes: 2 additions & 2 deletions src/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
{% if spec.version == "16" %}
RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper " && \
RUN INSTALL_PKGS="rsync tar gettext postgresql-server postgresql-contrib nss_wrapper " && \
INSTALL_PKGS+=" procps-ng util-linux postgresql-upgrade" && \
{% else %}
RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql{{ spec.short }}-server postgresql{{ spec.short }}-contrib nss_wrapper postgresql{{ spec.short }}-upgrade procps-ng util-linux" && \
RUN INSTALL_PKGS="rsync tar gettext postgresql{{ spec.short }}-server postgresql{{ spec.short }}-contrib nss_wrapper postgresql{{ spec.short }}-upgrade procps-ng util-linux" && \
{% endif %}
INSTALL_PKGS+=" findutils xz" && \
{% if spec.version == "16" %}
Expand Down
2 changes: 1 addition & 1 deletion src/root/usr/bin/run-postgresql-slave
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ generate_passwd_file
generate_postgresql_config

wait_for_postgresql_master
export MASTER_FQDN=$(postgresql_master_addr)
export MASTER_FQDN=${POSTGRESQL_MASTER_IP}
initialize_replica

unset_env_vars
Expand Down
23 changes: 3 additions & 20 deletions src/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,6 @@ function unset_env_vars() {
unset POSTGRESQL_{DATABASE,USER,PASSWORD,ADMIN_PASSWORD}
}

# postgresql_master_addr lookups the 'postgresql-master' DNS and get list of the available
# endpoints. Each endpoint is a PostgreSQL container with the 'master' PostgreSQL running.
function postgresql_master_addr() {
local service_name=${POSTGRESQL_MASTER_SERVICE_NAME:-postgresql-master}
local endpoints=$(dig ${service_name} A +search | grep ";${service_name}" | cut -d ';' -f 2 2>/dev/null)
# FIXME: This is for debugging (docker run)
if [ -v POSTGRESQL_MASTER_IP ]; then
endpoints=${POSTGRESQL_MASTER_IP:-}
fi
if [ -z "$endpoints" ]; then
>&2 echo "Failed to resolve PostgreSQL master IP address"
exit 3
fi
echo -n "$(echo $endpoints | cut -d ' ' -f 1)"
}

# Converts the version in format x.y or x.y.z to a number.
version2number ()
{
Expand Down Expand Up @@ -291,12 +275,11 @@ function set_pgdata ()

function wait_for_postgresql_master() {
while true; do
master_fqdn=$(postgresql_master_addr)
echo "Waiting for PostgreSQL master (${master_fqdn}) to accept connections ..."
echo "Waiting for PostgreSQL master (${POSTGRESQL_MASTER_IP}) to accept connections ..."
if [ -v POSTGRESQL_ADMIN_PASSWORD ]; then
PGPASSWORD=${POSTGRESQL_ADMIN_PASSWORD} psql "postgresql://postgres@${master_fqdn}" -c "SELECT 1;" && return 0
PGPASSWORD=${POSTGRESQL_ADMIN_PASSWORD} psql "postgresql://postgres@${POSTGRESQL_MASTER_IP}" -c "SELECT 1;" && return 0
else
PGPASSWORD=${POSTGRESQL_PASSWORD} psql "postgresql://${POSTGRESQL_USER}@${master_fqdn}/${POSTGRESQL_DATABASE}" -c "SELECT 1;" && return 0
PGPASSWORD=${POSTGRESQL_PASSWORD} psql "postgresql://${POSTGRESQL_USER}@${POSTGRESQL_MASTER_IP}/${POSTGRESQL_DATABASE}" -c "SELECT 1;" && return 0
fi
sleep 1
done
Expand Down
2 changes: 1 addition & 1 deletion test/test-lib-postgresql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function test_postgresql_imagestream() {
TEMPLATES="postgresql-ephemeral-template.json
postgresql-persistent-template.json"
for template in $TEMPLATES; do
ct_os_test_image_stream_template "${THISDIR}/imagestreams/postgresql-${OS%[0-9]*}.json" "${THISDIR}/examples/${template}" postgresql "-p POSTGRESQL_VERSION=${VERSION}${tag}"
ct_os_test_image_stream_template "${THISDIR}/imagestreams/postgresql-${OS//[0-9]/}.json" "${THISDIR}/examples/${template}" postgresql "-p POSTGRESQL_VERSION=${VERSION}${tag}"
done
}

Expand Down