Skip to content

Commit 7d1760c

Browse files
horsegegunes
andauthored
K8SPG-254 add upgrade image (percona#786)
* K8SPG-254 add upgrade image * add PG14 and PG15 support * add percona-pg_stat_monitor * fix pgaudit version --------- Co-authored-by: Ege Güneş <ege.gunes@percona.com>
1 parent a9f8923 commit 7d1760c

File tree

4 files changed

+330
-0
lines changed

4 files changed

+330
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 - 2023 Crunchy Data Solutions, Inc.
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
#
17+
# start the upgrade job
18+
#
19+
# the service looks for the following env vars to be set by
20+
# the cpm-admin that provisioned us
21+
#
22+
# /pgolddata is a volume that gets mapped into this container
23+
# /pgnewdata is a volume that gets mapped into this container
24+
# $OLD_VERSION (e.g. 9.5)
25+
# $NEW_VERSION (e.g. 9.6)
26+
#
27+
28+
CRUNCHY_DIR=${CRUNCHY_DIR:-'/opt/crunchy'}
29+
source "${CRUNCHY_DIR}/bin/common_lib.sh"
30+
enable_debugging
31+
32+
function trap_sigterm() {
33+
echo_warn "Signal trap triggered, beginning shutdown.." >> $PGDATA/trap.output
34+
echo_warn "Signal trap triggered, beginning shutdown.."
35+
kill -SIGINT `head -1 $PGDATA/postmaster.pid` >> $PGDATA/trap.output
36+
}
37+
38+
trap 'trap_sigterm' SIGINT SIGTERM
39+
40+
env_check_err "OLD_VERSION"
41+
env_check_err "NEW_VERSION"
42+
env_check_err "OLD_DATABASE_NAME"
43+
env_check_err "NEW_DATABASE_NAME"
44+
45+
export CHECKSUMS=${CHECKSUMS:-true}
46+
47+
export PGDATAOLD=/pgolddata/${OLD_DATABASE_NAME?}
48+
dir_check_err "${PGDATAOLD?}"
49+
50+
export PGDATANEW=/pgnewdata/${NEW_DATABASE_NAME?}
51+
mkdir -p ${PGDATANEW?}
52+
dir_check_err "${PGDATANEW?}"
53+
54+
# Set the postgres binary to match the NEW_VERSION
55+
56+
case $NEW_VERSION in
57+
"16")
58+
echo_info "Setting PGBINNEW to ${NEW_VERSION}."
59+
export PGBINNEW=/usr/pgsql-16/bin
60+
export LD_LIBRARY_PATH=/usr/pgsql-16/lib
61+
;;
62+
"15")
63+
echo_info "Setting PGBINNEW to ${NEW_VERSION}."
64+
export PGBINNEW=/usr/pgsql-15/bin
65+
export LD_LIBRARY_PATH=/usr/pgsql-15/lib
66+
;;
67+
"14")
68+
echo_info "Setting PGBINNEW to ${NEW_VERSION}."
69+
export PGBINNEW=/usr/pgsql-14/bin
70+
export LD_LIBRARY_PATH=/usr/pgsql-14/lib
71+
;;
72+
"13")
73+
echo_info "Setting PGBINNEW to ${NEW_VERSION}."
74+
export PGBINNEW=/usr/pgsql-13/bin
75+
export LD_LIBRARY_PATH=/usr/pgsql-13/lib
76+
;;
77+
"12")
78+
echo_info "Setting PGBINNEW to ${NEW_VERSION}."
79+
export PGBINNEW=/usr/pgsql-12/bin
80+
export LD_LIBRARY_PATH=/usr/pgsql-12/lib
81+
;;
82+
"11")
83+
echo_info "Setting PGBINNEW to ${NEW_VERSION}."
84+
export PGBINNEW=/usr/pgsql-11/bin
85+
export LD_LIBRARY_PATH=/usr/pgsql-11/lib
86+
;;
87+
*)
88+
echo_info "Unsupported NEW_VERSION of ${NEW_VERSION}."
89+
exit 2
90+
;;
91+
esac
92+
case $OLD_VERSION in
93+
"14")
94+
echo_info "Setting PGBINOLD to ${OLD_VERSION}."
95+
export PGBINOLD=/usr/pgsql-14/bin
96+
;;
97+
"13")
98+
echo_info "Setting PGBINOLD to ${OLD_VERSION}."
99+
export PGBINOLD=/usr/pgsql-13/bin
100+
;;
101+
"12")
102+
echo_info "Setting PGBINOLD to ${OLD_VERSION}."
103+
export PGBINOLD=/usr/pgsql-12/bin
104+
;;
105+
"11")
106+
echo_info "Setting PGBINOLD to ${OLD_VERSION}."
107+
export PGBINOLD=/usr/pgsql-11/bin
108+
;;
109+
*)
110+
echo_info "Unsupported OLD_VERSION of ${OLD_VERSION}."
111+
exit 2
112+
;;
113+
esac
114+
115+
export PATH="${CRUNCHY_DIR}/bin:${PGBINNEW?}:$PATH"
116+
117+
# Create a clean new data directory
118+
options=" "
119+
if [[ -v PG_LOCALE ]]; then
120+
options+=" --locale="$PG_LOCALE
121+
fi
122+
123+
if [[ -v XLOGDIR ]]; then
124+
if [ -d "$XLOGDIR" ]; then
125+
options+=" --X "$XLOGDIR
126+
else
127+
echo_info "XLOGDIR not found. Using default pg_wal directory.."
128+
fi
129+
fi
130+
131+
if [[ ${CHECKSUMS?} == 'true' ]]
132+
then
133+
options+=" --data-checksums"
134+
fi
135+
136+
echo_info "Using the ${options} flags for initdb.."
137+
${PGBINNEW?}/initdb -D ${PGDATANEW?} $options
138+
139+
# Get the old config files and use those in the new database
140+
cp ${PGDATAOLD?}/postgresql.conf ${PGDATANEW?}
141+
cp ${PGDATAOLD?}/pg_hba.conf ${PGDATANEW?}
142+
143+
# Remove the old postmaster.pid
144+
echo_info "Cleaning up the old postmaster.pid file.."
145+
rm ${PGDATAOLD?}/postmaster.pid
146+
147+
# changing to /tmp is necessary since pg_upgrade has to have write access
148+
cd /tmp
149+
150+
# pg_upgrade expects the old pgdata directory to have u=rwx (0700) permissions
151+
chmod 0700 ${PGDATAOLD?}
152+
153+
${PGBINNEW?}/pg_upgrade
154+
rc=$?
155+
if (( $rc == 0 )); then
156+
echo_info "Upgrade has completed."
157+
else
158+
echo_err "Problem with upgrade. rc=${rc}"
159+
fi
160+
161+
exit $rc
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
FROM redhat/ubi8-minimal
2+
3+
LABEL name="Percona PostgreSQL Distribution upgrade" \
4+
vendor="Percona" \
5+
summary="Percona Distribution for PostgreSQL" \
6+
description="Percona Distribution for PostgreSQL is a collection of tools to assist you in managing your PostgreSQL database system" \
7+
maintainer="Percona Development <info@percona.com>"
8+
9+
RUN set -ex; \
10+
microdnf -y update; \
11+
microdnf -y install glibc-langpack-en platform-python; \
12+
/usr/libexec/platform-python -m pip install pip --upgrade; \
13+
microdnf -y remove platform-python-pip; \
14+
microdnf clean all; \
15+
rm -rf /var/cache/dnf /var/cache/yum
16+
17+
ENV LC_ALL en_US.utf-8
18+
ENV LANG en_US.utf-8
19+
ARG PG_MAJOR=16
20+
21+
RUN set -ex; \
22+
export GNUPGHOME="$(mktemp -d)"; \
23+
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys \
24+
430BDF5C56E7C94E848EE60C1C4CBDCDCD2EFD2A \
25+
99DB70FAE1D7CE227FB6488205B555B38483C65D \
26+
94E279EB8D8F25B21810ADF121EA45AB2F86D6A1 \
27+
736AF5116D9C40E2AF6B074BF9B9FEE7764429E6; \
28+
gpg --batch --export --armor 430BDF5C56E7C94E848EE60C1C4CBDCDCD2EFD2A > ${GNUPGHOME}/RPM-GPG-KEY-Percona; \
29+
gpg --batch --export --armor 99DB70FAE1D7CE227FB6488205B555B38483C65D > ${GNUPGHOME}/RPM-GPG-KEY-centosofficial; \
30+
gpg --batch --export --armor 94E279EB8D8F25B21810ADF121EA45AB2F86D6A1 > ${GNUPGHOME}/RPM-GPG-KEY-EPEL-8; \
31+
gpg --batch --export --armor 736AF5116D9C40E2AF6B074BF9B9FEE7764429E6 > ${GNUPGHOME}/RPM-GPG-KEY-CentOS-SIG-Cloud; \
32+
rpmkeys --import \
33+
${GNUPGHOME}/RPM-GPG-KEY-Percona \
34+
${GNUPGHOME}/RPM-GPG-KEY-centosofficial \
35+
${GNUPGHOME}/RPM-GPG-KEY-EPEL-8 \
36+
${GNUPGHOME}/RPM-GPG-KEY-CentOS-SIG-Cloud; \
37+
microdnf install -y findutils; \
38+
curl -Lf -o /tmp/epel-release.rpm https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm; \
39+
curl -Lf -o /tmp/percona-release.rpm https://repo.percona.com/yum/percona-release-latest.noarch.rpm; \
40+
rpmkeys --checksig /tmp/percona-release.rpm; \
41+
rpmkeys --checksig /tmp/epel-release.rpm; \
42+
rpm -i /tmp/percona-release.rpm /tmp/epel-release.rpm; \
43+
rm -rf "$GNUPGHOME" /tmp/percona-release.rpm /tmp/epel-release.rpm; \
44+
curl -Lf -o /tmp/python3-pyparsing.rpm https://vault.centos.org/8.5.2111/cloud/x86_64/openstack-train/Packages/p/python3-pyparsing-2.4.6-1.el8.noarch.rpm; \
45+
rpmkeys --checksig /tmp/python3-pyparsing.rpm; \
46+
rpm -i /tmp/python3-pyparsing.rpm; \
47+
rm -rf /tmp/python3-pyparsing.rpm; \
48+
rpm --import /etc/pki/rpm-gpg/PERCONA-PACKAGING-KEY; \
49+
percona-release enable ppg-${PG_MAJOR} release
50+
51+
52+
RUN set -ex; \
53+
microdnf -y install \
54+
bind-utils \
55+
gettext \
56+
hostname \
57+
perl \
58+
libedit \
59+
procps-ng; \
60+
sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/epel*.repo; \
61+
microdnf -y module disable llvm-toolset; \
62+
microdnf -y install \
63+
libpq \
64+
llvm \
65+
percona-postgresql${PG_MAJOR//.}; \
66+
microdnf -y clean all; \
67+
rm -rf /var/cache/dnf /var/cache/yum
68+
69+
RUN set -ex; \
70+
microdnf -y install \
71+
--enablerepo="epel" \
72+
percona-pgaudit${PG_MAJOR//.} \
73+
percona-pgaudit${PG_MAJOR//.}_set_user \
74+
percona-postgresql${PG_MAJOR//.}-contrib \
75+
percona-postgresql${PG_MAJOR//.}-server \
76+
percona-postgresql${PG_MAJOR//.}-libs \
77+
percona-postgresql${PG_MAJOR//.}-plpython* \
78+
percona-postgresql${PG_MAJOR//.}-llvmjit \
79+
percona-wal2json${PG_MAJOR//.} \
80+
percona-pg_stat_monitor${PG_MAJOR//.} \
81+
nss_wrapper \
82+
lz4 \
83+
unzip; \
84+
microdnf -y reinstall tzdata; \
85+
microdnf clean all; \
86+
rm -rf /var/cache/dnf /var/cache/yum
87+
88+
RUN for pg_version in 15 14 13 12; do \
89+
percona-release enable ppg-${pg_version} release; \
90+
microdnf -y install --nodocs \
91+
percona-pgaudit${pg_version} \
92+
percona-pgaudit${pg_version}_set_user \
93+
percona-postgresql${pg_version}-contrib \
94+
percona-postgresql${pg_version}-server \
95+
percona-postgresql${pg_version}-libs \
96+
percona-postgresql${pg_version}-plpython* \
97+
percona-postgresql${pg_version}-llvmjit \
98+
percona-wal2json${pg_version} \
99+
percona-pg_stat_monitor${pg_version}; \
100+
done
101+
102+
# && microdnf -y clean all; \
103+
# microdnf clean all; \
104+
# rm -rf /var/cache/dnf /var/cache/yum
105+
106+
RUN mkdir -p /opt/crunchy/bin /pgolddata /pgnewdata /opt/crunchy/conf
107+
COPY bin/upgrade/ /opt/crunchy/bin
108+
COPY bin/common /opt/crunchy/bin
109+
COPY conf/upgrade/ /opt/crunchy/conf
110+
111+
RUN chown -R postgres:postgres /opt/crunchy /pgolddata /pgnewdata && \
112+
chmod -R g=u /opt/crunchy /pgolddata /pgnewdata
113+
114+
VOLUME /pgolddata /pgnewdata
115+
116+
ENV NSS_WRAPPER_SUBDIR="upgrade"
117+
118+
ENTRYPOINT ["opt/crunchy/bin/uid_postgres.sh"]
119+
120+
USER 26
121+
122+
CMD ["/opt/crunchy/bin/start.sh"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
root:x:0:
2+
bin:x:1:
3+
daemon:x:2:
4+
sys:x:3:
5+
adm:x:4:
6+
tty:x:5:
7+
disk:x:6:
8+
lp:x:7:
9+
mem:x:8:
10+
kmem:x:9:
11+
wheel:x:10:
12+
cdrom:x:11:
13+
mail:x:12:
14+
man:x:15:
15+
dialout:x:18:
16+
floppy:x:19:
17+
games:x:20:
18+
tape:x:30:
19+
video:x:39:
20+
ftp:x:50:
21+
lock:x:54:
22+
audio:x:63:
23+
nobody:x:99:
24+
users:x:100:
25+
utmp:x:22:
26+
utempter:x:35:
27+
input:x:999:
28+
systemd-journal:x:190:
29+
systemd-network:x:192:
30+
dbus:x:81:
31+
ssh_keys:x:998:
32+
nfsnobody:x:65534:
33+
postgres:x:${USER_ID}:postgres
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root:x:0:0:root:/root:/bin/bash
2+
bin:x:1:1:bin:/bin:/sbin/nologin
3+
daemon:x:2:2:daemon:/sbin:/sbin/nologin
4+
adm:x:3:4:adm:/var/adm:/sbin/nologin
5+
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6+
sync:x:5:0:sync:/sbin:/bin/sync
7+
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8+
halt:x:7:0:halt:/sbin:/sbin/halt
9+
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10+
operator:x:11:0:operator:/root:/sbin/nologin
11+
games:x:12:100:games:/usr/games:/sbin/nologin
12+
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13+
nobody:x:99:99:Nobody:/:/sbin/nologin
14+
postgres:x:${USER_ID}:${GROUP_ID}:PostgreSQL Server:${HOME}:/bin/bash

0 commit comments

Comments
 (0)