Skip to content

Commit

Permalink
DRY configuration of postgresql
Browse files Browse the repository at this point in the history
Signed-off-by: Oz N Tiram <[email protected]>
  • Loading branch information
oz123 committed Dec 20, 2023
1 parent 6bc814b commit 035dc57
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ base-image:
install marmot -o root -g root -m 755 /opt/spectrocloud/bin/ && \
rm -f marmot \
curl -sL https://github.com/k3s-io/kine/releases/download/v${KINE_VERSION}/kine-amd64 | install -m 755 /dev/stdin /opt/spectrocloud/bin/kine
IF [ TWO_NODE_BACKEND = "postgres" ]
IF [ $OS_DISTRIBUTION = "ubuntu" ]
ARG PG_CONF_DIR=/etc/postgresql/16/main/
ELSE IF [ $OS_DISTRIBUTION = "opensuse-leap" ]
ARG PG_CONF_DIR=/var/lib/pgsql/data/
END
END
END

IF [ "$OS_DISTRIBUTION" = "ubuntu" ] && [ "$ARCH" = "amd64" ]
Expand Down Expand Up @@ -283,13 +290,7 @@ base-image:
gpg --batch --yes --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg postgresql.asc && \
rm postgresql.asc && \
apt update && \
apt install -y postgresql-16 postgresql-contrib-16 iputils-ping && \
# prepare postgresql for replication
sed -i '/^#wal_level = replica/ s/#wal_level = replica/wal_level = logical/' /etc/postgresql/16/main/postgresql.conf
sed -i '/^#max_worker_processes = 8/ s/#max_worker_processes = 8/max_worker_processes = 16/' /etc/postgresql/16/main/postgresql.conf
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /etc/postgresql/16/main/postgresql.conf
echo "host all all 0.0.0.0/0 md5" | sudo tee -a /etc/postgresql/16/main/pg_hba.conf
systemctl enable postgresql
apt install -y postgresql-16 postgresql-contrib-16 iputils-ping
END
END
Expand Down Expand Up @@ -322,11 +323,6 @@ base-image:
RUN zypper --non-interactive --quiet addrepo --refresh -p 90 http://download.opensuse.org/repositories/server:database:postgresql/openSUSE_Tumbleweed/ PostgreSQL && \
zypper --gpg-auto-import-keys ref && \
zypper install -y postgresql-16 postgresql-server-16 postgresql-contrib iputils && \
sed -i '/^#wal_level = replica/ s/#wal_level = replica/wal_level = logical/' /var/lib/pgsql/data/postgresql.conf
sed -i '/^#max_worker_processes = 8/ s/#max_worker_processes = 8/max_worker_processes = 16/' /var/lib/pgsql/data/postgresql.conf
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /var/lib/pgsql/data/postgresql.conf
echo "host all all 0.0.0.0/0 md5" | sudo tee -a /var/lib/pgsql/data/pg_hba.conf
systemctl enable postresql
END
END
RUN zypper install -y zstd vim
Expand Down Expand Up @@ -363,6 +359,14 @@ base-image:
RUN if grep "security=selinux" /etc/cos/bootargs.cfg > /dev/null; then sed -i 's/security=selinux //g' /etc/cos/bootargs.cfg; fi &&\
if grep "selinux=1" /etc/cos/bootargs.cfg > /dev/null; then sed -i 's/selinux=1/selinux=0/g' /etc/cos/bootargs.cfg; fi
IF $TWO_NODE
sed -i '/^#wal_level = replica/ s/#wal_level = replica/wal_level = logical/' $PG_CONF_DIR/postgresql.conf
sed -i '/^#max_worker_processes = 8/ s/#max_worker_processes = 8/max_worker_processes = 16/' $PG_CONF_DIR/postgresql.conf
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" $PG_CONF_DIR/postgresql.conf
echo "host all all 0.0.0.0/0 md5" | sudo tee -a PG_CONF_DIR/pg_hba.conf
systemctl enable postresql
END
# Used to build the installer image. The installer ISO will be created from this.
iso-image:
FROM --platform=linux/${ARCH} +base-image
Expand Down

0 comments on commit 035dc57

Please sign in to comment.