Compare commits

...

10 commits

Author SHA1 Message Date
Torsten Raudssus
0ea86a8c05 Updated docker URL 2024-10-26 04:23:37 +02:00
Torsten Raudssus
cdece0f772 Adding plperl, plpython, Apache Age, pgvector to be ready for AI 🤖 demands 2024-08-17 01:16:42 +02:00
Torsten Raudssus
af2ea1924c Fixing the unnecessary integration of POSTGRES_USER from healthcheck 2024-03-31 21:59:43 +02:00
Torsten Raudssus
8a1a8a4e5b More information about the image, additional example for docker-compose custom image generation. 2024-03-31 05:20:01 +02:00
Torsten Raudssus
015f5601cc Mentioning that its a non-root image 2024-03-31 04:58:07 +02:00
Torsten Raudssus
d7792be6e1 Adding more README 2024-03-31 04:56:06 +02:00
Torsten Raudssus
c9ce644d4b Listen address * by parameter enforced 2024-03-31 00:44:36 +01:00
Torsten Raudssus
89d9f1e1a1 docker should ignore bash history 2024-03-31 00:21:09 +01:00
Torsten Raudssus
e5b3409a94 Adding README and switching CI to latest Docker and Dind 2024-03-31 00:09:33 +01:00
Torsten Raudssus
a2e5e14cb6 Updated to PostgreSQL 16 and added proper locale settings 2024-03-01 02:54:24 +01:00
5 changed files with 86 additions and 20 deletions

View file

@ -24,6 +24,7 @@ table_meta*
/*.pdf
.gitignore
.bash_history
node_modules
local

3
.gitignore vendored
View file

@ -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
dist

View file

@ -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

View file

@ -2,40 +2,44 @@ 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 \
$SRV_APT_GET_INSTALL && \
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-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/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,13 +49,13 @@ VOLUME $PGDATA
WORKDIR $PGDATA
ENTRYPOINT ["docker-entrypoint.sh"]
ENTRYPOINT ["/docker-entrypoint.sh"]
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}
CMD pg_isready -U postgres

60
README.md Normal file
View file

@ -0,0 +1,60 @@
# 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**. 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
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 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
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: "src.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
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*, 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)
## Support
### 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)