Skip to content

Commit 40cfe26

Browse files
committed
Merge pull request #36 from infosiftr/password
Add POSTGRES_PASSWORD and USER, with warning on no password
2 parents 5036e92 + 595fb37 commit 40cfe26

8 files changed

+239
-15
lines changed

Diff for: 8.4/docker-entrypoint.sh

+34-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,40 @@ if [ "$1" = 'postgres' ]; then
99

1010
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
1111

12-
{ echo; echo 'host all all 0.0.0.0/0 trust'; } >> "$PGDATA"/pg_hba.conf
13-
12+
# check password first so we can ouptut the warning before postgres
13+
# messes it up
14+
if [ "$POSTGRES_PASSWORD" ]; then
15+
pass="PASSWORD '$POSTGRES_PASSWORD'"
16+
authMethod=md5
17+
else
18+
# The - option suppresses leading tabs but *not* spaces. :)
19+
cat >&2 <<-'EOWARN'
20+
****************************************************
21+
WARNING: No password has been set for the database.
22+
Use "-e POSTGRES_PASSWORD=password" to set
23+
it in "docker run".
24+
****************************************************
25+
EOWARN
26+
27+
pass=
28+
authMethod=trust
29+
fi
30+
31+
: ${POSTGRES_USER:=postgres}
32+
if [ "$POSTGRES_USER" = 'postgres' ]; then
33+
op='ALTER'
34+
else
35+
op='CREATE'
36+
gosu postgres postgres --single -E <<-EOSQL
37+
CREATE DATABASE "$POSTGRES_USER"
38+
EOSQL
39+
fi
40+
41+
gosu postgres postgres --single <<-EOSQL
42+
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass
43+
EOSQL
44+
{ echo; echo "host all \"$POSTGRES_USER\" 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
45+
1446
if [ -d /docker-entrypoint-initdb.d ]; then
1547
for f in /docker-entrypoint-initdb.d/*.sh; do
1648
[ -f "$f" ] && . "$f"

Diff for: 9.0/docker-entrypoint.sh

+34-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,40 @@ if [ "$1" = 'postgres' ]; then
99

1010
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
1111

12-
{ echo; echo 'host all all 0.0.0.0/0 trust'; } >> "$PGDATA"/pg_hba.conf
13-
12+
# check password first so we can ouptut the warning before postgres
13+
# messes it up
14+
if [ "$POSTGRES_PASSWORD" ]; then
15+
pass="PASSWORD '$POSTGRES_PASSWORD'"
16+
authMethod=md5
17+
else
18+
# The - option suppresses leading tabs but *not* spaces. :)
19+
cat >&2 <<-'EOWARN'
20+
****************************************************
21+
WARNING: No password has been set for the database.
22+
Use "-e POSTGRES_PASSWORD=password" to set
23+
it in "docker run".
24+
****************************************************
25+
EOWARN
26+
27+
pass=
28+
authMethod=trust
29+
fi
30+
31+
: ${POSTGRES_USER:=postgres}
32+
if [ "$POSTGRES_USER" = 'postgres' ]; then
33+
op='ALTER'
34+
else
35+
op='CREATE'
36+
gosu postgres postgres --single -E <<-EOSQL
37+
CREATE DATABASE "$POSTGRES_USER"
38+
EOSQL
39+
fi
40+
41+
gosu postgres postgres --single <<-EOSQL
42+
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass
43+
EOSQL
44+
{ echo; echo "host all \"$POSTGRES_USER\" 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
45+
1446
if [ -d /docker-entrypoint-initdb.d ]; then
1547
for f in /docker-entrypoint-initdb.d/*.sh; do
1648
[ -f "$f" ] && . "$f"

Diff for: 9.1/docker-entrypoint.sh

+34-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,40 @@ if [ "$1" = 'postgres' ]; then
99

1010
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
1111

12-
{ echo; echo 'host all all 0.0.0.0/0 trust'; } >> "$PGDATA"/pg_hba.conf
13-
12+
# check password first so we can ouptut the warning before postgres
13+
# messes it up
14+
if [ "$POSTGRES_PASSWORD" ]; then
15+
pass="PASSWORD '$POSTGRES_PASSWORD'"
16+
authMethod=md5
17+
else
18+
# The - option suppresses leading tabs but *not* spaces. :)
19+
cat >&2 <<-'EOWARN'
20+
****************************************************
21+
WARNING: No password has been set for the database.
22+
Use "-e POSTGRES_PASSWORD=password" to set
23+
it in "docker run".
24+
****************************************************
25+
EOWARN
26+
27+
pass=
28+
authMethod=trust
29+
fi
30+
31+
: ${POSTGRES_USER:=postgres}
32+
if [ "$POSTGRES_USER" = 'postgres' ]; then
33+
op='ALTER'
34+
else
35+
op='CREATE'
36+
gosu postgres postgres --single -E <<-EOSQL
37+
CREATE DATABASE "$POSTGRES_USER"
38+
EOSQL
39+
fi
40+
41+
gosu postgres postgres --single <<-EOSQL
42+
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass
43+
EOSQL
44+
{ echo; echo "host all \"$POSTGRES_USER\" 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
45+
1446
if [ -d /docker-entrypoint-initdb.d ]; then
1547
for f in /docker-entrypoint-initdb.d/*.sh; do
1648
[ -f "$f" ] && . "$f"

Diff for: 9.2/docker-entrypoint.sh

+34-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,40 @@ if [ "$1" = 'postgres' ]; then
99

1010
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
1111

12-
{ echo; echo 'host all all 0.0.0.0/0 trust'; } >> "$PGDATA"/pg_hba.conf
13-
12+
# check password first so we can ouptut the warning before postgres
13+
# messes it up
14+
if [ "$POSTGRES_PASSWORD" ]; then
15+
pass="PASSWORD '$POSTGRES_PASSWORD'"
16+
authMethod=md5
17+
else
18+
# The - option suppresses leading tabs but *not* spaces. :)
19+
cat >&2 <<-'EOWARN'
20+
****************************************************
21+
WARNING: No password has been set for the database.
22+
Use "-e POSTGRES_PASSWORD=password" to set
23+
it in "docker run".
24+
****************************************************
25+
EOWARN
26+
27+
pass=
28+
authMethod=trust
29+
fi
30+
31+
: ${POSTGRES_USER:=postgres}
32+
if [ "$POSTGRES_USER" = 'postgres' ]; then
33+
op='ALTER'
34+
else
35+
op='CREATE'
36+
gosu postgres postgres --single -E <<-EOSQL
37+
CREATE DATABASE "$POSTGRES_USER"
38+
EOSQL
39+
fi
40+
41+
gosu postgres postgres --single <<-EOSQL
42+
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass
43+
EOSQL
44+
{ echo; echo "host all \"$POSTGRES_USER\" 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
45+
1446
if [ -d /docker-entrypoint-initdb.d ]; then
1547
for f in /docker-entrypoint-initdb.d/*.sh; do
1648
[ -f "$f" ] && . "$f"

Diff for: 9.3/docker-entrypoint.sh

+34-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,40 @@ if [ "$1" = 'postgres' ]; then
99

1010
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
1111

12-
{ echo; echo 'host all all 0.0.0.0/0 trust'; } >> "$PGDATA"/pg_hba.conf
13-
12+
# check password first so we can ouptut the warning before postgres
13+
# messes it up
14+
if [ "$POSTGRES_PASSWORD" ]; then
15+
pass="PASSWORD '$POSTGRES_PASSWORD'"
16+
authMethod=md5
17+
else
18+
# The - option suppresses leading tabs but *not* spaces. :)
19+
cat >&2 <<-'EOWARN'
20+
****************************************************
21+
WARNING: No password has been set for the database.
22+
Use "-e POSTGRES_PASSWORD=password" to set
23+
it in "docker run".
24+
****************************************************
25+
EOWARN
26+
27+
pass=
28+
authMethod=trust
29+
fi
30+
31+
: ${POSTGRES_USER:=postgres}
32+
if [ "$POSTGRES_USER" = 'postgres' ]; then
33+
op='ALTER'
34+
else
35+
op='CREATE'
36+
gosu postgres postgres --single -E <<-EOSQL
37+
CREATE DATABASE "$POSTGRES_USER"
38+
EOSQL
39+
fi
40+
41+
gosu postgres postgres --single <<-EOSQL
42+
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass
43+
EOSQL
44+
{ echo; echo "host all \"$POSTGRES_USER\" 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
45+
1446
if [ -d /docker-entrypoint-initdb.d ]; then
1547
for f in /docker-entrypoint-initdb.d/*.sh; do
1648
[ -f "$f" ] && . "$f"

Diff for: 9.4/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RUN mkdir /docker-entrypoint-initdb.d
2424
RUN apt-key adv --keyserver pgp.mit.edu --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
2525

2626
ENV PG_MAJOR 9.4
27-
ENV PG_VERSION 9.4~beta3-1.pgdg70+1
27+
ENV PG_VERSION 9.4~rc1-1.pgdg70+1
2828

2929
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
3030

Diff for: 9.4/docker-entrypoint.sh

+34-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,40 @@ if [ "$1" = 'postgres' ]; then
99

1010
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
1111

12-
{ echo; echo 'host all all 0.0.0.0/0 trust'; } >> "$PGDATA"/pg_hba.conf
13-
12+
# check password first so we can ouptut the warning before postgres
13+
# messes it up
14+
if [ "$POSTGRES_PASSWORD" ]; then
15+
pass="PASSWORD '$POSTGRES_PASSWORD'"
16+
authMethod=md5
17+
else
18+
# The - option suppresses leading tabs but *not* spaces. :)
19+
cat >&2 <<-'EOWARN'
20+
****************************************************
21+
WARNING: No password has been set for the database.
22+
Use "-e POSTGRES_PASSWORD=password" to set
23+
it in "docker run".
24+
****************************************************
25+
EOWARN
26+
27+
pass=
28+
authMethod=trust
29+
fi
30+
31+
: ${POSTGRES_USER:=postgres}
32+
if [ "$POSTGRES_USER" = 'postgres' ]; then
33+
op='ALTER'
34+
else
35+
op='CREATE'
36+
gosu postgres postgres --single -E <<-EOSQL
37+
CREATE DATABASE "$POSTGRES_USER"
38+
EOSQL
39+
fi
40+
41+
gosu postgres postgres --single <<-EOSQL
42+
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass
43+
EOSQL
44+
{ echo; echo "host all \"$POSTGRES_USER\" 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
45+
1446
if [ -d /docker-entrypoint-initdb.d ]; then
1547
for f in /docker-entrypoint-initdb.d/*.sh; do
1648
[ -f "$f" ] && . "$f"

Diff for: docker-entrypoint.sh

+34-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,40 @@ if [ "$1" = 'postgres' ]; then
99

1010
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
1111

12-
{ echo; echo 'host all all 0.0.0.0/0 trust'; } >> "$PGDATA"/pg_hba.conf
13-
12+
# check password first so we can ouptut the warning before postgres
13+
# messes it up
14+
if [ "$POSTGRES_PASSWORD" ]; then
15+
pass="PASSWORD '$POSTGRES_PASSWORD'"
16+
authMethod=md5
17+
else
18+
# The - option suppresses leading tabs but *not* spaces. :)
19+
cat >&2 <<-'EOWARN'
20+
****************************************************
21+
WARNING: No password has been set for the database.
22+
Use "-e POSTGRES_PASSWORD=password" to set
23+
it in "docker run".
24+
****************************************************
25+
EOWARN
26+
27+
pass=
28+
authMethod=trust
29+
fi
30+
31+
: ${POSTGRES_USER:=postgres}
32+
if [ "$POSTGRES_USER" = 'postgres' ]; then
33+
op='ALTER'
34+
else
35+
op='CREATE'
36+
gosu postgres postgres --single -E <<-EOSQL
37+
CREATE DATABASE "$POSTGRES_USER"
38+
EOSQL
39+
fi
40+
41+
gosu postgres postgres --single <<-EOSQL
42+
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass
43+
EOSQL
44+
{ echo; echo "host all \"$POSTGRES_USER\" 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
45+
1446
if [ -d /docker-entrypoint-initdb.d ]; then
1547
for f in /docker-entrypoint-initdb.d/*.sh; do
1648
[ -f "$f" ] && . "$f"

0 commit comments

Comments
 (0)