From a2e5e14cb68180d90cfd81a5f389798808dabf13 Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Fri, 1 Mar 2024 02:54:24 +0100 Subject: [PATCH 01/10] Updated to PostgreSQL 16 and added proper locale settings --- .gitignore | 3 ++- Dockerfile | 31 +++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 8d0d34d..6be227b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ node_modules local tmp .parcel-cache +.bash_history .env .mc @@ -34,4 +35,4 @@ docker-compose.override.yml .git root -dist \ No newline at end of file +dist diff --git a/Dockerfile b/Dockerfile index 785b73a..bd1f34c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,40 +2,43 @@ FROM buildpack-deps:bullseye ARG SRV_UID="1000" ARG SRV_GID="100" +ARG SRV_LOCALE="en_US" ARG SRV_VERSION="0" ENV SRV_UID $SRV_UID ENV SRV_GID $SRV_GID +ENV SRV_LOCALE $SRV_LOCALE ENV SRV_VERSION $SRV_VERSION ENV SRV_APT_GET_INSTALL $SRV_APT_GET_INSTALL ENV DEBIAN_FRONTEND "noninteractive" ENV PGDATA "/data" +ENV POSTGRES_INITDB_ARGS "--locale=${SRV_LOCALE}.UTF-8 --lc-ctype=${SRV_LOCALE}.UTF-8 --lc-monetary=${SRV_LOCALE}.UTF-8 --lc-numeric=${SRV_LOCALE}.UTF-8 --lc-time=${SRV_LOCALE}.UTF-8 --lc-collate=${SRV_LOCALE}.UTF-8 --encoding=UTF8" # explicitly set user/group IDs RUN if [ -z "$( getent group $SRV_GID )" ] ; then groupadd -r postgres --gid=$SRV_GID ; fi && \ useradd -r -g $SRV_GID --uid=$SRV_UID --home-dir=/var/lib/postgresql --shell=/bin/bash postgres && \ mkdir -p $PGDATA && chown -R $SRV_UID:$SRV_GID $PGDATA && \ - apt-get update -y && apt-get install -y lsb-release && \ + apt-get update -y && apt-get install -y apt-utils lsb-release && \ ( curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg ) && \ ( echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list ) && \ apt-get update -y && mkdir -p /docker-entrypoint-initdb.d && \ - apt-get install -y postgresql-15 postgresql-common postgresql-15-pglogical \ - postgresql-15-cron postgresql-15-extra-window-functions \ - postgresql-15-first-last-agg postgresql-15-jsquery postgresql-15-numeral \ - postgresql-15-pglogical-ticker postgresql-15-pgmemcache \ - postgresql-15-pgpcre postgresql-15-pgrouting postgresql-15-repack \ - postgresql-15-pgrouting-scripts postgresql-15-pgsphere \ - postgresql-15-postgis-3 postgresql-15-postgis-3-scripts \ - postgresql-15-repack postgresql-15-set-user postgresql-15-similarity \ - postgresql-15-pgpool2 postgresql-15-semver postgresql-15-repmgr \ - postgresql-15-tablelog postgresql-15-wal2json \ + apt-get install -y postgresql-16 postgresql-common postgresql-16-pglogical \ + postgresql-16-cron postgresql-16-extra-window-functions \ + postgresql-16-first-last-agg postgresql-16-jsquery postgresql-16-numeral \ + postgresql-16-pglogical-ticker postgresql-16-pgmemcache \ + postgresql-16-pgpcre postgresql-16-pgrouting postgresql-16-repack \ + postgresql-16-pgrouting-scripts postgresql-16-pgsphere \ + postgresql-16-postgis-3 postgresql-16-postgis-3-scripts \ + postgresql-16-repack postgresql-16-set-user postgresql-16-similarity \ + postgresql-16-pgpool2 postgresql-16-semver postgresql-16-repmgr \ + postgresql-16-tablelog postgresql-16-wal2json apgdiff locales-all \ $SRV_APT_GET_INSTALL && \ apt-get clean && rm -rf ~/.cache && rm -rf /var/lib/apt/lists/* -ENV PATH="/usr/lib/postgresql/15/bin:$PATH" +ENV PATH="/usr/lib/postgresql/16/bin:$PATH" -COPY docker-entrypoint.sh /usr/local/bin/ +COPY docker-entrypoint.sh / USER $SRV_UID:$SRV_GID @@ -45,7 +48,7 @@ VOLUME $PGDATA WORKDIR $PGDATA -ENTRYPOINT ["docker-entrypoint.sh"] +ENTRYPOINT ["/docker-entrypoint.sh"] STOPSIGNAL SIGINT From e5b3409a94358aadf853925b96cfbfdb31898390 Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Sun, 31 Mar 2024 00:09:33 +0100 Subject: [PATCH 02/10] Adding README and switching CI to latest Docker and Dind --- .gitlab-ci.yml | 4 ++-- README.md | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d066caa..9c9544d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: docker:20.10.16 +image: docker:latest variables: IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG @@ -9,7 +9,7 @@ stages: - release services: - - docker:20.10.16-dind + - docker:dind build: stage: build diff --git a/README.md b/README.md new file mode 100644 index 0000000..95fbff3 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# PostgreSQL 16 Image + +## How To Use + +### Args + +#### SRV_UID + +User ID for the PostgreSQL daemon and so of the data (Default: 1000) + +#### SRV_GID + +Group ID for the PostgreSQL daemon and so of the data (Default: 1000) + +#### SRV_LOCALE + +Locale used for initdb (Default: en_US) + +### Image Name + +``` +docker.ci/srv/postgres:latest +``` From 89d9f1e1a1f82ea386f5f4fd56b55c14798bfb8e Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Sun, 31 Mar 2024 00:21:09 +0100 Subject: [PATCH 03/10] docker should ignore bash history --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index f26be0a..3d24b46 100644 --- a/.dockerignore +++ b/.dockerignore @@ -24,6 +24,7 @@ table_meta* /*.pdf .gitignore +.bash_history node_modules local From c9ce644d4be5c2351c7fb79586f5f3f0f5ed5ce7 Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Sun, 31 Mar 2024 00:44:36 +0100 Subject: [PATCH 04/10] Listen address * by parameter enforced --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bd1f34c..e01f641 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,7 +54,7 @@ STOPSIGNAL SIGINT EXPOSE 5432 -CMD ["postgres"] +CMD ["postgres","-c","listen_addresses=*"] HEALTHCHECK --interval=30s --timeout=3s --retries=4 \ CMD pg_isready -U ${POSTGRES_USER:-postgres} From d7792be6e117428f4c4bc2b41a159bdc7246ecca Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Sun, 31 Mar 2024 04:56:06 +0200 Subject: [PATCH 05/10] Adding more README --- README.md | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 95fbff3..679a9c7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,20 @@ # PostgreSQL 16 Image +## About + +This is a special image that I created out of necessity to have a dynamic User ID and Group ID for the data of the PostgreSQL, while also solving the default listen address problem normally happening with Docker, without touching configuration. It will always listen to all network addresses. Additionally we use a Debian image and install the Debian packages for all the PostgreSQL modules from the official PostgreSQL Debian repository. This allows to activate them on demand. The image also contains a proper healthcheck that checks 4 times on the interval of 30 seconds with a timeout of 3 seconds. If you need this configurable, please contact me. The user will be called *postgres* and his home will be **/var/lib/postgresql**. The PostgreSQL itself is installed under **/data**. + ## How To Use -### Args +If you use the image, you will have to make a mount for the **/data** directory inside the image. Please be aware, that this directory must exist before and must have the same User ID and Group ID as the image is using, else Docker creates a root owned directory, the init db will fail. If you do not want the image to listen to all network addresses, then just set a new *command*. + +### Image Name + +The image name to use the image in your Docker is **docker.ci/srv/postgres:latest**. This is only applicable, if you do not want to change the User ID and Group ID. + +### ARGS + +For changing the ARGS, you need to copy the repository and build the image yourself with setting the necessary ARGS to get a new image. As convention, you could use the User ID as the tag name for your new image, we will not make an official tag that is just a number, so you will not collide here in the future. Of course, you can also just give it then a complete new image name, so that there can't be any collide. #### SRV_UID @@ -14,10 +26,18 @@ Group ID for the PostgreSQL daemon and so of the data (Default: 1000) #### SRV_LOCALE -Locale used for initdb (Default: en_US) +Locale used for *initdb*, it will be extended with **.UTF-8** and set for *locale*, *lc-ctype*, *lc-monetary*, *lc-numeric*, *lc-time* and *lc-collate*. In addition *encoding* is set to **UTF8**. Please be aware that after the database is initialized, a changing of this parameter is not having any effect, the database will not change its settings, also new databases are not set with different parameters, as *initdb* is not used there anymore. (Default: en_US) -### Image Name +## Support -``` -docker.ci/srv/postgres:latest -``` +### Discord + +Join the [**People, Postgres, Data**](https://discord.gg/bW2hsax8We) Discord and highlight **Getty** for support. + +### IRC + +Join the [**Libera.Chat**](https://libera.chat/) IRC server and best message **Getty** for support, you can also join the **#postgresql** channel there, via **irc://irc.libera.chat:+6697/postgresql**. + +### Email + +You can also email me under [**getty@conflict.industries**](mailto:getty@conflict.industries) From 015f5601ccf755abb077236bd99e11575b5c71a8 Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Sun, 31 Mar 2024 04:58:07 +0200 Subject: [PATCH 06/10] Mentioning that its a non-root image --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 679a9c7..ad08fac 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## About -This is a special image that I created out of necessity to have a dynamic User ID and Group ID for the data of the PostgreSQL, while also solving the default listen address problem normally happening with Docker, without touching configuration. It will always listen to all network addresses. Additionally we use a Debian image and install the Debian packages for all the PostgreSQL modules from the official PostgreSQL Debian repository. This allows to activate them on demand. The image also contains a proper healthcheck that checks 4 times on the interval of 30 seconds with a timeout of 3 seconds. If you need this configurable, please contact me. The user will be called *postgres* and his home will be **/var/lib/postgresql**. The PostgreSQL itself is installed under **/data**. +This is a special image that I created out of necessity to have a dynamic User ID and Group ID for the data of the PostgreSQL, while also solving the default listen address problem normally happening with Docker, without touching configuration. It will always listen to all network addresses. Additionally we use a Debian image and install the Debian packages for all the PostgreSQL modules from the official PostgreSQL Debian repository. This allows to activate them on demand. The image also contains a proper healthcheck that checks 4 times on the interval of 30 seconds with a timeout of 3 seconds. If you need this configurable, please contact me. The user will be called *postgres* and his home will be **/var/lib/postgresql**. The PostgreSQL itself is installed under **/data**. Additionally the image is not running as *root*. ## How To Use From 8a1a8a4e5bd8feb780edc06301beac6ded49e201 Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Sun, 31 Mar 2024 05:20:01 +0200 Subject: [PATCH 07/10] More information about the image, additional example for docker-compose custom image generation. --- README.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ad08fac..bc46cb5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## About -This is a special image that I created out of necessity to have a dynamic User ID and Group ID for the data of the PostgreSQL, while also solving the default listen address problem normally happening with Docker, without touching configuration. It will always listen to all network addresses. Additionally we use a Debian image and install the Debian packages for all the PostgreSQL modules from the official PostgreSQL Debian repository. This allows to activate them on demand. The image also contains a proper healthcheck that checks 4 times on the interval of 30 seconds with a timeout of 3 seconds. If you need this configurable, please contact me. The user will be called *postgres* and his home will be **/var/lib/postgresql**. The PostgreSQL itself is installed under **/data**. Additionally the image is not running as *root*. +This is a special image that I created out of necessity to have a dynamic User ID and Group ID for the data of the PostgreSQL, while also solving the default listen address problem normally happening with Docker, without touching configuration. It will always listen to all network addresses. Additionally we use a Debian image and install the Debian packages for all the PostgreSQL modules from the official PostgreSQL Debian repository. This allows to activate them on demand. The image also contains a proper healthcheck that checks 4 times on the interval of 30 seconds with a timeout of 3 seconds. If you need this configurable, please contact me. The user will be called *postgres* and his home will be **/var/lib/postgresql**. The PostgreSQL itself is installed under **/data**. Additionally the image is not running as *root* and is using the official Docker image *docker-entrypoint.sh* as documented on the [PostgreSQL Docker Hub page](https://hub.docker.com/_/postgres). ## How To Use @@ -10,11 +10,28 @@ If you use the image, you will have to make a mount for the **/data** directory ### Image Name -The image name to use the image in your Docker is **docker.ci/srv/postgres:latest**. This is only applicable, if you do not want to change the User ID and Group ID. +The image name for your Docker is **docker.ci/srv/postgres:latest**. This is only applicable, if you do not want to change the User ID and Group ID. ### ARGS -For changing the ARGS, you need to copy the repository and build the image yourself with setting the necessary ARGS to get a new image. As convention, you could use the User ID as the tag name for your new image, we will not make an official tag that is just a number, so you will not collide here in the future. Of course, you can also just give it then a complete new image name, so that there can't be any collide. +For changing the ARGS, you need to copy the repository and build the image yourself with setting the necessary ARGS to get a new image. As convention, you could use the User ID as the tag name for your new image, we will not make an official tag that is just a number, so you will not collide here in the future. Of course, you can also just give it then a complete new image name, so that there can't be any collide. You can also *git submodule* the repository in a subdirectory and then add it with args to your Docker-Compose configuration, like in this example, assuming you put the submodule of the repository under *docker/postgres*: + +```yaml +services: + db: + image: "docker.ci/srv/postgres:1010" + volumes: + - "db-volume:/data" + environment: + POSTGRES_USER: "myuser" + POSTGRES_DBNAME: "myuser" + POSTGRES_PASSWORD: "mypass" + ALLOW_IP_RANGE: "0.0.0.0/0" + build: + context: "docker/postgres" + args: + SRV_UID: "1010" +``` #### SRV_UID From af2ea1924cb419ea6dbeebc634fdff362d88ae1d Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Sun, 31 Mar 2024 21:59:43 +0200 Subject: [PATCH 08/10] Fixing the unnecessary integration of POSTGRES_USER from healthcheck --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e01f641..b8e7279 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,4 +57,4 @@ EXPOSE 5432 CMD ["postgres","-c","listen_addresses=*"] HEALTHCHECK --interval=30s --timeout=3s --retries=4 \ - CMD pg_isready -U ${POSTGRES_USER:-postgres} + CMD pg_isready -U postgres From cdece0f7729bd9dd7d2a8ceb097571170ec90450 Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Sat, 17 Aug 2024 01:16:42 +0200 Subject: [PATCH 09/10] =?UTF-8?q?Adding=20plperl,=20plpython,=20Apache=20A?= =?UTF-8?q?ge,=20pgvector=20to=20be=20ready=20for=20AI=20=F0=9F=A4=96=20de?= =?UTF-8?q?mands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b8e7279..118f038 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,8 +32,9 @@ RUN if [ -z "$( getent group $SRV_GID )" ] ; then groupadd -r postgres --gid=$SR postgresql-16-postgis-3 postgresql-16-postgis-3-scripts \ postgresql-16-repack postgresql-16-set-user postgresql-16-similarity \ postgresql-16-pgpool2 postgresql-16-semver postgresql-16-repmgr \ - postgresql-16-tablelog postgresql-16-wal2json apgdiff locales-all \ - $SRV_APT_GET_INSTALL && \ + postgresql-plperl-16 postgresql-plpython3-16 postgresql-16-age \ + postgresql-16-pgvector postgresql-16-tablelog postgresql-16-wal2json \ + apgdiff locales-all $SRV_APT_GET_INSTALL && \ apt-get clean && rm -rf ~/.cache && rm -rf /var/lib/apt/lists/* ENV PATH="/usr/lib/postgresql/16/bin:$PATH" From 0ea86a8c05514afe0bd29baf40451086f9b1c904 Mon Sep 17 00:00:00 2001 From: Torsten Raudssus Date: Sat, 26 Oct 2024 04:23:37 +0200 Subject: [PATCH 10/10] Updated docker URL --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bc46cb5..cfff5e3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ If you use the image, you will have to make a mount for the **/data** directory ### Image Name -The image name for your Docker is **docker.ci/srv/postgres:latest**. This is only applicable, if you do not want to change the User ID and Group ID. +The image name for your Docker is **src.ci/srv/postgres:latest**. This is only applicable, if you do not want to change the User ID and Group ID. ### ARGS @@ -19,7 +19,7 @@ For changing the ARGS, you need to copy the repository and build the image yours ```yaml services: db: - image: "docker.ci/srv/postgres:1010" + image: "src.ci/srv/postgres:1010" volumes: - "db-volume:/data" environment: @@ -49,7 +49,7 @@ Locale used for *initdb*, it will be extended with **.UTF-8** and set for *local ### Discord -Join the [**People, Postgres, Data**](https://discord.gg/bW2hsax8We) Discord and highlight **Getty** for support. +Join the [**People, Postgres, Data**](https://discord.gg/bW2hsax8We) Discord and highlight **Getty** for support. ### IRC