2024-11-12 17:02:53 +01:00
|
|
|
# Rx3-Docker/PosgreSQL Docker Image
|
2024-08-30 19:08:09 +02:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
2024-11-12 17:02:53 +01:00
|
|
|
ARG IMG_FROM_URL="rx3-docker/server:latest"
|
2024-08-30 19:08:09 +02:00
|
|
|
|
2024-11-12 17:02:53 +01:00
|
|
|
FROM ${IMG_FROM_URL}
|
2024-08-30 19:08:09 +02:00
|
|
|
|
|
|
|
ARG IMG_NAME
|
2024-11-12 17:02:53 +01:00
|
|
|
ARG IMG_NAME_FULL
|
2024-08-30 19:08:09 +02:00
|
|
|
ARG IMG_VERSION
|
|
|
|
ARG IMG_MAINTAINER
|
|
|
|
|
2024-11-12 17:02:53 +01:00
|
|
|
LABEL org.rx3.${IMG_NAME}.name=${IMG_NAME_FULL}
|
2024-08-30 19:08:09 +02:00
|
|
|
LABEL org.rx3.${IMG_NAME}.version=${IMG_VERSION}
|
|
|
|
LABEL org.rx3.${IMG_NAME}.maintainer=${IMG_MAINTAINER}
|
|
|
|
LABEL maintainer=${IMG_MAINTAINER}
|
|
|
|
|
2024-11-12 17:02:53 +01:00
|
|
|
ARG POSTGRESQL_LIB
|
|
|
|
ARG POSTGRESQL_DATA
|
|
|
|
ARG POSTGRESQL_PORT
|
|
|
|
ARG POSTSQL_LOG_DIR
|
|
|
|
|
|
|
|
ARG POSTSQL_LOG_FILE="${POSTSQL_LOG_DIR}/postsql.log"
|
|
|
|
|
|
|
|
|
2024-08-30 19:08:09 +02:00
|
|
|
|
2024-08-31 12:26:19 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
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\
|
2024-08-30 19:08:09 +02:00
|
|
|
fi'
|
2024-11-12 17:02:53 +01:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------------
|
2024-08-30 19:08:09 +02:00
|
|
|
|
2024-11-12 17:02:53 +01:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
ARG POSTGRESQLD_INI='[program:postgresqld] \n\
|
|
|
|
command=/usr/bin/postgres -D '${POSTGRESQL_DATA}' -p '${POSTGRESQL_PORT}' \n\
|
2024-08-30 19:08:09 +02:00
|
|
|
user=postgres'
|
2024-11-12 17:02:53 +01:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
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\
|
2024-08-30 19:08:09 +02:00
|
|
|
log "Completed"'
|
2024-11-12 17:02:53 +01:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------------
|
2024-08-30 19:08:09 +02:00
|
|
|
|
2024-11-12 17:02:53 +01:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
ARG POSTSQL_INI='[program:postsql] \n\
|
2024-08-30 19:08:09 +02:00
|
|
|
command=/usr/local/sbin/postsql'
|
2024-11-12 17:02:53 +01:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------------
|
2024-08-30 19:08:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-12 17:02:53 +01:00
|
|
|
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
|
2024-08-30 19:08:09 +02:00
|
|
|
|
|
|
|
|
2024-11-12 17:02:53 +01:00
|
|
|
VOLUME ${POSTGRESQL_LIB}
|
2024-08-30 19:08:09 +02:00
|
|
|
|
|
|
|
EXPOSE 5432
|