|
1 | 1 | ARG IMAGE_PATH |
2 | 2 | ARG BUILD |
3 | 3 | ARG BASEOS |
4 | | -ARG CONTAINERIMAGE |
| 4 | +ARG PGVERSION |
5 | 5 |
|
6 | | -FROM ${IMAGE_PATH}/base:${BASEOS}-${BUILD} AS builder |
| 6 | +FROM ${IMAGE_PATH}/base:${BASEOS}-${BUILD} as builder |
7 | 7 |
|
8 | 8 | # Dockerfile specific informations |
9 | 9 | ARG PACKAGER |
10 | 10 | ARG PGBACKREST_VERSION |
| 11 | +ARG PATRONI_VERSION |
11 | 12 | ARG PGVERSION |
12 | 13 | ARG OLD_PG_VERSIONS |
| 14 | +ARG PG_SUPPORTED_VERSIONS="$PGVERSION" |
13 | 15 | ARG PG_SUPPORTED_VERSIONS="$OLD_PG_VERSIONS $PGVERSION" |
| 16 | +ARG ETCD_VERSION |
| 17 | +ARG ARCH |
14 | 18 |
|
15 | 19 | # Enable Beta-Repo |
16 | 20 | RUN ${PACKAGER} config-manager --set-enabled pgdg${PGVERSION}-updates-testing \ |
17 | | - && ${PACKAGER} config-manager --set-enabled pgdg${PGVERSION}-source-updates-testing \ |
18 | | - && ${PACKAGER} -y update; |
| 21 | + && ${PACKAGER} config-manager --set-enabled pgdg${PGVERSION}-source-updates-testing; |
| 22 | + |
| 23 | +# Spilo-specific |
| 24 | +ENV PAM_OAUTH2=v1.0.1 \ |
| 25 | + PG_PERMISSIONS=REL_1_3 |
19 | 26 |
|
20 | | -RUN ${PACKAGER} -y install --nodocs \ |
| 27 | +# Get some Standard-Stuff |
| 28 | +RUN ${PACKAGER} -y update && ${PACKAGER} -y install --nodocs --noplugins --setopt=install_weak_deps=0 \ |
21 | 29 | --setopt=skip_missing_names_on_install=False \ |
22 | | - openssh-clients \ |
23 | | - openssh-server \ |
24 | | - bzip2 \ |
25 | | - lz4 \ |
26 | | - zstd \ |
27 | | - libicu \ |
28 | | - dumb-init \ |
29 | | - jq \ |
30 | | - pgbackrest-${PGBACKREST_VERSION} \ |
31 | | - && ${PACKAGER} -y clean all ; |
32 | | - |
33 | | -# Install postgres-server |
34 | | -RUN ${PACKAGER} -y update \ |
35 | | - && for version in $PG_SUPPORTED_VERSIONS; do \ |
36 | | - ${PACKAGER} -y install --nodocs postgresql${version}-server; \ |
| 30 | + openssh-clients \ |
| 31 | + openssh-server \ |
| 32 | + shadow-utils \ |
| 33 | + tar \ |
| 34 | + bzip2 \ |
| 35 | + lz4 \ |
| 36 | + python3 \ |
| 37 | + python3-pip \ |
| 38 | + python3-psycopg2 \ |
| 39 | + git \ |
| 40 | + patchutils \ |
| 41 | + binutils \ |
| 42 | + make \ |
| 43 | + cmake \ |
| 44 | + gcc \ |
| 45 | + clang \ |
| 46 | + pam-devel \ |
| 47 | + wget \ |
| 48 | + mlocate \ |
| 49 | + git-clang-format \ |
| 50 | + openssl-devel \ |
| 51 | + ccache \ |
| 52 | + redhat-rpm-config \ |
| 53 | + krb5-devel \ |
| 54 | + busybox \ |
| 55 | + jq \ |
| 56 | + rsync \ |
| 57 | + dumb-init \ |
| 58 | + libicu \ |
| 59 | + pgbackrest-${PGBACKREST_VERSION} \ |
| 60 | + cronie \ |
| 61 | + libcurl-devel \ |
| 62 | + && ${PACKAGER} -y clean all; |
| 63 | + |
| 64 | +# install etcdctl |
| 65 | +RUN curl -L https://github.com/coreos/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-linux-${ARCH}.tar.gz | tar xz -C /bin --strip=1 --wildcards --no-anchored --no-same-owner etcdctl etcd; |
| 66 | + |
| 67 | +ENV PATHBACKUP = $PATH |
| 68 | + |
| 69 | +RUN wget https://smarden.org/runit/runit-2.1.2.tar.gz -P /package/ |
| 70 | +COPY cron_unprivileged.c /package/ |
| 71 | + |
| 72 | +RUN pip3 install 'PyYAML<6.0' setuptools pystache loader kazoo meld3 boto python-etcd psutil requests cdiff ydiff==1.4.2 --upgrade \ |
| 73 | + && if [[ $PATRONI_VERSION == "multisite-"* ]]; then \ |
| 74 | + git clone -b $PATRONI_VERSION https://github.com/cybertec-postgresql/patroni; \ |
| 75 | + pip3 install ./patroni[kubernetes,etcd,etcd3]; \ |
| 76 | + else \ |
| 77 | + pip3 install patroni[kubernetes$EXTRAS]==$PATRONI_VERSION --upgrade; \ |
| 78 | + fi \ |
| 79 | + && mkdir /usr/lib/postgresql \ |
| 80 | + # Install pam_oauth2.so |
| 81 | + && git clone -b $PAM_OAUTH2 --recurse-submodules https://github.com/zalando-pg/pam-oauth2.git && make -C pam-oauth2 install \ |
| 82 | + && git clone -b $PG_PERMISSIONS https://github.com/cybertec-postgresql/pg_permissions.git \ |
| 83 | + && git clone https://github.com/dimitri/pgextwlist.git \ |
| 84 | + && git clone https://github.com/crunchydata/pgnodemx \ |
| 85 | +\ |
| 86 | + && ${PACKAGER} -y install --nodocs --noplugins --setopt=install_weak_deps=0 postgresql${PGVERSION} libevent-devel brotli-devel libbrotli \ |
| 87 | + && ${PACKAGER} -y clean all \ |
| 88 | +\ |
| 89 | + # forbid creation of a main cluster when package is installed |
| 90 | + #&& sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \ |
| 91 | +\ |
| 92 | +# Install PostgreSQL |
| 93 | + && for version in $PG_SUPPORTED_VERSIONS; do \ |
| 94 | + ${PACKAGER} -y update && \ |
| 95 | + ${PACKAGER} -y install postgresql${version}-pltcl \ |
| 96 | + pgaudit*${version} \ |
| 97 | + credcheck_*${version} \ |
| 98 | + # Install PostgreSQL binaries, contrib, plproxy and multiple pl's |
| 99 | + && ${PACKAGER} -y install -y postgresql${version}-contrib \ |
| 100 | + postgresql${version}-plpython3 postgresql${version}-devel \ |
| 101 | + pg_cron_${version} pgvector_${version} set_user_${version} \ |
| 102 | + # Modify for using origial-spilo scripts |
| 103 | + && ln -s /usr/pgsql-${version} /usr/lib/postgresql/${version} \ |
| 104 | + && export PATH=$PATHBACKUP:/usr/pgsql-${version}/bin \ |
| 105 | + # Install TimescaleDB |
| 106 | + && ${PACKAGER} -y install timescaledb_${version} \ |
| 107 | + && cd / \ |
| 108 | + && for n in pg_permissions $EXTRA_EXTENSIONS; do \ |
| 109 | + make -C $n USE_PGXS=1 clean install-strip; \ |
| 110 | + done \ |
| 111 | + && cd /pgextwlist && make clean && make && make install \ |
| 112 | + && cd /pgnodemx && make USE_PGXS=1 clean && make USE_PGXS=1 && make USE_PGXS=1 install; \ |
37 | 113 | done \ |
38 | | - && ${PACKAGER} -y clean all; |
39 | | - |
40 | | -# Remove default pgbackrest-config |
41 | | -RUN rm /etc/pgbackrest.conf |
42 | | -RUN rm -rf /var/spool/pgbackrest |
43 | | - |
44 | | -# Add kubectl |
45 | | -RUN curl -LO https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl && chmod +x kubectl |
46 | | - |
47 | | -RUN mkdir -p /tmp/pgsql && cp -r /usr/pgsql* /tmp/pgsql |
48 | | -RUN mkdir -p /tmp/pg && cp -r /usr/bin/pg* /tmp/pg |
49 | | -RUN mkdir -p /tmp/lz4 && cp -r /usr/bin/lz4* /tmp/lz4 |
50 | | -RUN mkdir -p /tmp/zstd && cp -r /usr/bin/zstd* /tmp/zstd |
51 | | - |
52 | | - |
53 | | -FROM ${CONTAINERIMAGE} as micro |
54 | | - |
55 | | -ARG PGVERSION |
56 | | - |
57 | | -COPY --from=builder /usr/bin/dumb-init /usr/bin/dumb-init |
58 | | -COPY --from=builder /etc/passwd /etc/passwd |
59 | | -COPY --from=builder /etc/group /etc/group |
60 | | -COPY --from=builder /usr/lib64 /usr/lib64 |
61 | | -# SSH-client |
62 | | -COPY --from=builder /etc/ssh /etc/ssh |
63 | | -COPY --from=builder /usr/bin/ssh /usr/bin/ssh |
64 | | -COPY --from=builder /usr/libexec/openssh /usr/libexec/openssh |
65 | | -# pgBackRest |
66 | | -COPY --from=builder /usr/bin/pgbackrest /usr/bin/pgbackrest |
67 | | -COPY --from=builder /usr/share/licenses/pgbackrest/LICENSE /usr/share/licenses/pgbackrest/LICENSE |
68 | | -COPY --from=builder /var/lib/pgbackrest /var/lib/pgbackrest |
69 | | -COPY --from=builder /var/log/pgbackrest /var/log/pgbackrest |
70 | | -# Postgres |
71 | | -COPY --from=builder /tmp/pgsql/ /usr/ |
72 | | -COPY --from=builder /var/lib/pgsql /var/lib/pgsql |
73 | | -COPY --from=builder /tmp/pg /usr/bin/ |
74 | | - |
75 | | -COPY --from=builder ./kubectl /usr/local/bin/ |
76 | | -# lz4 |
77 | | -COPY --from=builder /tmp/lz4 /usr/bin/ |
78 | | -# zstd |
79 | | -COPY --from=builder /tmp/zstd /usr/bin/ |
80 | | -# Others |
81 | | -COPY --from=builder /usr/bin/sed /usr/bin/sed |
82 | | -COPY --from=builder /usr/bin/jq /usr/bin/jq |
83 | | -COPY --from=builder /usr/bin/watch /usr/bin/watch |
84 | | -COPY --from=builder /usr/share/locale /usr/share/locale |
85 | | -COPY --from=builder /usr/lib /usr/lib |
86 | | -COPY --from=builder /usr/lib64 /usr/lib64 |
87 | | -# CA |
88 | | -COPY --from=builder /usr/bin/ca-legacy /usr/bin/ca-legacy |
89 | | -COPY --from=builder /usr/bin/update-ca-trust /usr/bin/update-ca-trust |
90 | | -# grep |
91 | | -COPY --from=builder /etc/profile.d /etc/profile.d |
92 | | -COPY --from=builder /usr/bin/grep /usr/bin/grep |
93 | | -COPY --from=builder /usr/libexec /usr/libexec |
94 | | -# COPY --from=builder /usr/bin/update-ca-trust /usr/bin/update-ca-trust |
95 | | -# COPY --from=builder /usr/bin/update-ca-trust /usr/bin/update-ca-trust |
96 | | - |
97 | | -# p11-kit |
98 | | -COPY --from=builder /etc/pkcs11 /etc/pkcs11 |
99 | | -COPY --from=builder /usr/libexec/p11-kit /usr/libexec/p11-kit |
100 | | -COPY --from=builder /usr/share/bash-completion/completions /usr/share/bash-completion/completions |
101 | | -COPY --from=builder /usr/share/p11-kit /usr/share/p11-kit |
102 | | -COPY --from=builder /usr/share/polkit-1 /usr/share/polkit-1 |
103 | | - |
104 | | -COPY --from=builder /usr/bin/p11-kit /usr/bin/p11-kit |
105 | | -COPY --from=builder /etc/pki /etc/pki |
106 | | -COPY --from=builder /usr/share/pki /usr/share/pki |
107 | | -COPY --from=builder /etc/ssl /etc/ssl |
108 | | -COPY --from=builder /etc/pkcs11 /etc/pkcs11 |
109 | | - |
110 | | -# p11-kit-trust |
111 | | -COPY --from=builder /usr/bin/trust /usr/bin/ |
112 | | - |
113 | | -# libraries |
114 | | -COPY --from=builder /usr/bin/nss_wrapper.pl /usr/bin/nss_wrapper.pl |
115 | | -# COPY --from=builder /usr/lib64/libnss_wrapper.so /usr/lib64/libnss_wrapper.so |
116 | | -COPY --from=builder /usr/share/man/man1 /usr/share/man/man1 |
117 | | -COPY --from=builder /usr/bin/envsubst /usr/bin/envsubst |
118 | | - |
119 | | -RUN /usr/bin/update-ca-trust extract |
120 | | - |
121 | | -# add postgres user and group |
122 | | -#RUN groupadd postgres -g 26 && useradd postgres -u 26 -g 26 |
123 | | - |
124 | | -# Prepare all needed stuff |
125 | | -Run mkdir -p /opt/pgbackrest /backrestrepo /home/postgres /home/postgres/pgdata/pgbackrest/log |
126 | | - |
127 | | -# add pgbackrest-restore files |
128 | | -ADD scripts/pgbackrest/ /opt/pgbackrest/bin/ |
129 | | - |
130 | | -# add pgbackrest-common files |
131 | | -ADD /scripts/nss_wrapper /scripts/nss_wrapper |
| 114 | + && ${PACKAGER} -y install --nodocs --noplugins --setopt=install_weak_deps=0 glibc-static \ |
| 115 | + && ${PACKAGER} -y clean all; |
| 116 | + RUN gcc -s -shared -fPIC -o /usr/local/lib/cron_unprivileged.so /package/cron_unprivileged.c |
| 117 | + |
| 118 | + RUN cd /package && tar -xvzf runit-2.1.2.tar.gz && rm runit-2.1.2.tar.gz \ |
| 119 | + && cd admin/runit-2.1.2 && package/install \ |
| 120 | + && ln -s /usr/local/bin/runsvdir /usr/bin/runsvdir \ |
| 121 | + && rm -rf /pg_permissions /pgextwlist /pg_stat_kcache /pgnodemx /timescaledb /pam-oauth2 \ |
| 122 | + && rm /etc/pgbackrest.conf && rm -rf /var/spool/pgbackrest \ |
| 123 | + && ${PACKAGER} -y remove $(rpm -qa "*devel*") python3-pip python3-wheel python3-dev python3-setuptools git patchutils flatpak glibc-static gcc glibc-devel \ |
| 124 | + && ${PACKAGER} -y autoremove \ |
| 125 | + && ${PACKAGER} -y clean dbcache \ |
| 126 | + && ${PACKAGER} -y clean all; |
132 | 127 |
|
133 | 128 | FROM scratch |
134 | | -COPY --from=micro / / |
135 | 129 |
|
136 | 130 | ARG PGVERSION |
137 | 131 |
|
138 | | -# set user and group ownership |
139 | | -RUN chown -R postgres:postgres /opt/pgbackrest \ |
140 | | - /backrestrepo /home/postgres/pgdata/pgbackrest /home/postgres/pgdata |
141 | | - |
142 | | -RUN mkdir -p /etc/pgbackrest \ |
143 | | - && chown -R postgres:postgres /etc/pgbackrest |
144 | | - |
145 | | -RUN chmod -R g=u /etc/pgbackrest \ |
146 | | - && rm -f /run/nologin |
147 | | - |
148 | | -RUN mkdir /.ssh && chown postgres:postgres /.ssh && chmod o+rwx /.ssh |
149 | | - |
150 | | -# set user and group ownership |
151 | | -RUN chown -R postgres:postgres /opt/pgbackrest \ |
152 | | - /backrestrepo /home/postgres/pgdata |
153 | | - |
154 | | -#ENV PATH=$PATH:/usr/pgsql-$PGVERSION/bin |
155 | | -COPY launcher/pgbackrest/launch.sh / |
156 | | - |
157 | | -VOLUME ["sshd", "/home/postgres/pgdata", "/backrestrepo"] |
| 132 | +COPY --from=builder / / |
| 133 | + |
| 134 | +EXPOSE 5432 8008 8080 |
| 135 | +ENV LC_ALL=en_US.utf-8 \ |
| 136 | + PATH=$PATH:/usr/pgsql-$PGVERSION/bin \ |
| 137 | + PGHOME=/home/postgres \ |
| 138 | + RW_DIR=/run \ |
| 139 | + TIMESCALEDB=$TIMESCALEDB \ |
| 140 | + DEMO=$DEMO |
| 141 | + |
| 142 | +ENV LOG_ENV_DIR=$RW_DIR/etc/log.d/env \ |
| 143 | + PGROOT=$PGHOME/pgdata/pgroot |
| 144 | + |
| 145 | +ENV PGDATA=$PGROOT/data \ |
| 146 | + PGLOG=$PGROOT/pg_log |
| 147 | + |
| 148 | +WORKDIR $PGHOME |
| 149 | + |
| 150 | +COPY motd /etc/ |
| 151 | +#COPY runit /etc/service/ |
| 152 | + |
| 153 | +COPY runit /etc/runit/runsvdir/default/ |
| 154 | +COPY pgq_ticker.ini $PGHOME/ |
| 155 | +RUN rm -rf /etc/service && mkdir /home/postgres/pgdata && chown -R postgres:postgres /home/postgres/pgdata && chmod -R g=u /home/postgres/pgdata \ |
| 156 | + && sed -i "s|/var/lib/pgsql.*|$PGHOME:/bin/bash|" /etc/passwd \ |
| 157 | + && chown -R postgres:postgres $PGHOME $PGHOME/pgdata $RW_DIR \ |
| 158 | + && rm -fr /var/spool/cron /var/tmp \ |
| 159 | + && mkdir -p /var/spool \ |
| 160 | + && ln -s $RW_DIR/cron /var/spool/cron \ |
| 161 | + && ln -s $RW_DIR/tmp /var/tmp \ |
| 162 | + && for d in /etc/runit/runsvdir/default/*; do \ |
| 163 | + chmod 755 $d/* \ |
| 164 | + && ln -s /run/supervise/$(basename $d) $d/supervise; \ |
| 165 | + done \ |
| 166 | + && chmod +r /etc/motd \ |
| 167 | + && ln -snf $RW_DIR/service /etc/service \ |
| 168 | + #&& ln -s $RW_DIR/pam.d-postgresql /etc/pam.d/postgresql \ |
| 169 | + && ln -s $RW_DIR/postgres.yml $PGHOME/postgres.yml \ |
| 170 | + && ln -s $RW_DIR/.bash_history /root/.bash_history \ |
| 171 | + && ln -s $RW_DIR/postgresql/.bash_history $PGHOME/.bash_history \ |
| 172 | + && ln -s $RW_DIR/postgresql/.psql_history $PGHOME/.psql_history \ |
| 173 | + && ln -s $RW_DIR/etc $PGHOME/etc \ |
| 174 | + && for d in $PGHOME /root; do \ |
| 175 | + d=$d/.config/patroni \ |
| 176 | + && mkdir -p $d \ |
| 177 | + && ln -s $PGHOME/postgres.yml $d/patronictl.yaml; \ |
| 178 | + done \ |
| 179 | + && sed -i 's/set compatible/set nocompatible/' /etc/vimrc \ |
| 180 | + && echo "PATH=\"$PATH\"" > /etc/environment \ |
| 181 | + && for e in TERM=linux LC_ALL=C.UTF-8 LANG=C.UTF-8 EDITOR=editor; \ |
| 182 | + do echo "export $e" >> /etc/bash.bashrc; \ |
| 183 | + done \ |
| 184 | + && ln -s /etc/skel/.bashrc $PGHOME/.bashrc \ |
| 185 | + && echo "source /etc/motd" >> /home/postgres/.bashrc \ |
| 186 | + # Allow users in the root group to access the following files and dirs |
| 187 | + && if [ "$COMPRESS" != "true" ]; then \ |
| 188 | + chmod 664 /etc/passwd \ |
| 189 | + && chmod o+r /etc/shadow \ |
| 190 | + && chgrp -R 0 $PGHOME $RW_DIR \ |
| 191 | + && chmod -R g=u $PGHOME $RW_DIR \ |
| 192 | + && usermod -a -G root postgres; \ |
| 193 | + fi |
| 194 | + |
| 195 | + |
| 196 | +COPY scripts bootstrap major_upgrade /scripts/ |
| 197 | +COPY launcher/postgres/launch.sh / |
158 | 198 |
|
159 | 199 | ENTRYPOINT ["/scripts/nss_wrapper/nss_wrapper.sh"] |
160 | 200 |
|
161 | | -USER 26 |
| 201 | +USER postgres |
162 | 202 |
|
163 | | -CMD ["dumb-init", "/launch.sh", "init"] |
| 203 | +CMD ["/bin/sh", "/launch.sh", "init"] |
0 commit comments