|
| 1 | +FROM docker.io/ubuntu:24.04 |
| 2 | +MAINTAINER Julio Gonzalez Gil <git@juliogonzalez.es> |
| 3 | + |
| 4 | +USER root |
| 5 | + |
| 6 | +# Set locale (will be used by PostgreSQL initdb later on) |
| 7 | +# Also install gnupg2, to be used by apt-key later on (apt-key does not have a explicit dependency) |
| 8 | +RUN apt-get -qq -o=Dpkg::Use-Pty=0 update > /dev/null && \ |
| 9 | + apt-get -qq -o=Dpkg::Use-Pty=0 -y install locales gnupg2 && \ |
| 10 | + apt-get -qq -o=Dpkg::Use-Pty=0 clean > /dev/null && \ |
| 11 | + DEBIAN_FRONTEND=noninteractive locale-gen en_US.UTF-8 && \ |
| 12 | + DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales && \ |
| 13 | + update-locale LANG=en_US.UTF-8 |
| 14 | +ENV LANG en_US.UTF-8 |
| 15 | +ENV LANGUAGE en_US:en |
| 16 | +ENV LC_ALL en_US.UTF-8 |
| 17 | + |
| 18 | + |
| 19 | +# Default UID/GID for mounting folders (used at jenkins slaves) |
| 20 | +ARG UID=500 |
| 21 | +ARG GID=500 |
| 22 | + |
| 23 | +# Create postgres group and user according to arguments UID/GID |
| 24 | +RUN groupadd -g ${GID} postgres |
| 25 | +RUN useradd -d /var/lib/postgresql -u ${UID} -g ${GID} postgres && mkdir /var/lib/postgresql && chown postgres:postgres /var/lib/postgresql |
| 26 | + |
| 27 | +# Create the wrappers to start PostgreSQL and check for PostgreSQL Updates |
| 28 | +ADD files/*.sh /opt/ |
| 29 | + |
| 30 | +# PostgreSQL arguments |
| 31 | +# Default version |
| 32 | +ARG POSTGRESQL_VER=9.5 |
| 33 | +ENV POSTGRESQL_VER=${POSTGRESQL_VER} |
| 34 | +ARG POSTGRESQL_TESTING=0 |
| 35 | +ENV POSTGRESQL_TESTING=${POSTGRESQL_TESTING} |
| 36 | + |
| 37 | +# Pass the output of date command as DATE argument if you want |
| 38 | +# make sure that the image is generated using the lastest |
| 39 | +# PostgreSQL packages (cache will be used for previous steps) |
| 40 | +ARG DATE=None |
| 41 | + |
| 42 | +# Add the PostgreSQL PGP key to verify their Debian packages and install them |
| 43 | +# Key should be the same as https://www.postgresql.org/media/keys/ACCC4CF8.asc |
| 44 | +# Then generate a list of original packages, upgrade and install PostgreSQL |
| 45 | +RUN dpkg --get-selections | grep 'install' | grep -v 'deinstall'|cut -f1 > /opt/packages-image.txt && \ |
| 46 | + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 && \ |
| 47 | + apt-get -qq -o=Dpkg::Use-Pty=0 update > /dev/null && \ |
| 48 | + LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 DEBIAN_FRONTEND=noninteractive apt-get -qq -o=Dpkg::Use-Pty=0 -y install ca-certificates && \ |
| 49 | + LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 DEBIAN_FRONTEND=noninteractive apt-get -qq -o=Dpkg::Use-Pty=0 -y dist-upgrade > /dev/null && \ |
| 50 | + [ ${POSTGRESQL_TESTING} -eq 1 ] && TESTING="-testing"; echo "deb https://download.postgresql.org/pub/repos/apt/ focal-pgdg${testing} ${POSTGRESQL_VER} main" >> /etc/apt/sources.list.d/pgdg.list && \ |
| 51 | + apt-get -qq -o=Dpkg::Use-Pty=0 update > /dev/null && \ |
| 52 | + LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 DEBIAN_FRONTEND=noninteractive apt-get -qq -o=Dpkg::Use-Pty=0 -y install \ |
| 53 | + postgresql-${POSTGRESQL_VER} \ |
| 54 | + postgresql-client-${POSTGRESQL_VER} \ |
| 55 | + postgresql-server-dev-${POSTGRESQL_VER} > /dev/null && \ |
| 56 | + apt-get -qq -o=Dpkg::Use-Pty=0 clean > /dev/null # ${DATE} |
| 57 | + |
| 58 | +# Allow PostgreSQL password acess from localhost |
| 59 | +RUN sed -i -r -e 's/host\s+all\s+all\s+127.0.0.1\/32\s+md5/host all all 127.0.0.1\/32 password/' /etc/postgresql/${POSTGRESQL_VER}/main/pg_hba.conf |
| 60 | + |
| 61 | +# Configure temporary dir |
| 62 | +RUN mkdir -p /var/run/postgresql/${POSTGRESQL_VER}-main.pg_stat_tmp && chown postgres:postgres /var/run/postgresql/${POSTGRESQL_VER}-main.pg_stat_tmp |
| 63 | + |
| 64 | +# Expose the PostgreSQL port |
| 65 | +EXPOSE 5432 |
| 66 | + |
| 67 | +# Seems there is a problem with the latest openSUSE MicroOS as if |
| 68 | +# userns is used to launch the container, the /var/log/postgresql |
| 69 | +# is owned by UID/GID 1002 which does not exist on the container or |
| 70 | +# the OS |
| 71 | +# I still could not find where the issue is, but we do not need to |
| 72 | +# do anything for Ubuntu, unlike for other OS, as rights are |
| 73 | +# 755 already |
| 74 | + |
| 75 | +# Add VOLUMEs to allow backup of config, logs and databases |
| 76 | +VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"] |
| 77 | + |
| 78 | +USER postgres |
| 79 | + |
| 80 | +CMD ["/bin/bash", "/opt/start_postgresql.sh"] |
0 commit comments