diff --git a/.woodpecker.yml b/.woodpecker.yml index 5a8364d..a365c20 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -4,10 +4,12 @@ pipeline: registry: registry.nulo.in repo: registry.nulo.in/sutty/postgresql tags: - - ${ALPINE_VERSION} + - ${ALPINE_VERSION}-${PG_VERSION} - latest build_args: - ALPINE_VERSION=${ALPINE_VERSION} + - PG_VERSION=${PG_VERSION} + - PG_VERSION_APPENDED=${PG_VERSION_APPENDED} - BASE_IMAGE=registry.nulo.in/sutty/monit username: sutty secrets: @@ -15,8 +17,15 @@ pipeline: when: branch: antifascista event: push - matrix: - ALPINE_VERSION: - - 3.13.6 - - 3.14.2 + include: + - ALPINE_VERSION: 3.13.7 + PG_VERSION: 13 + - ALPINE_VERSION: 3.14.3 + PG_VERSION: 13 + - ALPINE_VERSION: 3.15.0 + PG_VERSION: 13 + PG_VERSION_APPENDED: 13 + - ALPINE_VERSION: 3.15.0 + PG_VERSION: 14 + PG_VERSION_APPENDED: 14 diff --git a/Dockerfile b/Dockerfile index 075631b..0b45ee1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,22 +2,22 @@ ARG ALPINE_VERSION=3.13.6 ARG BASE_IMAGE=sutty/monit FROM ${BASE_IMAGE}:${ALPINE_VERSION} MAINTAINER "f " +ARG PG_VERSION=13 +ARG PG_VERSION_APPENDED -ENV PGBASE /var/lib/postgresql -ENV PGDATA $PGBASE/13/data -ENV LANG en_US.utf8 -ENV PGUSER sutty -ENV PGDB sutty -ENV PGVER 13 -ENV PGCLIENT sutty -ENV PAGER "less -niSFX" +ENV PGVER=$PG_VERSION +ENV PGBASE=/var/lib/postgresql +ENV PGDATA=${PGBASE}/${PGVER}/data +ENV PAGER="less -niSFX" -RUN apk add --no-cache postgresql postgresql-contrib daemonize less +# Starting from Alpine 3.15 there are several PostgreSQL versions +# supported. +RUN apk add --no-cache postgresql${PG_VERSION_APPENDED} postgresql${PG_VERSION_APPENDED}-contrib daemonize less +RUN install -dm 750 -o postgres -g postgres /etc/postgres.d -COPY ./postgresql.sh /usr/local/bin/postgresql COPY ./monit.conf /etc/monit.d/postgresql.conf - -RUN chmod 750 /usr/local/bin/postgresql +COPY ./postgresqld.sh /usr/local/bin/postgresqld +COPY ./postgresql.conf /etc/postgres.d/postgresql.conf EXPOSE 5432 VOLUME $PGBASE diff --git a/monit.conf b/monit.conf index d968884..f46e079 100644 --- a/monit.conf +++ b/monit.conf @@ -1,4 +1,4 @@ -check process postgresql with pidfile /tmp/postgresql.pid - start program = "/usr/local/bin/postgresql start" - stop program = "/usr/local/bin/postgresql stop" +check process postgresql with pidfile /run/postgresql.pid + start program = "/usr/local/bin/postgresqld start" + stop program = "/usr/local/bin/postgresqld stop" if failed port 5432 protocol pgsql for 3 times within 5 cycles then restart diff --git a/postgresql.conf b/postgresql.conf new file mode 100644 index 0000000..a07cd97 --- /dev/null +++ b/postgresql.conf @@ -0,0 +1,7 @@ +listen_addresses = '*' +external_pid_file = '/run/postgresql.pid' +log_destination = 'syslog' +log_checkpoints = on +log_connections = on +log_disconnections = on +log_hostname = on diff --git a/postgresql.sh b/postgresql.sh deleted file mode 100644 index a06b85c..0000000 --- a/postgresql.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh -set -e - -case $1 in - stop) - /bin/su postgres -c "pg_ctl stop -D ${PGDATA}" ;; - reload) - /bin/su postgres -c "pg_ctl reload -D ${PGDATA}" ;; - *) - pid=/tmp/postgresql.pid - user=postgres - log=${PGDATA}/postgresql.log - - install -dm 2750 -o postgres -g postgres /run/postgresql - chown -R postgres:postgres ${PGBASE} - - if test ! -f ${PGDATA}/PG_VERSION ; then - su - postgres -c "/usr/bin/initdb --locale ${LANG} -E UTF8 -D ${PGDATA}" - su - postgres -c "/usr/bin/pg_ctl start --pgdata ${PGDATA}" - su - postgres -c "/usr/bin/createuser --login ${PGUSER}" - su - postgres -c "/usr/bin/createdb --owner ${PGUSER} ${PGDB}" - su - postgres -c "/usr/bin/pg_ctl stop --pgdata ${PGDATA}" - - echo "host ${PGDB} ${PGUSER} ${PGCLIENT} trust" >> ${PGDATA}/pg_hba.conf - echo "host ${PGDB}_test ${PGUSER} ${PGCLIENT} trust" >> ${PGDATA}/pg_hba.conf - - echo "listen_addresses = '*'" >> ${PGDATA}/postgresql.conf - echo "external_pid_file = '${pid}'" >> ${PGDATA}/postgresql.conf - fi - - rm -f ${pid} - daemonize -u ${user} -c ${PGDATA} -o ${log} -a -e ${log} \ - /usr/bin/postgres - - su - postgres -c "echo 'create extension if not exists pgcrypto;' | psql -U postgres" - ;; -esac diff --git a/postgresqld.sh b/postgresqld.sh new file mode 100644 index 0000000..bc48997 --- /dev/null +++ b/postgresqld.sh @@ -0,0 +1,24 @@ +#!/bin/sh +set -e + +case $1 in + stop) + su postgres -c "pg_ctl stop -D ${PGDATA}" ;; + reload) + su postgres -c "pg_ctl reload -D ${PGDATA}" ;; + *) + pid=/run/postgresql.pid + + install -dm 2750 -o ${user} -g ${user} /run/postgresql + chown -R ${user}:${user} ${PGBASE} + + if test ! -f ${PGDATA}/PG_VERSION ; then + su postgres -c "/usr/bin/initdb -D ${PGDATA}" + + echo "include_dir = '/etc/postgres.d'" >> ${PGDATA}/postgresql.conf + fi + + rm -f ${pid} + daemonize -u postgres -c ${PGDATA} /usr/bin/postgres + ;; +esac