Skip to content

Commit

Permalink
build pg autofailover ourselves
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ke committed Jan 14, 2023
1 parent 47a8ad7 commit 1f48cfb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
45 changes: 36 additions & 9 deletions pgaf/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
ARG POSTGRES_VERSION
FROM postgres:$POSTGRES_VERSION as build
FROM postgres:$POSTGRES_VERSION as pg_base

FROM pg_base as pgaf_build
ARG POSTGRES_VERSION
ARG POSTGRES_MAJOR_VERSION
ARG PG_AUTO_FAILOVER_VERSION=2.0

ENV PG_CONFIG /usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/bin/pg_config

RUN apt-get update && apt-get install -y \
curl \
gcc \
make \
postgresql-server-dev-${POSTGRES_MAJOR_VERSION} \
libkrb5-dev \
libselinux1-dev \
libxslt1-dev \
libzstd-dev \
liblz4-dev \
libpam-dev \
libreadline-dev \
zlib1g-dev

RUN mkdir -p /build && \
curl -L https://github.com/citusdata/pg_auto_failover/archive/refs/tags/v${PG_AUTO_FAILOVER_VERSION}.tar.gz -o /build/pgaf.tar.gz && \
cd /build && tar -xvf pgaf.tar.gz && \
cd /build/pg_auto_failover-${PG_AUTO_FAILOVER_VERSION} && \
make -s clean && make -s install -j8

# kill all settings on the postgres image
FROM scratch
ARG PG_AUTO_FAILOVER_VERSION=2.0
ARG POSTGRES_VERSION
ARG POSTGRES_MAJOR_VERSION
ENV POSTGRES_MAJOR_VERSION=$POSTGRES_MAJOR_VERSION
COPY --from=build / /
COPY --from=pg_base / /

RUN apt-get update && apt-get install -y curl && \
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list
COPY --from=pgaf_build /usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/lib/pgautofailover.so /usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/lib
COPY --from=pgaf_build /usr/share/postgresql/${POSTGRES_MAJOR_VERSION}/extension/pgautofailover* /usr/share/postgresql/${POSTGRES_MAJOR_VERSION}/extension/
COPY --from=pgaf_build /usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/bin/pg_autoctl /usr/local/bin

# FIXME: install a specific version!
RUN apt-get update && apt-get install -y \
pg-auto-failover-cli \
postgresql-$POSTGRES_MAJOR_VERSION-auto-failover \
sudo
sudo \
libncurses6

RUN mkdir -p /etc/pgaf/
RUN mkdir -p /etc/pgaf/config
Expand Down
8 changes: 4 additions & 4 deletions pgaf/pgaf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ docker_create_db_directories() {
create_monitor() {
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
log "creating data monitor..."
sudo PGDATA=$PGDATA -u postgres /usr/bin/pg_autoctl create monitor \
sudo PGDATA=$PGDATA -u postgres /usr/local/bin/pg_autoctl create monitor \
--pgctl /usr/lib/postgresql/$POSTGRES_MAJOR_VERSION/bin/pg_ctl \
--hostname "${PGAF_HOSTNAME}" \
--skip-pg-hba \
Expand All @@ -67,7 +67,7 @@ create_monitor() {
create_postgres() {
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
log "creating data node..."
sudo PGDATA=$PGDATA -u postgres /usr/bin/pg_autoctl create postgres \
sudo PGDATA=$PGDATA -u postgres /usr/local/bin/pg_autoctl create postgres \
--monitor "postgres://autoctl_node@${PGAF_monitor_node_hostname}:5432/pg_auto_failover" \
--hostname "${PGAF_HOSTNAME}" \
--name "${PGAF_NAME}" \
Expand Down Expand Up @@ -106,11 +106,11 @@ setup_hba() {

pg_autoctl_run() {
log "starting pg_autoctl..."
exec sudo PGDATA=$PGDATA -u postgres /usr/bin/pg_autoctl run
exec sudo PGDATA=$PGDATA -u postgres /usr/local/bin/pg_autoctl run
}

run_pg_autoctl() {
exec sudo PGDATA=$PGDATA -u postgres /usr/bin/pg_autoctl "$@"
exec sudo PGDATA=$PGDATA -u postgres /usr/local/bin/pg_autoctl "$@"
}

run_sql() {
Expand Down

0 comments on commit 1f48cfb

Please sign in to comment.