File tree Expand file tree Collapse file tree 4 files changed +64
-1
lines changed Expand file tree Collapse file tree 4 files changed +64
-1
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,16 @@ USER 70:70
59
59
60
60
COPY --from=extracted_bundle /bundle/docker-entrypoint-initdb.d/definitions.sql.gz /docker-entrypoint-initdb.d/
61
61
62
- ENTRYPOINT ["docker-entrypoint.sh" ]
62
+ COPY scripts/custom-entrypoint.sh /usr/local/bin/
63
+ COPY scripts/start-db.sh /usr/local/bin/
64
+
65
+ RUN /usr/local/bin/start-db.sh
66
+ USER root
67
+ RUN rm -rf /usr/local/bin/start-db.sh && \
68
+ rm -rf /docker-entrypoint-initdb.d/definitions.sql
69
+ USER 70:70
70
+ ENV DATABASE_ALREADY_EXISTS=true
71
+ ENTRYPOINT ["custom-entrypoint.sh" ]
63
72
64
73
EXPOSE 5432
65
74
CMD ["postgres" , "-c" , "config_file=/etc/postgresql.conf" ]
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ # The postgres server has been started once during the build process in the Dockerfile.
4
+ # Now we need to start it again, but this time with the correct password.
5
+ # So we need to issue a command to change the password.
6
+
7
+ set -e
8
+
9
+ echo " Starting database..."
10
+ POSTGRES_PASSWORD=postgres /usr/local/bin/docker-entrypoint.sh postgres -c config_file=/etc/postgresql.conf &
11
+
12
+ echo " Waiting for database to be ready..."
13
+ while ! pg_isready -U postgres -h localhost -p 5432; do
14
+ sleep 1
15
+ done
16
+
17
+ echo " Changing password..."
18
+ if [ " $POSTGRES_PASSWORD " != " postgres" ]; then
19
+ PGPASSWORD=postgres psql -c " ALTER USER postgres WITH PASSWORD '$POSTGRES_PASSWORD ';"
20
+ fi
21
+
22
+ echo " Renaming postgres user if necessary..."
23
+ if [ " $POSTGRES_USER " != " postgres" ]; then
24
+ PGPASSWORD=" $POSTGRES_PASSWORD " psql -c " ALTER USER postgres RENAME TO $POSTGRES_USER ;"
25
+ fi
26
+
27
+ echo " Stopping database..."
28
+ pg_ctl -D /var/lib/postgresql/data/pgdata -w stop
29
+
30
+ # Now we can start the database for real. But we will
31
+ # forward any arguments to the actual entrypoint script
32
+ echo " Starting database for real..."
33
+
34
+ exec /usr/local/bin/docker-entrypoint.sh " $@ "
Original file line number Diff line number Diff line change 6
6
# ##
7
7
# ## [1]: https://github.com/docker-library/postgres/blob/master/12/bullseye/docker-entrypoint.sh
8
8
9
+ if [ -n " $ROX_SCANNER_DB_INIT " ]; then
10
+ exit 0
11
+ fi
12
+
9
13
set -Eeo pipefail
10
14
# TODO swap to -Eeuo pipefail above (after handling all potentially-unset variables)
11
15
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ set -eu
4
+
5
+ echo " Creating postgres.conf for initialization..."
6
+ cat << EOF > /tmp/postgres.conf
7
+ listen_addresses = '*'
8
+ EOF
9
+
10
+ echo " Starting database..."
11
+ POSTGRES_PASSWORD=postgres /usr/local/bin/docker-entrypoint.sh postgres -c config_file=/tmp/postgres.conf
12
+
13
+ echo " Waiting for database to stop..."
14
+ pg_ctl -D /var/lib/postgresql/data/pgdata -w stop
15
+
16
+ rm /tmp/postgres.conf
You can’t perform that action at this time.
0 commit comments