1+ ARG CONTAINERSUITE
2+ ARG BUILD
3+ ARG BASEOS
4+ ARG PGVERSION
5+
6+ FROM ${CONTAINERSUITE}/base:${BASEOS}-${BUILD} as builder
7+
8+ # Dockerfile specific informations
9+ ARG PACKAGER
10+ ARG PGBACKREST_VERSION
11+ ARG PATRONI_VERSION
12+ ARG PGVERSION
13+ ARG OLD_PG_VERSIONS
14+ ARG PG_SUPPORTED_VERSIONS="$PGVERSION"
15+ ARG PG_SUPPORTED_VERSIONS="$OLD_PG_VERSIONS $PGVERSION"
16+ ARG ARCH
17+
18+ # Enable Beta-Repo
19+ RUN ${PACKAGER} config-manager --set-enabled pgdg${PGVERSION}-updates-testing \
20+ && ${PACKAGER} config-manager --set-enabled pgdg${PGVERSION}-source-updates-testing;
21+
22+ # Get some Standard-Stuff
23+ RUN ${PACKAGER} -y update && ${PACKAGER} -y install --nodocs --noplugins --setopt=install_weak_deps=0 \
24+ --setopt=skip_missing_names_on_install=False \
25+ openssh-clients \
26+ openssh-server \
27+ shadow-utils \
28+ tar \
29+ bzip2 \
30+ lz4 \
31+ python3 \
32+ python3-pip \
33+ python3-psycopg2 \
34+ git \
35+ patchutils \
36+ binutils \
37+ make \
38+ cmake \
39+ gcc \
40+ pam-devel \
41+ wget \
42+ mlocate \
43+ git-clang-format \
44+ openssl-devel \
45+ ccache \
46+ redhat-rpm-config \
47+ krb5-devel \
48+ busybox \
49+ jq \
50+ rsync \
51+ dumb-init \
52+ libicu \
53+ pgbackrest-${PGBACKREST_VERSION} \
54+ && ${PACKAGER} -y clean all;
55+
56+ # install etcdctl
57+ RUN ETCDVERSION=3.5.1 \
58+ && curl -L https://github.com/coreos/etcd/releases/download/v${ETCDVERSION}/etcd-v${ETCDVERSION}-linux-${ARCH}.tar.gz | tar xz -C /bin --strip=1 --wildcards --no-anchored --no-same-owner etcdctl etcd;
59+
60+ ENV PATHBACKUP = $PATH
61+
62+ RUN wget https://smarden.org/runit/runit-2.1.2.tar.gz -P /package/
63+
64+ RUN pip3 install 'PyYAML<6.0' setuptools pystache loader kazoo meld3 boto python-etcd psutil requests cdiff ydiff --upgrade \
65+ && pip3 install patroni[kubernetes$EXTRAS]==$PATRONI_VERSION --upgrade \
66+ && mkdir /usr/lib/postgresql \
67+ && ${PACKAGER} -y install --nodocs --noplugins --setopt=install_weak_deps=0 postgresql${PGVERSION} libevent-devel brotli-devel libbrotli \
68+ && ${PACKAGER} -y clean all \
69+ \
70+ # Install PostgreSQL
71+ && for version in $PG_SUPPORTED_VERSIONS; do \
72+ ${PACKAGER} -y update && \
73+ ${PACKAGER} -y install postgresql${version}-pltcl \
74+ # Install PostgreSQL binaries, contrib, plproxy and multiple pl's
75+ && ${PACKAGER} -y install -y postgresql${version}-contrib \
76+ postgresql${version}-devel \
77+ \
78+ # Modify for using origial-spilo scripts
79+ && ln -s /usr/pgsql-${version} /usr/lib/postgresql/${version} \
80+ && export PATH=$PATHBACKUP:/usr/pgsql-${version}/bin; \
81+ done \
82+ && ${PACKAGER} -y install --nodocs --noplugins --setopt=install_weak_deps=0 glibc-static \
83+ && ${PACKAGER} -y clean all;
84+
85+ RUN cd /package && tar -xvzf runit-2.1.2.tar.gz && rm runit-2.1.2.tar.gz \
86+ && cd admin/runit-2.1.2 && package/install \
87+ && ln -s /usr/local/bin/runsvdir /usr/bin/runsvdir \
88+ && rm -rf /pg_permissions* /pgextwlist /pg_stat_kcache /pgnodemx /timescaledb /set_user /pam-oauth2 \
89+ && rm /etc/pgbackrest.conf && rm -rf /var/spool/pgbackrest \
90+ && ${PACKAGER} -y remove $(rpm -qa "*devel*" ) python3-pip python3-wheel python3-dev python3-setuptools git patchutils flatpak glibc-static gcc glibc-devel \
91+ && ${PACKAGER} -y autoremove \
92+ && ${PACKAGER} -y clean dbcache \
93+ && ${PACKAGER} -y clean all;
94+
95+ FROM scratch
96+
97+ ARG PGVERSION
98+
99+ COPY --from=builder / /
100+
101+ EXPOSE 5432 8008 8080
102+ ENV LC_ALL=en_US.utf-8 \
103+ PATH=$PATH:/usr/pgsql-$PGVERSION/bin \
104+ PGHOME=/home/postgres \
105+ RW_DIR=/run \
106+ TIMESCALEDB=$TIMESCALEDB \
107+ DEMO=$DEMO
108+
109+ ENV LOG_ENV_DIR=$RW_DIR/etc/log.d/env \
110+ PGROOT=$PGHOME/pgdata/pgroot
111+
112+ ENV PGDATA=$PGROOT/data \
113+ PGLOG=$PGROOT/pg_log
114+
115+ WORKDIR $PGHOME
116+
117+ COPY motd /etc/
118+ # COPY runit /etc/service/
119+
120+ COPY runit /etc/runit/runsvdir/default/
121+ COPY pgq_ticker.ini $PGHOME/
122+ RUN rm -rf /etc/service && mkdir /home/postgres/pgdata && chown -R postgres:postgres /home/postgres/pgdata && chmod -R g=u /home/postgres/pgdata \
123+ && sed -i "s|/var/lib/pgsql.*|$PGHOME:/bin/bash|" /etc/passwd \
124+ && chown -R postgres:postgres $PGHOME $PGHOME/pgdata $RW_DIR \
125+ && rm -fr /var/spool/cron /var/tmp \
126+ && mkdir -p /var/spool \
127+ && ln -s $RW_DIR/cron /var/spool/cron \
128+ && ln -s $RW_DIR/tmp /var/tmp \
129+ && for d in /etc/runit/runsvdir/default/*; do \
130+ chmod 755 $d/* \
131+ && ln -s /run/supervise/$(basename $d) $d/supervise; \
132+ done \
133+ && ln -snf $RW_DIR/service /etc/service \
134+ # && ln -s $RW_DIR/pam.d-postgresql /etc/pam.d/postgresql \
135+ && ln -s $RW_DIR/postgres.yml $PGHOME/postgres.yml \
136+ && ln -s $RW_DIR/.bash_history /root/.bash_history \
137+ && ln -s $RW_DIR/postgresql/.bash_history $PGHOME/.bash_history \
138+ && ln -s $RW_DIR/postgresql/.psql_history $PGHOME/.psql_history \
139+ && ln -s $RW_DIR/etc $PGHOME/etc \
140+ && for d in $PGHOME /root; do \
141+ d=$d/.config/patroni \
142+ && mkdir -p $d \
143+ && ln -s $PGHOME/postgres.yml $d/patronictl.yaml; \
144+ done \
145+ && sed -i 's/set compatible/set nocompatible/' /etc/vimrc \
146+ && echo "PATH=\" $PATH\" " > /etc/environment \
147+ && for e in TERM=linux LC_ALL=C.UTF-8 LANG=C.UTF-8 EDITOR=editor; \
148+ do echo "export $e" >> /etc/bash.bashrc; \
149+ done \
150+ && ln -s /etc/skel/.bashrc $PGHOME/.bashrc \
151+ && echo "source /etc/motd" >> /root/.bashrc \
152+ # Allow users in the root group to access the following files and dirs
153+ && if [ "$COMPRESS" != "true" ]; then \
154+ chmod 664 /etc/passwd \
155+ && chmod o+r /etc/shadow \
156+ && chgrp -R 0 $PGHOME $RW_DIR \
157+ && chmod -R g=u $PGHOME $RW_DIR \
158+ && usermod -a -G root postgres; \
159+ fi
160+
161+
162+ COPY scripts bootstrap major_upgrade /scripts/
163+ COPY launcher/postgres/launch.sh /
164+
165+ ENTRYPOINT ["/scripts/nss_wrapper/nss_wrapper.sh" ]
166+
167+ USER 26
168+
169+ CMD ["/bin/sh" , "/launch.sh" , "init" ]
0 commit comments