Skip to content

Commit 28b8bd7

Browse files
committed
Merge pull request docker-library#72 from bakavic/fix-gce
Check that vol actually contains DB files, as opposed to a non-empty dir.
2 parents 403dc53 + 9c7bb73 commit 28b8bd7

7 files changed

+105
-91
lines changed

9.0/docker-entrypoint.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
set -e
33

44
if [ "$1" = 'postgres' ]; then
5+
mkdir -p "$PGDATA"
56
chown -R postgres "$PGDATA"
6-
7+
78
chmod g+s /run/postgresql
89
chown -R postgres:postgres /run/postgresql
9-
10-
if [ -z "$(ls -A "$PGDATA")" ]; then
10+
11+
# look specifically for PG_VERSION, as it is expected in the DB dir
12+
if [ -s "$PGDATA/PG_VERSION" ]; then
1113
gosu postgres initdb
12-
14+
1315
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
14-
15-
# check password first so we can ouptut the warning before postgres
16+
17+
# check password first so we can output the warning before postgres
1618
# messes it up
1719
if [ "$POSTGRES_PASSWORD" ]; then
1820
pass="PASSWORD '$POSTGRES_PASSWORD'"
@@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
2729
Docker's default configuration, this is
2830
effectively any other container on the same
2931
system.
30-
32+
3133
Use "-e POSTGRES_PASSWORD=password" to set
3234
it in "docker run".
3335
****************************************************
3436
EOWARN
35-
37+
3638
pass=
3739
authMethod=trust
3840
fi
39-
41+
4042
: ${POSTGRES_USER:=postgres}
4143
: ${POSTGRES_DB:=$POSTGRES_USER}
4244

@@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
4648
EOSQL
4749
echo
4850
fi
49-
51+
5052
if [ "$POSTGRES_USER" = 'postgres' ]; then
5153
op='ALTER'
5254
else
@@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
5759
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
5860
EOSQL
5961
echo
60-
62+
6163
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
62-
64+
6365
if [ -d /docker-entrypoint-initdb.d ]; then
6466
for f in /docker-entrypoint-initdb.d/*.sh; do
6567
[ -f "$f" ] && . "$f"
6668
done
6769
fi
6870
fi
69-
71+
7072
exec gosu postgres "$@"
7173
fi
7274

9.1/docker-entrypoint.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
set -e
33

44
if [ "$1" = 'postgres' ]; then
5+
mkdir -p "$PGDATA"
56
chown -R postgres "$PGDATA"
6-
7+
78
chmod g+s /run/postgresql
89
chown -R postgres:postgres /run/postgresql
9-
10-
if [ -z "$(ls -A "$PGDATA")" ]; then
10+
11+
# look specifically for PG_VERSION, as it is expected in the DB dir
12+
if [ -s "$PGDATA/PG_VERSION" ]; then
1113
gosu postgres initdb
12-
14+
1315
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
14-
15-
# check password first so we can ouptut the warning before postgres
16+
17+
# check password first so we can output the warning before postgres
1618
# messes it up
1719
if [ "$POSTGRES_PASSWORD" ]; then
1820
pass="PASSWORD '$POSTGRES_PASSWORD'"
@@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
2729
Docker's default configuration, this is
2830
effectively any other container on the same
2931
system.
30-
32+
3133
Use "-e POSTGRES_PASSWORD=password" to set
3234
it in "docker run".
3335
****************************************************
3436
EOWARN
35-
37+
3638
pass=
3739
authMethod=trust
3840
fi
39-
41+
4042
: ${POSTGRES_USER:=postgres}
4143
: ${POSTGRES_DB:=$POSTGRES_USER}
4244

@@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
4648
EOSQL
4749
echo
4850
fi
49-
51+
5052
if [ "$POSTGRES_USER" = 'postgres' ]; then
5153
op='ALTER'
5254
else
@@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
5759
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
5860
EOSQL
5961
echo
60-
62+
6163
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
62-
64+
6365
if [ -d /docker-entrypoint-initdb.d ]; then
6466
for f in /docker-entrypoint-initdb.d/*.sh; do
6567
[ -f "$f" ] && . "$f"
6668
done
6769
fi
6870
fi
69-
71+
7072
exec gosu postgres "$@"
7173
fi
7274

9.2/docker-entrypoint.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
set -e
33

44
if [ "$1" = 'postgres' ]; then
5+
mkdir -p "$PGDATA"
56
chown -R postgres "$PGDATA"
6-
7+
78
chmod g+s /run/postgresql
89
chown -R postgres:postgres /run/postgresql
9-
10-
if [ -z "$(ls -A "$PGDATA")" ]; then
10+
11+
# look specifically for PG_VERSION, as it is expected in the DB dir
12+
if [ -s "$PGDATA/PG_VERSION" ]; then
1113
gosu postgres initdb
12-
14+
1315
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
14-
15-
# check password first so we can ouptut the warning before postgres
16+
17+
# check password first so we can output the warning before postgres
1618
# messes it up
1719
if [ "$POSTGRES_PASSWORD" ]; then
1820
pass="PASSWORD '$POSTGRES_PASSWORD'"
@@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
2729
Docker's default configuration, this is
2830
effectively any other container on the same
2931
system.
30-
32+
3133
Use "-e POSTGRES_PASSWORD=password" to set
3234
it in "docker run".
3335
****************************************************
3436
EOWARN
35-
37+
3638
pass=
3739
authMethod=trust
3840
fi
39-
41+
4042
: ${POSTGRES_USER:=postgres}
4143
: ${POSTGRES_DB:=$POSTGRES_USER}
4244

@@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
4648
EOSQL
4749
echo
4850
fi
49-
51+
5052
if [ "$POSTGRES_USER" = 'postgres' ]; then
5153
op='ALTER'
5254
else
@@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
5759
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
5860
EOSQL
5961
echo
60-
62+
6163
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
62-
64+
6365
if [ -d /docker-entrypoint-initdb.d ]; then
6466
for f in /docker-entrypoint-initdb.d/*.sh; do
6567
[ -f "$f" ] && . "$f"
6668
done
6769
fi
6870
fi
69-
71+
7072
exec gosu postgres "$@"
7173
fi
7274

9.3/docker-entrypoint.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
set -e
33

44
if [ "$1" = 'postgres' ]; then
5+
mkdir -p "$PGDATA"
56
chown -R postgres "$PGDATA"
6-
7+
78
chmod g+s /run/postgresql
89
chown -R postgres:postgres /run/postgresql
9-
10-
if [ -z "$(ls -A "$PGDATA")" ]; then
10+
11+
# look specifically for PG_VERSION, as it is expected in the DB dir
12+
if [ -s "$PGDATA/PG_VERSION" ]; then
1113
gosu postgres initdb
12-
14+
1315
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
14-
15-
# check password first so we can ouptut the warning before postgres
16+
17+
# check password first so we can output the warning before postgres
1618
# messes it up
1719
if [ "$POSTGRES_PASSWORD" ]; then
1820
pass="PASSWORD '$POSTGRES_PASSWORD'"
@@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
2729
Docker's default configuration, this is
2830
effectively any other container on the same
2931
system.
30-
32+
3133
Use "-e POSTGRES_PASSWORD=password" to set
3234
it in "docker run".
3335
****************************************************
3436
EOWARN
35-
37+
3638
pass=
3739
authMethod=trust
3840
fi
39-
41+
4042
: ${POSTGRES_USER:=postgres}
4143
: ${POSTGRES_DB:=$POSTGRES_USER}
4244

@@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
4648
EOSQL
4749
echo
4850
fi
49-
51+
5052
if [ "$POSTGRES_USER" = 'postgres' ]; then
5153
op='ALTER'
5254
else
@@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
5759
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
5860
EOSQL
5961
echo
60-
62+
6163
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
62-
64+
6365
if [ -d /docker-entrypoint-initdb.d ]; then
6466
for f in /docker-entrypoint-initdb.d/*.sh; do
6567
[ -f "$f" ] && . "$f"
6668
done
6769
fi
6870
fi
69-
71+
7072
exec gosu postgres "$@"
7173
fi
7274

9.4/docker-entrypoint.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
set -e
33

44
if [ "$1" = 'postgres' ]; then
5+
mkdir -p "$PGDATA"
56
chown -R postgres "$PGDATA"
6-
7+
78
chmod g+s /run/postgresql
89
chown -R postgres:postgres /run/postgresql
9-
10-
if [ -z "$(ls -A "$PGDATA")" ]; then
10+
11+
# look specifically for PG_VERSION, as it is expected in the DB dir
12+
if [ -s "$PGDATA/PG_VERSION" ]; then
1113
gosu postgres initdb
12-
14+
1315
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
14-
15-
# check password first so we can ouptut the warning before postgres
16+
17+
# check password first so we can output the warning before postgres
1618
# messes it up
1719
if [ "$POSTGRES_PASSWORD" ]; then
1820
pass="PASSWORD '$POSTGRES_PASSWORD'"
@@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
2729
Docker's default configuration, this is
2830
effectively any other container on the same
2931
system.
30-
32+
3133
Use "-e POSTGRES_PASSWORD=password" to set
3234
it in "docker run".
3335
****************************************************
3436
EOWARN
35-
37+
3638
pass=
3739
authMethod=trust
3840
fi
39-
41+
4042
: ${POSTGRES_USER:=postgres}
4143
: ${POSTGRES_DB:=$POSTGRES_USER}
4244

@@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
4648
EOSQL
4749
echo
4850
fi
49-
51+
5052
if [ "$POSTGRES_USER" = 'postgres' ]; then
5153
op='ALTER'
5254
else
@@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
5759
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
5860
EOSQL
5961
echo
60-
62+
6163
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
62-
64+
6365
if [ -d /docker-entrypoint-initdb.d ]; then
6466
for f in /docker-entrypoint-initdb.d/*.sh; do
6567
[ -f "$f" ] && . "$f"
6668
done
6769
fi
6870
fi
69-
71+
7072
exec gosu postgres "$@"
7173
fi
7274

0 commit comments

Comments
 (0)