From 234c8ce21811a1a76d14ee1e813d4cebf4c3890c Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Fri, 30 Aug 2024 19:08:09 +0200 Subject: [PATCH] - Initial release, - Based on server-mga9:1.1.2 image. --- .env | 35 +++++++++++++++ .gitignore | 2 + Dockerfile | 114 +++++++++++++++++++++++++++++++++++++++++++++++ ReadMe.txt | 22 +++++++++ ReleaseNotes.txt | 6 +++ compose.yaml | 39 ++++++++++++++++ 6 files changed, 218 insertions(+) create mode 100644 .env create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 ReadMe.txt create mode 100644 ReleaseNotes.txt create mode 100644 compose.yaml diff --git a/.env b/.env new file mode 100644 index 0000000..cab1026 --- /dev/null +++ b/.env @@ -0,0 +1,35 @@ +# Rx3 PostgreSQL Mageia-9 Docker Image +#------------------------------------------------------------------------------- + +#------------------------------------------------------------------------------- +# Global Settings +#------------------------------------------------------------------------------- + +IMG_ORG="rx3" +IMG_REGISTRY="docker.xor.rx3:5000" +IMG_URL_PREFIX="${IMG_REGISTRY}/${IMG_ORG}" + + + +#------------------------------------------------------------------------------- +# Image Settings +#------------------------------------------------------------------------------- + +IMG_NAME="postgresql-mga9" +IMG_FULL_NAME="Rx3 MariaDB Mageia-9 Docker Image" +IMG_VERSION="1.0.0" +IMG_URL="${IMG_URL_PREFIX}/${IMG_NAME}:${IMG_VERSION}" +IMG_MAINTAINER='"Arnaud G. GIBERT" ' + + + +#------------------------------------------------------------------------------- +# User Settings +#------------------------------------------------------------------------------- + +POSTGRESQL_UID=971 +POSTGRESQL_GID=971 +POSTGRESQL_POSTGRES_PASSWORD="postgresadmin" +POSTGRESQL_DATABASE="test" +POSTGRESQL_USER="test" +POSTGRESQL_PASSWORD="testadmin" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..556bc65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +*.old diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4d7f555 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,114 @@ +# Rx3 PosgreSQL Mageia-9 Docker Image +#------------------------------------------------------------------------------- + +ARG IMG_URL_PREFIX="rx3" + +FROM ${IMG_URL_PREFIX}/server-mga9:1.1.2 + +ARG IMG_NAME +ARG IMG_FULL_NAME +ARG IMG_VERSION +ARG IMG_MAINTAINER + +LABEL org.rx3.${IMG_NAME}.name=${IMG_FULL_NAME} +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 POSTGRESQLD='#!/bin/bash \n\ + \n\ +usermod -u ${POSTGRESQL_UID} postgres \n\ +groupmod -g ${POSTGRESQL_GID} postgres \n\ + \n\ +chown -R postgres:postgres '${POSTGRESQL_LIB}' /var/log/postgres /var/run/postgresql \n\ + \n\ +if [[ ! -f '${POSTGRESQL_DATA}/pg_hba.conf' ]] \n\ +then \n\ + echo "ALTER USER postgres WITH PASSWORD `${POSTGRESQL_POSTGRES_PASSWORD}`;" >>/tmp/post.sql \n\ + \n\ + if [[ -n "${POSTGRESQL_DATABASE}" ]] \n\ + then \n\ + echo "CREATE DATABASE ${POSTGRESQL_DATABASE};" >>/tmp/post.sql \n\ + fi \n\ + \n\ + if [[ -n "${POSTGRESQL_USER}" ]] && [[ -n "${POSTGRESQL_PASSWORD}" ]] \n\ + then \n\ + echo "CREATE USER ${POSTGRESQL_USER} WITH PASSWORD `${POSTGRESQL_PASSWORD}`;" >>/tmp/post.sql \n\ + \n\ + if [[ -n "${POSTGRESQL_DATABASE}" ]] \n\ + then \n\ + echo "GRANT ALL PRIVILEGES ON DATABASE ${POSTGRESQL_DATABASE} TO ${POSTGRESQL_USER};" >>/tmp/post.sql \n\ + fi \n\ + fi \n\ + \n\ + su - postgres -c "/usr/libexec/postgresql_initdb.sh '${POSTGRESQL_DATA}'" \n\ + \n\ + echo "# IPv4 extern connections:" >>'${POSTGRESQL_DATA}'/pg_hba.conf \n\ + 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' +#--------------------------------------------------------------------------------------------------- + +#command=/usr/bin/pg_ctl start -D '${POSTGRESQL_DATA}' -s -o "-p '${POSTGRESQL_PORT}'" -w -t 300 \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\ +log "Completed"' +#--------------------------------------------------------------------------------------------------- + +#--------------------------------------------------------------------------------------------------- +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 + + +VOLUME /var/lib/pgsql + +EXPOSE 5432 diff --git a/ReadMe.txt b/ReadMe.txt new file mode 100644 index 0000000..9eedd60 --- /dev/null +++ b/ReadMe.txt @@ -0,0 +1,22 @@ +Welcome to Rx3/PostgreSQL-Mga9 docker image! + + + +This is project aims to build a PostgreSQL + Mageia 9 docker image used by others Rx3 packaging projects. + +Features: + - Curtently based on rx3/server-mga9:1.1.2 image, + - Following env vars supported: + - POSTGRESQL_UID & POSTGRESQL_GID, + - POSTGRESQL_POSTGRES_PASSWORD, + - POSTGRESQL_DATABASE, + - POSTGRESQL_USER & POSTGRESQL_PASSWORD. + + +Enjoy it! + +Your Rx3 Team. + +-- +arnaud@rx3.net +https://git.rx3.org/gitea/rx3/postgresql-mga9 diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt new file mode 100644 index 0000000..e19f17d --- /dev/null +++ b/ReleaseNotes.txt @@ -0,0 +1,6 @@ +------------------------------------------------------------------------------------------------------------------------------------ +Rx3/PostgreSQL-Mga9 V 1.0.0 - A. GIBERT - 2024/08/30 +------------------------------------------------------------------------------------------------------------------------------------ + +- Initial release, +- Based on server-mga9:1.1.2 image. diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..2ca8917 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,39 @@ +# Rx3 PostgreSQL Mageia-9 Docker Image +#------------------------------------------------------------------------------- + +name: ${IMG_NAME} + +services: + + database: + container_name: ${IMG_NAME} + + image: ${IMG_URL} + + build: + 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} + + restart: unless-stopped + + environment: + POSTGRESQL_UID: ${POSTGRESQL_UID} + POSTGRESQL_GID: ${POSTGRESQL_GID} + POSTGRESQL_POSTGRES_PASSWORD: ${POSTGRESQL_POSTGRES_PASSWORD} + POSTGRESQL_DATABASE: ${POSTGRESQL_DATABASE} + POSTGRESQL_USER: ${POSTGRESQL_USER} + POSTGRESQL_PASSWORD: ${POSTGRESQL_PASSWORD} + + volumes: + - ./pgsql/data:/var/lib/pgsql/data + + network_mode: bridge + + ports: + - "127.0.0.1:9013:9001" + - "127.0.0.1:8032:5432"