kopia lustrzana https://github.com/kartoza/docker-postgis
random password and add kartoza figlet
rodzic
fcac40b2ad
commit
b8ce200076
|
@ -20,7 +20,8 @@ RUN set -eux \
|
||||||
apt-transport-https curl gettext \
|
apt-transport-https curl gettext \
|
||||||
&& dpkg-divert --local --rename --add /sbin/initctl
|
&& dpkg-divert --local --rename --add /sbin/initctl
|
||||||
|
|
||||||
RUN apt-get -y update; apt-get -y install build-essential autoconf libxml2-dev zlib1g-dev netcat gdal-bin
|
RUN apt-get -y update; apt-get -y install build-essential autoconf libxml2-dev zlib1g-dev netcat gdal-bin \
|
||||||
|
figlet toilet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,13 @@ source /scripts/setup-ssl.sh
|
||||||
# Setup pg_hba.conf
|
# Setup pg_hba.conf
|
||||||
|
|
||||||
source /scripts/setup-pg_hba.sh
|
source /scripts/setup-pg_hba.sh
|
||||||
|
# Function to add figlet
|
||||||
|
advertise
|
||||||
|
figlet -t "Kartoza Docker PostGIS"
|
||||||
|
|
||||||
|
POSTGRES_PASS=$(cat /tmp/PGPASSWORD.txt)
|
||||||
|
echo -e "[Entrypoint] GENERATED Postgres PASSWORD: \e[1;31m $POSTGRES_PASS"
|
||||||
|
echo -e "\033[0m PGPASSWORD Generated above: "
|
||||||
|
|
||||||
if [[ -z "$REPLICATE_FROM" ]]; then
|
if [[ -z "$REPLICATE_FROM" ]]; then
|
||||||
# This means this is a master instance. We check that database exists
|
# This means this is a master instance. We check that database exists
|
||||||
|
@ -43,4 +50,5 @@ if [[ "${1:0:1}" = '-' ]]; then
|
||||||
set -- postgres "$@"
|
set -- postgres "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
exec su - "$@"
|
exec su - "$@"
|
||||||
|
|
|
@ -3,6 +3,7 @@ POSTGRES_MAJOR_VERSION=$(cat /tmp/pg_version.txt)
|
||||||
POSTGIS_MAJOR=$(cat /tmp/pg_major_version.txt)
|
POSTGIS_MAJOR=$(cat /tmp/pg_major_version.txt)
|
||||||
POSTGIS_MINOR_RELEASE=$(cat /tmp/pg_minor_version.txt)
|
POSTGIS_MINOR_RELEASE=$(cat /tmp/pg_minor_version.txt)
|
||||||
DEFAULT_DATADIR="/var/lib/postgresql/${POSTGRES_MAJOR_VERSION}/main"
|
DEFAULT_DATADIR="/var/lib/postgresql/${POSTGRES_MAJOR_VERSION}/main"
|
||||||
|
POSTGRES_INITDB_WALDIR="/opt/${POSTGRES_MAJOR_VERSION}/pg_waldir"
|
||||||
ROOT_CONF="/etc/postgresql/${POSTGRES_MAJOR_VERSION}/main"
|
ROOT_CONF="/etc/postgresql/${POSTGRES_MAJOR_VERSION}/main"
|
||||||
PG_ENV="$ROOT_CONF/environment"
|
PG_ENV="$ROOT_CONF/environment"
|
||||||
CONF="$ROOT_CONF/postgresql.conf"
|
CONF="$ROOT_CONF/postgresql.conf"
|
||||||
|
@ -67,13 +68,18 @@ then
|
||||||
mkdir -p ${DATA_PATH}
|
mkdir -p ${DATA_PATH}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [ -z "${POSTGRES_INITDB_WALDIR}" ]; then
|
||||||
|
POSTGRES_INITDB_WALDIR=${POSTGRES_INITDB_WALDIR}
|
||||||
|
fi
|
||||||
|
|
||||||
# Make sure we have a user set up
|
# Make sure we have a user set up
|
||||||
if [ -z "${POSTGRES_USER}" ]; then
|
if [ -z "${POSTGRES_USER}" ]; then
|
||||||
POSTGRES_USER=docker
|
POSTGRES_USER=docker
|
||||||
fi
|
fi
|
||||||
if [ -z "${POSTGRES_PASS}" ]; then
|
|
||||||
POSTGRES_PASS=docker
|
|
||||||
fi
|
|
||||||
if [ -z "${POSTGRES_DBNAME}" ]; then
|
if [ -z "${POSTGRES_DBNAME}" ]; then
|
||||||
POSTGRES_DBNAME=gis
|
POSTGRES_DBNAME=gis
|
||||||
fi
|
fi
|
||||||
|
@ -81,6 +87,7 @@ fi
|
||||||
if [ -z "${DATADIR}" ]; then
|
if [ -z "${DATADIR}" ]; then
|
||||||
DATADIR=${DEFAULT_DATADIR}
|
DATADIR=${DEFAULT_DATADIR}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# RECREATE_DATADIR flag default value
|
# RECREATE_DATADIR flag default value
|
||||||
# Always assume that we don't want to recreate datadir if not explicitly defined
|
# Always assume that we don't want to recreate datadir if not explicitly defined
|
||||||
# For issue: https://github.com/kartoza/docker-postgis/issues/226
|
# For issue: https://github.com/kartoza/docker-postgis/issues/226
|
||||||
|
@ -377,3 +384,23 @@ until su - postgres -c "${PG_BASEBACKUP} -X stream -h ${REPLICATE_FROM} -p ${REP
|
||||||
done
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pg_password() {
|
||||||
|
SETUP_LOCKFILE="${EXTRA_CONF_DIR}/.pass.lock"
|
||||||
|
if [ -z "${POSTGRES_PASS}" ] && [ ! -f ${SETUP_LOCKFILE} ]; then
|
||||||
|
POSTGRES_PASS=$(openssl rand -base64 15)
|
||||||
|
touch ${SETUP_LOCKFILE}
|
||||||
|
echo "$POSTGRES_PASS" >> /tmp/PGPASSWORD.txt
|
||||||
|
else
|
||||||
|
echo "$POSTGRES_PASS" >> /tmp/PGPASSWORD.txt
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function advertise() {
|
||||||
|
SETUP_LOCKFILE="${EXTRA_CONF_DIR}/.bash.lock"
|
||||||
|
if [[ ! -f ${SETUP_LOCKFILE} ]]; then
|
||||||
|
echo 'figlet -t "Kartoza Docker PostGIS"' >> ~/.bashrc
|
||||||
|
touch ${SETUP_LOCKFILE}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
source /scripts/env-data.sh
|
source /scripts/env-data.sh
|
||||||
|
|
||||||
|
POSTGRES_PASS=$(cat /tmp/PGPASSWORD.txt)
|
||||||
|
|
||||||
# test if DATADIR has content
|
# test if DATADIR has content
|
||||||
# Do initialization if DATADIR is empty, or RECREATE_DATADIR is true
|
# Do initialization if DATADIR is empty, or RECREATE_DATADIR is true
|
||||||
if [[ -z "$(ls -A ${DATADIR} 2> /dev/null)" || "${RECREATE_DATADIR}" == 'TRUE' ]]; then
|
if [[ -z "$(ls -A ${DATADIR} 2> /dev/null)" || "${RECREATE_DATADIR}" == 'TRUE' ]]; then
|
||||||
|
@ -9,14 +11,12 @@ if [[ -z "$(ls -A ${DATADIR} 2> /dev/null)" || "${RECREATE_DATADIR}" == 'TRUE' ]
|
||||||
# No Replicate From settings. Assume that this is a master database.
|
# No Replicate From settings. Assume that this is a master database.
|
||||||
# Initialise db
|
# Initialise db
|
||||||
echo "Initializing Postgres Database at ${DATADIR}"
|
echo "Initializing Postgres Database at ${DATADIR}"
|
||||||
create_dir ${DATADIR}
|
create_dir ${DATADIR} ${POSTGRES_INITDB_WALDIR}
|
||||||
rm -rf ${DATADIR}/*
|
rm -rf ${DATADIR}/*
|
||||||
chown -R postgres:postgres ${DATADIR}
|
chown -R postgres:postgres ${DATADIR} ${POSTGRES_INITDB_WALDIR}
|
||||||
echo "Initializing with command:"
|
echo "Initializing with command:"
|
||||||
echo "postgres" > /tmp/superuser_pass.txt
|
command="$INITDB -U postgres --pwfile=<(echo "$POSTGRES_PASS") -E ${DEFAULT_ENCODING} --lc-collate=${DEFAULT_COLLATION} --lc-ctype=${DEFAULT_CTYPE} --wal-segsize=${WAL_SEGSIZE} --auth=${PASSWORD_AUTHENTICATION} -D ${DATADIR} --waldir=${POSTGRES_INITDB_WALDIR} ${INITDB_EXTRA_ARGS}"
|
||||||
command="$INITDB -U postgres --pwfile "/tmp/superuser_pass.txt" -E ${DEFAULT_ENCODING} --lc-collate=${DEFAULT_COLLATION} --lc-ctype=${DEFAULT_CTYPE} --wal-segsize=${WAL_SEGSIZE} --auth=${PASSWORD_AUTHENTICATION} -D ${DATADIR} ${INITDB_EXTRA_ARGS}"
|
|
||||||
su - postgres -c "$command"
|
su - postgres -c "$command"
|
||||||
rm /tmp/superuser_pass.txt
|
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
# Set proper permissions
|
# Set proper permissions
|
||||||
|
|
|
@ -7,6 +7,9 @@ if [ -f "${SETUP_LOCKFILE}" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Setup Postgresql password
|
||||||
|
pg_password
|
||||||
|
|
||||||
# This script will setup pg_hba.conf
|
# This script will setup pg_hba.conf
|
||||||
|
|
||||||
# Reconfigure pg_hba if environment settings changed
|
# Reconfigure pg_hba if environment settings changed
|
||||||
|
|
|
@ -14,9 +14,9 @@ source /scripts/env-data.sh
|
||||||
|
|
||||||
# Only create credentials if this is a master database
|
# Only create credentials if this is a master database
|
||||||
# Slave database will just mirror from master users
|
# Slave database will just mirror from master users
|
||||||
echo "Setup postgres User:Password"
|
|
||||||
echo "postgresql user: $POSTGRES_USER" > /tmp/PGPASSWORD.txt
|
|
||||||
echo "postgresql password: $POSTGRES_PASS" >> /tmp/PGPASSWORD.txt
|
POSTGRES_PASS=$(cat /tmp/PGPASSWORD.txt)
|
||||||
|
|
||||||
# Check user already exists
|
# Check user already exists
|
||||||
echo "Creating superuser $POSTGRES_USER"
|
echo "Creating superuser $POSTGRES_USER"
|
||||||
|
|
Ładowanie…
Reference in New Issue