|
| 1 | +FROM ubuntu |
| 2 | +ARG PG_VERSION |
| 3 | +ARG PHASE1_ACTION |
| 4 | +ARG PHASE2_ACTION |
| 5 | +ARG REPOSITORY |
| 6 | +ARG EXTRA_OS_PACKAGES |
| 7 | +ARG EXTRA_PG_MODULES |
| 8 | +ARG PG_PARAMETERS |
| 9 | +ARG CFG_OPTIONS |
| 10 | + |
| 11 | +ARG PGPRO_EDN |
| 12 | + |
| 13 | +ENV DEBIAN_FRONTEND=noninteractive |
| 14 | + |
| 15 | +# Install a common set of packages needed for tests |
| 16 | +# There are some warnings (in red) that show up during the build. You can hide |
| 17 | +# them by prefixing each apt statement with DEBIAN_FRONTEND=noninteractive |
| 18 | +RUN p=$EXTRA_OS_PACKAGES; p="${p%\"}";p="${p#\"}"; \ |
| 19 | + apt update && apt install -y $p python3 python3-dev python3-pip \ |
| 20 | + software-properties-common wget vim time pkg-config locales recode \ |
| 21 | + git gcc make libreadline-dev zlib1g-dev libicu-dev bison flex gettext \ |
| 22 | + openjdk-17-jdk maven |
| 23 | + |
| 24 | +RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8 |
| 25 | +ENV LANG en_US.UTF-8 |
| 26 | +ENV LC_ALL en_US.UTF-8 |
| 27 | + |
| 28 | +COPY ./$PHASE1_ACTION /bin/ |
| 29 | +RUN $PHASE1_ACTION |
| 30 | + |
| 31 | +RUN echo $REPOSITORY |
| 32 | +RUN echo `echo $REPOSITORY | sed 's|^\([^/]*//[^/]*/[^/]*\).*|\1|'` |
| 33 | + |
| 34 | +# Add the Postgres PRO PGP key to verify the Debian packages. |
| 35 | +# http://repo.postgrespro.ru/std-15/ubuntu $OS_CODENAME main -> http://repo.postgrespro.ru/std-$PG_VERSION/keys/GPG-KEY-POSTGRESPRO |
| 36 | +RUN wget --quiet -O - `echo $REPOSITORY | sed 's|^\([^/]*//[^/]*/[^/]*\).*|\1|'`/keys/GPG-KEY-POSTGRESPRO | apt-key add - |
| 37 | + |
| 38 | +# Add Postgres Pro's repository. |
| 39 | +RUN echo "deb $REPOSITORY" | sed s/\$OS_CODENAME/$(lsb_release -cs)/ > /etc/apt/sources.list.d/postgrespro.list |
| 40 | + |
| 41 | +# Install Postgres Pro |
| 42 | +# There are some warnings (in red) that show up during the build. You can hide |
| 43 | +# them by prefixing each apt statement with DEBIAN_FRONTEND=noninteractive |
| 44 | +RUN apt-get update && apt-get install -y postgrespro-$PGPRO_EDN-$PG_VERSION postgrespro-$PGPRO_EDN-$PG_VERSION-server postgrespro-$PGPRO_EDN-$PG_VERSION-contrib |
| 45 | + |
| 46 | +WORKDIR /home/postgres |
| 47 | + |
| 48 | +ADD postgres-pgbench.tar.gz /home/postgres/src/postgres-pgbench |
| 49 | +RUN chown -R postgres:postgres /home/postgres/ |
| 50 | + |
| 51 | +# Setup jdbc driver |
| 52 | +RUN JAVA_VERSION=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}'); \ |
| 53 | + case "$JAVA_VERSION" in \ |
| 54 | + 1\.6* ) jdbcjar="https://jdbc.postgresql.org/download/postgresql-42.2.12.jre6.jar" ;; \ |
| 55 | + 1\.7* ) jdbcjar="https://jdbc.postgresql.org/download/postgresql-42.2.12.jre7.jar" ;; \ |
| 56 | + *) jdbcjar="https://jdbc.postgresql.org/download/postgresql-42.2.12.jar" ;; \ |
| 57 | + esac; \ |
| 58 | + [ -z "$jdbcjar" ] || wget --no-verbose "$jdbcjar" -P /usr/share/java |
| 59 | + |
| 60 | +RUN rm -rf /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data |
| 61 | + |
| 62 | +RUN /opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/pg-setup initdb |
| 63 | + |
| 64 | +COPY ./$PHASE2_ACTION /bin/ |
| 65 | +RUN $PHASE2_ACTION |
| 66 | + |
| 67 | +RUN touch /home/postgres/extra.conf && printf "\nlisten_addresses='*'\n"\ |
| 68 | +"logging_collector = on\n"\ |
| 69 | +"fsync = off\n"\ |
| 70 | +"max_connections = 500\n"\ |
| 71 | +"include '/home/postgres/extra.conf'\n" >> /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/postgresql.conf |
| 72 | +RUN m=$EXTRA_PG_MODULES; m="${m%\"}";m="${m#\"}"; \ |
| 73 | + [ ! -z "$m" ] || printf "\nshared_preload_libraries = '"$m"'\n" >> /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/postgresql.conf |
| 74 | +RUN p=$PG_PARAMETERS; p="${p%\"}"; p="${p#\"}"; \ |
| 75 | + [ -z "$p" ] || printf "\n$p\n" >> /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/postgresql.conf |
| 76 | + |
| 77 | +RUN sed -i -e 's/^\(host\s\+all\s\+all\s\+127\.0\.0\.1\/32\)/#\1/' \ |
| 78 | + -e 's/^\(host\s\+all\s\+all\s\+::1\/128\)/#\1/' /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/pg_hba.conf; \ |
| 79 | +printf "\n"\ |
| 80 | +"host all all 127.0.0.1/32 trust\n"\ |
| 81 | +"host all all 0.0.0.0/0 md5\n"\ |
| 82 | +"host all all ::1/128 trust\n" >> /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/pg_hba.conf |
| 83 | + |
| 84 | +RUN echo "/opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/postgres -D /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data -c config_file=/var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain |
| 85 | + |
| 86 | +# Run the rest of the commands as the ``postgres`` user created by the ``postgres*-$version`` package when it was ``apt installed`` |
| 87 | +USER postgres |
| 88 | + |
| 89 | +RUN /opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/pg_ctl start -D /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data -w && \ |
| 90 | + psql -c "CREATE USER tester WITH SUPERUSER PASSWORD 'tester'; ALTER user postgres password 'pgpass';" |
| 91 | + |
| 92 | +COPY ./setup-reference-pgbench /tmp/ |
| 93 | +RUN /tmp/setup-reference-pgbench $PG_VERSION |
| 94 | + |
| 95 | +# Expose the PostgreSQL port |
| 96 | +EXPOSE 5432 |
| 97 | + |
| 98 | +# Add VOLUMEs to allow backup of config, logs and databases |
| 99 | +VOLUME ["/var/lib/pgpro"] |
| 100 | + |
| 101 | +# Set the default command to run when starting the container |
| 102 | +CMD /usr/bin/pgmain |
0 commit comments