Skip to content

Commit 62ace3d

Browse files
author
mazano
authored
Merge pull request kartoza#313 from kartoza/fix-password
Fix password
2 parents 5b89078 + bee6939 commit 62ace3d

File tree

13 files changed

+79
-16
lines changed

13 files changed

+79
-16
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ RUN set -eux \
2020
apt-transport-https curl gettext \
2121
&& dpkg-divert --local --rename --add /sbin/initctl
2222

23-
RUN apt-get -y update; apt-get -y install build-essential autoconf libxml2-dev zlib1g-dev netcat gdal-bin
23+
RUN apt-get -y update; apt-get -y install build-essential autoconf libxml2-dev zlib1g-dev netcat gdal-bin \
24+
figlet toilet
2425

2526

2627

@@ -127,7 +128,7 @@ RUN chmod +x *.sh
127128
# this dockerfile directly.
128129
RUN set -eux \
129130
&& /scripts/setup.sh
130-
131+
RUN echo 'figlet -t "Kartoza Docker PostGIS"' >> ~/.bashrc
131132
VOLUME /var/lib/postgresql
132133

133134
ENTRYPOINT /scripts/docker-entrypoint.sh

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ To create a running container do:
307307
docker run --name "postgis" -p 25432:5432 -d -t kartoza/postgis
308308
```
309309

310+
**Note** If you do not pass the env variable `POSTGRES_PASS` a random password
311+
will be generated and will be visible from the logs or within the container in
312+
`/tmp/PGPASSWORD.txt`
313+
310314
## Convenience docker-compose.yml
311315

312316
For convenience, we provide a ``docker-compose.yml`` that will run a
@@ -506,6 +510,9 @@ replicant is read-only.
506510
docker run --name "streaming-replication" -e REPLICATION=true -e WAL_LEVEL='replica' -d -p 25432:5432 kartoza/postgis:13.0
507511
```
508512

513+
**Note** If you do not pass the env variable `REPLICATION_PASS` a random password
514+
will be generated and will be visible from the logs or within the container in
515+
`/tmp/REPLPASSWORD.txt`
509516

510517
![qgis](https://user-images.githubusercontent.com/178003/37755610-dd3b774a-2dae-11e8-9fa1-4877e2034675.gif)
511518

scenario_tests/collations/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ services:
2020
DEFAULT_CTYPE: ${DEFAULT_COLLATION:-id_ID.utf8}
2121
ALLOW_IP_RANGE: '0.0.0.0/0'
2222
TEST_CLASS: test_collation.TestCollationDefault
23+
POSTGRES_PASS: 'docker'
2324
ports:
2425
- "7777:5432"
2526
healthcheck:
@@ -45,6 +46,7 @@ services:
4546
DEFAULT_CTYPE: ${DEFAULT_COLLATION:-id_ID.utf8}
4647
ALLOW_IP_RANGE: '0.0.0.0/0'
4748
TEST_CLASS: test_collation.TestCollationInitialization
49+
POSTGRES_PASS: 'docker'
4850
ports:
4951
- "7776:5432"
5052
healthcheck:

scenario_tests/datadir_init/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
environment:
1515
# Default usage, no datadir location defined
1616
TEST_CLASS: TestDefault
17+
POSTGRES_PASS: 'docker'
1718
healthcheck:
1819
interval: 60s
1920
timeout: 30s
@@ -31,6 +32,7 @@ services:
3132
# Tell the new location
3233
TEST_CLASS: TestNew
3334
DATADIR: /opt/mypostgis/data
35+
POSTGRES_PASS: 'docker'
3436
healthcheck:
3537
interval: 60s
3638
timeout: 30s
@@ -50,6 +52,7 @@ services:
5052
DEFAULT_ENCODING: ${DEFAULT_ENCODING:-UTF-8}
5153
DEFAULT_COLLATION: ${DEFAULT_COLLATION:-id_ID.utf8}
5254
DEFAULT_CTYPE: ${DEFAULT_COLLATION:-id_ID.utf8}
55+
POSTGRES_PASS: 'docker'
5356
healthcheck:
5457
interval: 60s
5558
timeout: 30s

scenario_tests/extensions/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
environment:
1414
ALLOW_IP_RANGE: '0.0.0.0/0'
1515
TEST_CLASS: test_extensions.TestExtensions
16+
POSTGRES_PASS: 'docker'
1617
ports:
1718
- "7777:5432"
1819
healthcheck:
@@ -33,6 +34,7 @@ services:
3334
ALLOW_IP_RANGE: '0.0.0.0/0'
3435
TEST_CLASS: test_extensions.TestExtensions
3536
POSTGRES_MULTIPLE_EXTENSIONS: postgis,pgrouting
37+
POSTGRES_PASS: 'docker'
3638
ports:
3739
- "7776:5432"
3840
healthcheck:

scenario_tests/logical_replication/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ services:
1717
- ../utils:/lib/utils
1818
environment:
1919
ALLOW_IP_RANGE: '0.0.0.0/0'
20+
POSTGRES_PASS: 'docker'
2021
REPLICATION_USER: 'replicator'
2122
REPLICATION_PASS: 'replicator'
2223
REPLICATION: 'true'
@@ -43,6 +44,7 @@ services:
4344
environment:
4445
ALLOW_IP_RANGE: '0.0.0.0/0'
4546
WAL_LEVEL: 'logical'
47+
POSTGRES_PASS: 'docker'
4648
REPLICATION_USER: 'replicator'
4749
REPLICATION_PASS: 'replicator'
4850
REPLICATION: 'true'

scenario_tests/streaming_replication/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ services:
2222
ALLOW_IP_RANGE: '0.0.0.0/0'
2323

2424
# We can specify optional credentials
25+
POSTGRES_PASS: 'docker'
2526
REPLICATION_USER: 'replicator'
2627
REPLICATION_PASS: 'replicator'
2728
REPLICATION: 'true'
@@ -61,6 +62,7 @@ services:
6162
# REPLICATE_FROM options accepts domain-name or IP address
6263
# with this in mind, you can also put docker service name, because it
6364
# will be resolved as host name.
65+
POSTGRES_PASS: 'docker'
6466
REPLICATE_FROM: 'pg-master'
6567
REPLICATION: 'true'
6668

scripts/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ source /scripts/setup-ssl.sh
1414
# Setup pg_hba.conf
1515

1616
source /scripts/setup-pg_hba.sh
17+
# Function to add figlet
18+
figlet -t "Kartoza Docker PostGIS"
19+
20+
POSTGRES_PASS=$(cat /tmp/PGPASSWORD.txt)
21+
echo -e "[Entrypoint] GENERATED Postgres PASSWORD: \e[1;31m $POSTGRES_PASS"
22+
echo -e "\033[0m PGPASSWORD Generated above: "
1723

1824
if [[ -z "$REPLICATE_FROM" ]]; then
1925
# This means this is a master instance. We check that database exists
@@ -43,4 +49,5 @@ if [[ "${1:0:1}" = '-' ]]; then
4349
set -- postgres "$@"
4450
fi
4551

52+
4653
exec su - "$@"

scripts/env-data.sh

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ POSTGRES_MAJOR_VERSION=$(cat /tmp/pg_version.txt)
33
POSTGIS_MAJOR=$(cat /tmp/pg_major_version.txt)
44
POSTGIS_MINOR_RELEASE=$(cat /tmp/pg_minor_version.txt)
55
DEFAULT_DATADIR="/var/lib/postgresql/${POSTGRES_MAJOR_VERSION}/main"
6+
POSTGRES_INITDB_WALDIR="/opt/postgresql/${POSTGRES_MAJOR_VERSION}/pg_waldir"
67
ROOT_CONF="/etc/postgresql/${POSTGRES_MAJOR_VERSION}/main"
78
PG_ENV="$ROOT_CONF/environment"
89
CONF="$ROOT_CONF/postgresql.conf"
@@ -19,6 +20,7 @@ PGSTAT_TMP="/var/run/postgresql/"
1920
PG_PID="/var/run/postgresql/${POSTGRES_MAJOR_VERSION}-main.pid"
2021

2122

23+
2224
# Read data from secrets into env variables.
2325

2426
# usage: file_env VAR [DEFAULT]
@@ -67,20 +69,26 @@ then
6769
mkdir -p ${DATA_PATH}
6870
fi
6971
}
72+
73+
74+
if [ -z "${POSTGRES_INITDB_WALDIR}" ]; then
75+
POSTGRES_INITDB_WALDIR=${POSTGRES_INITDB_WALDIR}
76+
fi
77+
7078
# Make sure we have a user set up
7179
if [ -z "${POSTGRES_USER}" ]; then
7280
POSTGRES_USER=docker
7381
fi
74-
if [ -z "${POSTGRES_PASS}" ]; then
75-
POSTGRES_PASS=docker
76-
fi
82+
83+
7784
if [ -z "${POSTGRES_DBNAME}" ]; then
7885
POSTGRES_DBNAME=gis
7986
fi
8087
# If datadir is not defined, then use this
8188
if [ -z "${DATADIR}" ]; then
8289
DATADIR=${DEFAULT_DATADIR}
8390
fi
91+
8492
# RECREATE_DATADIR flag default value
8593
# Always assume that we don't want to recreate datadir if not explicitly defined
8694
# For issue: https://github.com/kartoza/docker-postgis/issues/226
@@ -245,10 +253,6 @@ if [ -z "${REPLICATION_USER}" ]; then
245253
REPLICATION_USER=replicator
246254
fi
247255

248-
if [ -z "${REPLICATION_PASS}" ]; then
249-
REPLICATION_PASS=replicator
250-
fi
251-
252256

253257
if [ -z "$IGNORE_INIT_HOOK_LOCKFILE" ]; then
254258
IGNORE_INIT_HOOK_LOCKFILE=false
@@ -377,3 +381,28 @@ until su - postgres -c "${PG_BASEBACKUP} -X stream -h ${REPLICATE_FROM} -p ${REP
377381
done
378382

379383
}
384+
385+
function pg_password() {
386+
SETUP_LOCKFILE="/settings/.pgpasspass.lock"
387+
if [ -z "${POSTGRES_PASS}" ] && [ ! -f ${SETUP_LOCKFILE} ]; then
388+
POSTGRES_PASS=$(openssl rand -base64 15)
389+
touch ${SETUP_LOCKFILE}
390+
echo "$POSTGRES_PASS" >> /tmp/PGPASSWORD.txt
391+
else
392+
echo "$POSTGRES_PASS" >> /tmp/PGPASSWORD.txt
393+
fi
394+
395+
}
396+
397+
function replication_password() {
398+
SETUP_LOCKFILE="/settings/.replicationpass.lock"
399+
if [ -z "${REPLICATION_PASS}" ] && [ ! -f ${SETUP_LOCKFILE} ]; then
400+
REPLICATION_PASS=$(openssl rand -base64 15)
401+
touch ${SETUP_LOCKFILE}
402+
echo "$REPLICATION_PASS" >> /tmp/REPLPASSWORD.txt
403+
else
404+
echo "$REPLICATION_PASS" >> /tmp/REPLPASSWORD.txt
405+
fi
406+
407+
}
408+

scripts/setup-conf.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
source /scripts/env-data.sh
44

55
SETUP_LOCKFILE="${ROOT_CONF}/.postgresql.conf.lock"
6+
create_dir /settings
67
if [ -f "${SETUP_LOCKFILE}" ]; then
78
return 0
89
fi

0 commit comments

Comments
 (0)