Skip to content

Commit

Permalink
Merge pull request #43 from cybertec-postgresql/fixUpgrade
Browse files Browse the repository at this point in the history
Fix upgrade
  • Loading branch information
Schmaetz authored Jul 15, 2024
2 parents 022f94d + fa75ae4 commit ded800a
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 10 deletions.
25 changes: 21 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ postgres-gis: base postgres-gis
postgres-oracle: base postgres-oracle
pgbouncer: pgbouncer
exporter: exporter
publicbeta: publicbeta
publicbeta: publicbeta-pg publicbeta-pgbackrest

base-build:
docker build $(ROOTPATH) --no-cache \
docker build $(ROOTPATH) \
--file $(ROOTPATH)/docker/base/Dockerfile \
--tag cybertec-pg-container/base:$(BASEOS)-$(BUILD) \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
Expand Down Expand Up @@ -174,7 +174,7 @@ exporter-build:

exporter: exporter-build

publicbeta-build:
publicbeta-pg-build:
docker build $(ROOTPATH) \
--file $(ROOTPATH)/docker/pg-public-beta/Dockerfile \
--tag cybertec-pg-container/postgres:$(IMAGE_TAG)-beta${PUBLICBETA} \
Expand All @@ -191,4 +191,21 @@ publicbeta-build:
--build-arg PGVERSION=$(BETAVERSION) \
--build-arg ARCH=$(ARCH)

publicbeta: publicbeta-build
publicbeta-pg: publicbeta-pg-build

publicbeta-pgbackrest-build:
docker build $(ROOTPATH) \
--file $(ROOTPATH)/docker/pgbackrest-public-beta/Dockerfile \
--tag cybertec-pg-container/pgbackrest:$(IMAGE_TAG)-beta${PUBLICBETA} \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg CONTAINERIMAGE=${CONTAINERIMAGE} \
--build-arg IMAGE_REPOSITORY=$(IMAGE_REPOSITORY) \
--build-arg BASEOS=$(BASEOS) \
--build-arg PACKAGER=$(PACKAGER) \
--build-arg CONTAINERSUITE=$(CONTAINERSUITE) \
--build-arg BUILD=$(BUILD) \
--build-arg PGBACKREST_VERSION=$(PGBACKREST_VERSION) \
--build-arg OLD_PG_VERSIONS="$(OLD_PG_VERSIONS)" \
--build-arg PGVERSION=$(BETAVERSION)

publicbeta-pgbackrest: publicbeta-pgbackrest-build;
163 changes: 163 additions & 0 deletions docker/pgbackrest-public-beta/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
ARG CONTAINERSUITE
ARG BUILD
ARG BASEOS
ARG CONTAINERIMAGE

FROM ${CONTAINERSUITE}/base:${BASEOS}-${BUILD} AS builder

# Dockerfile specific informations
ARG PACKAGER
ARG PGBACKREST_VERSION
ARG PGVERSION
ARG OLD_PG_VERSIONS
ARG PG_SUPPORTED_VERSIONS="$OLD_PG_VERSIONS $PGVERSION"

# Enable Beta-Repo
RUN ${PACKAGER} config-manager --set-enabled pgdg${PGVERSION}-updates-testing \
&& ${PACKAGER} config-manager --set-enabled pgdg${PGVERSION}-source-updates-testing \
&& ${PACKAGER} -y update;

RUN ${PACKAGER} -y install --nodocs \
--setopt=skip_missing_names_on_install=False \
openssh-clients \
openssh-server \
bzip2 \
lz4 \
zstd \
libicu \
dumb-init \
jq \
pgbackrest-${PGBACKREST_VERSION} \
&& ${PACKAGER} -y clean all ;

# Install postgres-server
RUN ${PACKAGER} -y update \
&& for version in $PG_SUPPORTED_VERSIONS; do \
${PACKAGER} -y install --nodocs postgresql${version}-server; \
done \
&& ${PACKAGER} -y clean all;

# Remove default pgbackrest-config
RUN rm /etc/pgbackrest.conf
RUN rm -rf /var/spool/pgbackrest

# Add kubectl
RUN curl -LO https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl && chmod +x kubectl

RUN mkdir -p /tmp/pgsql && cp -r /usr/pgsql* /tmp/pgsql
RUN mkdir -p /tmp/pg && cp -r /usr/bin/pg* /tmp/pg
RUN mkdir -p /tmp/lz4 && cp -r /usr/bin/lz4* /tmp/lz4
RUN mkdir -p /tmp/zstd && cp -r /usr/bin/zstd* /tmp/zstd


FROM ${CONTAINERIMAGE} as micro

ARG PGVERSION

COPY --from=builder /usr/bin/dumb-init /usr/bin/dumb-init
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /usr/lib64 /usr/lib64
# SSH-client
COPY --from=builder /etc/ssh /etc/ssh
COPY --from=builder /usr/bin/ssh /usr/bin/ssh
COPY --from=builder /usr/libexec/openssh /usr/libexec/openssh
# pgBackRest
COPY --from=builder /usr/bin/pgbackrest /usr/bin/pgbackrest
COPY --from=builder /usr/share/licenses/pgbackrest/LICENSE /usr/share/licenses/pgbackrest/LICENSE
COPY --from=builder /var/lib/pgbackrest /var/lib/pgbackrest
COPY --from=builder /var/log/pgbackrest /var/log/pgbackrest
# Postgres
COPY --from=builder /tmp/pgsql/ /usr/
COPY --from=builder /var/lib/pgsql /var/lib/pgsql
COPY --from=builder /tmp/pg /usr/bin/

COPY --from=builder ./kubectl /usr/local/bin/
# lz4
COPY --from=builder /tmp/lz4 /usr/bin/
# zstd
COPY --from=builder /tmp/zstd /usr/bin/
# Others
COPY --from=builder /usr/bin/sed /usr/bin/sed
COPY --from=builder /usr/bin/jq /usr/bin/jq
COPY --from=builder /usr/bin/watch /usr/bin/watch
COPY --from=builder /usr/share/locale /usr/share/locale
COPY --from=builder /usr/lib /usr/lib
COPY --from=builder /usr/lib64 /usr/lib64
# CA
COPY --from=builder /usr/bin/ca-legacy /usr/bin/ca-legacy
COPY --from=builder /usr/bin/update-ca-trust /usr/bin/update-ca-trust
# grep
COPY --from=builder /etc/profile.d /etc/profile.d
COPY --from=builder /usr/bin/grep /usr/bin/grep
COPY --from=builder /usr/libexec /usr/libexec
# COPY --from=builder /usr/bin/update-ca-trust /usr/bin/update-ca-trust
# COPY --from=builder /usr/bin/update-ca-trust /usr/bin/update-ca-trust

# p11-kit
COPY --from=builder /etc/pkcs11 /etc/pkcs11
COPY --from=builder /usr/libexec/p11-kit /usr/libexec/p11-kit
COPY --from=builder /usr/share/bash-completion/completions /usr/share/bash-completion/completions
COPY --from=builder /usr/share/p11-kit /usr/share/p11-kit
COPY --from=builder /usr/share/polkit-1 /usr/share/polkit-1

COPY --from=builder /usr/bin/p11-kit /usr/bin/p11-kit
COPY --from=builder /etc/pki /etc/pki
COPY --from=builder /usr/share/pki /usr/share/pki
COPY --from=builder /etc/ssl /etc/ssl
COPY --from=builder /etc/pkcs11 /etc/pkcs11

# p11-kit-trust
COPY --from=builder /usr/bin/trust /usr/bin/

# libraries
COPY --from=builder /usr/bin/nss_wrapper.pl /usr/bin/nss_wrapper.pl
# COPY --from=builder /usr/lib64/libnss_wrapper.so /usr/lib64/libnss_wrapper.so
COPY --from=builder /usr/share/man/man1 /usr/share/man/man1
COPY --from=builder /usr/bin/envsubst /usr/bin/envsubst

RUN /usr/bin/update-ca-trust extract

# add postgres user and group
#RUN groupadd postgres -g 26 && useradd postgres -u 26 -g 26

# Prepare all needed stuff
Run mkdir -p /opt/pgbackrest /backrestrepo /home/postgres /home/postgres/pgdata/pgbackrest/log

# add pgbackrest-restore files
ADD scripts/pgbackrest/ /opt/pgbackrest/bin/

# add pgbackrest-common files
ADD /scripts/nss_wrapper /scripts/nss_wrapper

FROM scratch
COPY --from=micro / /

ARG PGVERSION

# set user and group ownership
RUN chown -R postgres:postgres /opt/pgbackrest \
/backrestrepo /home/postgres/pgdata/pgbackrest /home/postgres/pgdata

RUN mkdir -p /etc/pgbackrest \
&& chown -R postgres:postgres /etc/pgbackrest

RUN chmod -R g=u /etc/pgbackrest \
&& rm -f /run/nologin

RUN mkdir /.ssh && chown postgres:postgres /.ssh && chmod o+rwx /.ssh

# set user and group ownership
RUN chown -R postgres:postgres /opt/pgbackrest \
/backrestrepo /home/postgres/pgdata

#ENV PATH=$PATH:/usr/pgsql-$PGVERSION/bin
COPY launcher/pgbackrest/launch.sh /

VOLUME ["sshd", "/home/postgres/pgdata", "/backrestrepo"]

ENTRYPOINT ["/scripts/nss_wrapper/nss_wrapper.sh"]

USER 26

CMD ["dumb-init", "/launch.sh", "init"]
10 changes: 5 additions & 5 deletions major_upgrade/pg_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def drop_possibly_incompatible_objects(self):
# cur.execute(cmd)

logger.info('Executing "DROP FUNCTION metric_helpers.pg_stat_statements" in the database="%s"', d)
function call dur cur.execute("DROP FUNCTION IF EXISTS metric_helpers.pg_stat_statements(boolean) CASCADE")
cur.execute("DROP FUNCTION IF EXISTS metric_helpers.pg_stat_statements(boolean) CASCADE")

for ext in ('pg_stat_kcache', 'pg_stat_statements') + self._INCOMPATIBLE_EXTENSIONS:
logger.info('Executing "DROP EXTENSION IF EXISTS %s" in the database="%s"', ext, d)
Expand Down Expand Up @@ -187,10 +187,10 @@ def pg_upgrade(self, check=False):

def prepare_new_pgdata(self, version):
from spilo_commons import append_extensions

locale = self.query('SHOW lc_collate')[0][0]
encoding = self.query('SHOW server_encoding')[0][0]
initdb_config = [{'locale': locale}, {'encoding': encoding}]
locale = self.query("SELECT datcollate FROM pg_database WHERE datname = 'template1'")[0][0]
# encoding = self.query('SHOW server_encoding')[0][0]
initdb_config = [{'locale': locale}, {'locale-provider': 'icu'}]
if self.query("SELECT current_setting('data_checksums')::bool")[0][0]:
initdb_config.append('data-checksums')

Expand Down
1 change: 0 additions & 1 deletion scripts/configure_spilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ def deep_update(a, b):
--port={{CLONE_PORT}} --user="{{CLONE_USER}}"
{{/CLONE_WITH_BASEBACKUP}}
initdb:
- encoding: UTF8
- locale: {{INITDB_LOCALE}}.UTF-8
- data-checksums
- locale-provider: icu
Expand Down

0 comments on commit ded800a

Please sign in to comment.