From f2517f786d46fbf8fe6db9414ba2d40ec164472c Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Tue, 12 Nov 2024 17:02:53 +0100 Subject: [PATCH] - Move & Rename repo from Rx3/PostgreSQL-MGA9 to Rx3-Docker/PostgreSQL, - New version naming standard, - Now use docker_tools for .env building, - Use now rx3-docker/server:1.2.0-mga9 image, - Add /var/log/init, /var/log/supervisor & var/log/postgres volumes, - Add healthcheck example in compose file. --- Dockerfile | 113 ++++++++++++++++++---------------- ReadMe.txt | 6 +- ReleaseNotes.txt | 7 ++- compose.yaml | 40 +++++++----- env => env.dist | 35 ++++++++--- var/log/init/.gitignore | 4 ++ var/log/postgres/.gitignore | 4 ++ var/log/supervisor/.gitignore | 4 ++ 8 files changed, 129 insertions(+), 84 deletions(-) rename env => env.dist (55%) create mode 100644 var/log/init/.gitignore create mode 100644 var/log/postgres/.gitignore create mode 100644 var/log/supervisor/.gitignore diff --git a/Dockerfile b/Dockerfile index a99a387..89f0c27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,28 @@ -# Rx3 PosgreSQL Mageia-9 Docker Image +# Rx3-Docker/PosgreSQL Docker Image #------------------------------------------------------------------------------- -ARG IMG_URL_PREFIX="rx3" +ARG IMG_FROM_URL="rx3-docker/server:latest" -FROM ${IMG_URL_PREFIX}/server-mga9:1.1.3 +FROM ${IMG_FROM_URL} ARG IMG_NAME -ARG IMG_FULL_NAME +ARG IMG_NAME_FULL ARG IMG_VERSION ARG IMG_MAINTAINER -LABEL org.rx3.${IMG_NAME}.name=${IMG_FULL_NAME} +LABEL org.rx3.${IMG_NAME}.name=${IMG_NAME_FULL} LABEL org.rx3.${IMG_NAME}.version=${IMG_VERSION} LABEL org.rx3.${IMG_NAME}.maintainer=${IMG_MAINTAINER} LABEL maintainer=${IMG_MAINTAINER} -ARG POSTGRESQL_LIB=/var/lib/pgsql -ARG POSTGRESQL_DATA=${POSTGRESQL_LIB}/data -ARG POSTGRESQL_PORT=5432 +ARG POSTGRESQL_LIB +ARG POSTGRESQL_DATA +ARG POSTGRESQL_PORT +ARG POSTSQL_LOG_DIR + +ARG POSTSQL_LOG_FILE="${POSTSQL_LOG_DIR}/postsql.log" + + #----------------------------------------------------------------------------------------------------------------------------- ARG POSTGRESQLD='#!/bin/bash \n\ @@ -52,62 +57,62 @@ then echo "host all all 0.0.0.0/0 password" >>'${POSTGRESQL_DATA}'/pg_hba.conf \n\ sed -i "s/#port = 5432/listen_addresses=`*`\\n#port = 5432/" '${POSTGRESQL_DATA}'/postgresql.conf \n\ fi' -#--------------------------------------------------------------------------------------------------- +#----------------------------------------------------------------------------------------------------------------------------- -#--------------------------------------------------------------------------------------------------- -ARG POSTGRESQLD_INI='[program:postgresqld] \n\ -command=/usr/bin/postgres -D '${POSTGRESQL_DATA}' -p '${POSTGRESQL_PORT}' \n\ +#----------------------------------------------------------------------------------------------------------------------------- +ARG POSTGRESQLD_INI='[program:postgresqld] \n\ +command=/usr/bin/postgres -D '${POSTGRESQL_DATA}' -p '${POSTGRESQL_PORT}' \n\ user=postgres' -#--------------------------------------------------------------------------------------------------- +#----------------------------------------------------------------------------------------------------------------------------- -#--------------------------------------------------------------------------------------------------- -ARG POSTSQL='#!/bin/bash \n\ - \n\ -function log() { echo "$(date --rfc-3339=ns) PostSQL: $*" | tee -a /var/log/postsql.log; } \n\ - \n\ -log "Starting" \n\ - \n\ -for i in {30..0} \n\ -do \n\ - if psql --username=postgres <<< "SELECT 1" &> /dev/null \n\ - then \n\ - break \n\ - fi \n\ - \n\ - sleep 1 \n\ -done \n\ - \n\ -if [ "$i" = 0 ] \n\ -then \n\ - log "Unable to connect server" \n\ -else \n\ - while read line \n\ - do \n\ - log "Executing: [${line}]" \n\ - echo ${line} | psql --username=postgres \n\ - done < /tmp/post.sql \n\ -fi \n\ - \n\ +#----------------------------------------------------------------------------------------------------------------------------- +ARG POSTSQL='#!/bin/bash \n\ + \n\ +function log() { echo "$(date --rfc-3339=ns) PostSQL: $*" | tee -a '${POSTSQL_LOG_FILE}'; } \n\ + \n\ +log "Starting" \n\ + \n\ +for i in {30..0} \n\ +do \n\ + if psql --username=postgres <<< "SELECT 1" &> /dev/null \n\ + then \n\ + break \n\ + fi \n\ + \n\ + sleep 1 \n\ +done \n\ + \n\ +if [ "$i" = 0 ] \n\ +then \n\ + log "Unable to connect server" \n\ +else \n\ + while read line \n\ + do \n\ + log "Executing: [${line}]" \n\ + echo ${line} | psql --username=postgres \n\ + done < /tmp/post.sql \n\ +fi \n\ + \n\ log "Completed"' -#--------------------------------------------------------------------------------------------------- +#----------------------------------------------------------------------------------------------------------------------------- -#--------------------------------------------------------------------------------------------------- -ARG POSTSQL_INI='[program:postsql] \n\ +#----------------------------------------------------------------------------------------------------------------------------- +ARG POSTSQL_INI='[program:postsql] \n\ command=/usr/local/sbin/postsql' -#--------------------------------------------------------------------------------------------------- +#----------------------------------------------------------------------------------------------------------------------------- -RUN urpmi --force postgresql15 postgresql15-server postgresql15-pl \ - && echo -e "${POSTGRESQLD}" | sed -e "s/\`/'/g" -e 's/ *$//' > /etc/init.d/postgresqld \ - && chmod a+x /etc/init.d/postgresqld \ - && ln -s /etc/init.d/postgresqld /etc/rcD.d/S30postgresqld \ - && echo -e "${POSTGRESQLD_INI}" | sed -e "s/\`/'/g" -e 's/ *$//' > /etc/supervisord.d/postgresqld.ini \ - && echo -e "${POSTSQL}" | sed -e "s/\`/'/g" -e 's/ *$//' > /usr/local/sbin/postsql \ - && chmod a+x /usr/local/sbin/postsql \ - && echo -e "${POSTSQL_INI}" | sed -e 's/ *$//' > /etc/supervisord.d/postsql.ini +RUN urpmi --force postgresql15 postgresql15-server postgresql15-pl \ + && echo -e "${POSTGRESQLD}" | sed -e "s/\`/'/g" -e 's/ *$//' > /etc/init.d/postgresqld \ + && chmod a+x /etc/init.d/postgresqld \ + && ln -s /etc/init.d/postgresqld /etc/rcD.d/S30postgresqld \ + && echo -e "${POSTGRESQLD_INI}" | sed -e "s/\`/'/g" -e 's/ *$//' > /etc/supervisord.d/postgresqld.ini \ + && echo -e "${POSTSQL}" | sed -e "s/\`/'/g" -e 's/ *$//' > /usr/local/sbin/postsql \ + && chmod a+x /usr/local/sbin/postsql \ + && echo -e "${POSTSQL_INI}" | sed -e 's/ *$//' > /etc/supervisord.d/postsql.ini -VOLUME /var/lib/pgsql +VOLUME ${POSTGRESQL_LIB} EXPOSE 5432 diff --git a/ReadMe.txt b/ReadMe.txt index 9eedd60..ce47f17 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -1,8 +1,8 @@ -Welcome to Rx3/PostgreSQL-Mga9 docker image! +Welcome to Rx3-Docker/PostgreSQL docker image! -This is project aims to build a PostgreSQL + Mageia 9 docker image used by others Rx3 packaging projects. +This project aims to build a PostgreSQL docker image used by other Rx3 packaging projects. Features: - Curtently based on rx3/server-mga9:1.1.2 image, @@ -19,4 +19,4 @@ Your Rx3 Team. -- arnaud@rx3.net -https://git.rx3.org/gitea/rx3/postgresql-mga9 +https://git.rx3.org/gitea/rx3-docker/postgresql diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 19bce72..0c0a6f0 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,7 +1,12 @@ ------------------------------------------------------------------------------------------------------------------------------------ -Rx3/PostgreSQL-Mga9 V 1.0.3 - A. GIBERT - 2024/11/xx +Rx3/PostgreSQL-Mga9 V 1.1.0 - A. GIBERT - 2024/11/12 ------------------------------------------------------------------------------------------------------------------------------------ +- Move & Rename repo from Rx3/PostgreSQL-MGA9 to Rx3-Docker/PostgreSQL, +- New version naming standard, +- Now use docker_tools for .env building, +- Use now rx3-docker/server:1.2.0-mga9 image, +- Add /var/log/init, /var/log/supervisor & var/log/postgres volumes, - Add healthcheck example in compose file. diff --git a/compose.yaml b/compose.yaml index 82abc22..318cda2 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,23 +1,29 @@ -# Rx3 PostgreSQL Mageia-9 Docker Image +# Rx3-Docker/PostgreSQL Docker Image #------------------------------------------------------------------------------- -name: ${IMG_NAME} +name: ${IMG_NAME} services: database: - container_name: ${IMG_NAME} - - image: ${IMG_URL} + container_name: ${IMG_NAME} + hostname: ${IMG_NAME} + + image: ${IMG_URL} build: - context: . + context: . args: - - IMG_NAME=${IMG_NAME} - - IMG_FULL_NAME=${IMG_FULL_NAME} - - IMG_VERSION=${IMG_VERSION} - - IMG_MAINTAINER=${IMG_MAINTAINER} - - IMG_URL_PREFIX=${IMG_URL_PREFIX} + IMG_NAME: ${IMG_NAME} + IMG_NAME_FULL: ${IMG_NAME_FULL} + IMG_VERSION: ${IMG_VERSION} + IMG_MAINTAINER: ${IMG_MAINTAINER} + IMG_FROM_URL: ${IMG_FROM_URL} + + POSTGRESQL_LIB: ${DATABASE_LIB_DIR} + POSTGRESQL_DATA: ${DATABASE_DATA_DIR} + POSTGRESQL_PORT: ${DATABASE_PORT_MAIN_INT} + POSTSQL_LOG_DIR: ${DATABASE_LOG_POSTSQL_DIR} restart: unless-stopped @@ -37,9 +43,11 @@ services: volumes: - ./var/lib/pgsql/data:/var/lib/pgsql/data - - network_mode: bridge - + - ./var/log/init:${DATABASE_LOG_INIT_DIR} + - ./var/log/supervisor:${DATABASE_LOG_SV_DIR} + - ./var/log/postgres:${DATABASE_LOG_POSTGRES_DIR} + ports: - - "127.0.0.1:${DATABASE_SV_PORT}:9001" - - "127.0.0.1:${DATABASE_PORT}:5432" + - "127.0.0.1:${DATABASE_PORT_SV_EXT}:${DATABASE_PORT_SV_INT}" + - "127.0.0.1:${DATABASE_PORT_MAIN_EXT}:${DATABASE_PORT_MAIN_INT}" + diff --git a/env b/env.dist similarity index 55% rename from env rename to env.dist index cc2d16c..0b19164 100644 --- a/env +++ b/env.dist @@ -1,13 +1,14 @@ -# Rx3 PostgreSQL Mageia-9 Docker Image +# Rx3-Docker/PostgreSQL Docker Image #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # Global Settings #------------------------------------------------------------------------------- -IMG_ORG="rx3" -IMG_REGISTRY="docker.xor.rx3:5000" -IMG_URL_PREFIX="${IMG_REGISTRY}/${IMG_ORG}" +ORG_NAME="rx3-docker" +ORG_REGISTRY="docker.xor.rx3:5000" + +ORG_URL_PREFIX="${ORG_REGISTRY}/${ORG_NAME}" @@ -15,12 +16,16 @@ IMG_URL_PREFIX="${IMG_REGISTRY}/${IMG_ORG}" # Image Settings #------------------------------------------------------------------------------- -IMG_NAME="postgresql-mga9" -IMG_FULL_NAME="Rx3 PostgreSQL Mageia-9 Docker Image" -IMG_VERSION="1.0.2" -IMG_URL="${IMG_URL_PREFIX}/${IMG_NAME}:${IMG_VERSION}" +IMG_NAME="postgresql" +IMG_NAME_FULL="Rx3-Docker/PostgreSQL Docker Image" +IMG_VERSION="1.1.0-mga9" IMG_MAINTAINER='"Arnaud G. GIBERT" ' +IMG_URL_PREFIX="${ORG_URL_PREFIX}" +IMG_URL="${IMG_URL_PREFIX}/${IMG_NAME}:${IMG_VERSION}" + +IMG_FROM_URL="${ORG_URL_PREFIX}/server:1.2.0-mga9" + #------------------------------------------------------------------------------- @@ -30,8 +35,18 @@ IMG_MAINTAINER='"Arnaud G. GIBERT" ' ENV_PORT_OFFSET=0 SV_PORT_OFFSET=1000 -DATABASE_PORT=$(( 8032 + ${ENV_PORT_OFFSET})) -DATABASE_SV_PORT=$(( ${DATABASE_PORT} + ${SV_PORT_OFFSET})) +DATABASE_PORT_MAIN_EXT=$(( 8032 + ${ENV_PORT_OFFSET})) +DATABASE_PORT_MAIN_INT=5432 + +DATABASE_PORT_SV_EXT=$(( ${DATABASE_PORT_MAIN_EXT} + ${SV_PORT_OFFSET})) +DATABASE_PORT_SV_INT=9001 + +DATABASE_LIB_DIR="/var/lib/pgsql" +DATABASE_DATA_DIR="${DATABASE_LIB_DIR}/data" +DATABASE_LOG_INIT_DIR="/var/log/init" +DATABASE_LOG_SV_DIR="/var/log/supervisor" +DATABASE_LOG_POSTGRES_DIR="/var/log/postgres" +DATABASE_LOG_POSTSQL_DIR="${DATABASE_LOG_SV_DIR}" POSTGRESQL_UID=971 POSTGRESQL_GID=971 diff --git a/var/log/init/.gitignore b/var/log/init/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/var/log/init/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/var/log/postgres/.gitignore b/var/log/postgres/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/var/log/postgres/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/var/log/supervisor/.gitignore b/var/log/supervisor/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/var/log/supervisor/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore