Skip to content

Commit 23189b7

Browse files
committedNov 29, 2017
Applying review suggestions-to be squashed when approved
1 parent f58b86e commit 23189b7

File tree

11 files changed

+31
-42
lines changed

11 files changed

+31
-42
lines changed
 

‎examples/extending-image/init/init-backup-user.sh

-4
This file was deleted.

‎examples/extending-image/pre-init/check-backup-user.sh

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# postgresql image encrypts user passwords at service start
4+
# the functionality can be disabled by providing this file (start-hook/set_passwords.sh) in s2i build

‎latest/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ ENV BASH_ENV=${CONTAINER_SCRIPTS_PATH}/scl_enable \
6969

7070
VOLUME ["/var/lib/pgsql/data"]
7171

72-
RUN chown -R 26:26 ${APP_DATA}
72+
# {APP_DATA} needs to be accessed by postgres user while s2i assembling
73+
RUN chown -R 26:0 ${APP_DATA}
7374
USER 26
7475

7576
ENTRYPOINT ["container-entrypoint"]

‎latest/Dockerfile.rhel7

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ ENV BASH_ENV=${CONTAINER_SCRIPTS_PATH}/scl_enable \
7272

7373
VOLUME ["/var/lib/pgsql/data"]
7474

75-
RUN chown -R 26:26 ${APP_DATA}
75+
# {APP_DATA} needs to be accessed by postgres user while s2i assembling
76+
RUN chown -R 26:0 ${APP_DATA}
7677
USER 26
7778

7879
ENTRYPOINT ["container-entrypoint"]

‎latest/root/usr/bin/run-postgresql

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@ else
2222
try_pgupgrade
2323
fi
2424

25-
process_extending_files ${APP_DATA}/src/pre-init ${CONTAINER_SCRIPTS_PATH}/pre-init
26-
2725
pg_ctl -w start -o "-h ''"
2826
if $PG_INITIALIZED ; then
27+
process_extending_files ${APP_DATA}/src/init-hook ${CONTAINER_SCRIPTS_PATH}/init-hook
2928
migrate_db
3029
create_users
3130
fi
32-
set_passwords
3331

34-
process_extending_files ${APP_DATA}/src/init ${CONTAINER_SCRIPTS_PATH}/init
32+
process_extending_files ${APP_DATA}/src/start-hook ${CONTAINER_SCRIPTS_PATH}/start-hook
3533

3634
pg_ctl stop
3735

‎latest/root/usr/share/container-scripts/postgresql/README.md

+7-14
Original file line numberDiff line numberDiff line change
@@ -254,32 +254,25 @@ following directories:
254254

255255
##### `postgresql-config/`
256256

257-
contained files will be included at the end of image postgresql.conf file
257+
contained files will be included at the end of image postgresql.conf file during database initialization
258258

259-
##### `pre-init/`
260259

261-
contained shell scripts (`*.sh`) are sourced before `service` is started
260+
##### `init-hook/`
262261

263-
##### `init/`
262+
contained shell scripts (`*.sh`) are sourced once, when database is initialized
264263

265-
contained shell scripts (`*.sh`) are sourced after `service` is
266-
started
264+
##### `start-hook/`
265+
266+
contained shell scripts (`*.sh`) are sourced before every start
267267

268268
----------------------------------------------
269269

270270
During `s2i build` all provided files are copied into `/opt/app-root/src`
271-
directory in the new image. If some configuration files are present in
272-
destination directory, files with the same name are overwritten. Also only one
271+
directory in the new image. Only one
273272
file with the same name can be used for customization and user provided files
274273
are preferred over default files in `/usr/share/container-scripts/`-
275274
so it is possible to overwrite them.
276275

277-
Same configuration directory structure can be used to customize the image
278-
every time the image is started using `docker run`. The directory have to be
279-
mounted into `/opt/app-root/src/` in the image (`-v
280-
./image-configuration/:/opt/app-root/src/`). This overwrites customization
281-
built into the image.
282-
283276

284277
Troubleshooting
285278
---------------

‎latest/root/usr/share/container-scripts/postgresql/common.sh

-15
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,6 @@ function create_users() {
190190
fi
191191
}
192192

193-
function set_passwords() {
194-
if [[ ",$postinitdb_actions," = *,simple_db,* ]]; then
195-
psql --command "ALTER USER \"${POSTGRESQL_USER}\" WITH ENCRYPTED PASSWORD '${POSTGRESQL_PASSWORD}';"
196-
fi
197-
198-
if [ -v POSTGRESQL_MASTER_USER ]; then
199-
psql --command "ALTER USER \"${POSTGRESQL_MASTER_USER}\" WITH REPLICATION;"
200-
psql --command "ALTER USER \"${POSTGRESQL_MASTER_USER}\" WITH ENCRYPTED PASSWORD '${POSTGRESQL_MASTER_PASSWORD}';"
201-
fi
202-
203-
if [ -v POSTGRESQL_ADMIN_PASSWORD ]; then
204-
psql --command "ALTER USER \"postgres\" WITH ENCRYPTED PASSWORD '${POSTGRESQL_ADMIN_PASSWORD}';"
205-
fi
206-
}
207-
208193
migrate_db ()
209194
{
210195
test "$postinitdb_actions" = ",migration" || return 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
if [[ ",$postinitdb_actions," = *,simple_db,* ]]; then
4+
psql --command "ALTER USER \"${POSTGRESQL_USER}\" WITH ENCRYPTED PASSWORD '${POSTGRESQL_PASSWORD}';"
5+
fi
6+
7+
if [ -v POSTGRESQL_MASTER_USER ]; then
8+
psql --command "ALTER USER \"${POSTGRESQL_MASTER_USER}\" WITH REPLICATION;"
9+
psql --command "ALTER USER \"${POSTGRESQL_MASTER_USER}\" WITH ENCRYPTED PASSWORD '${POSTGRESQL_MASTER_PASSWORD}';"
10+
fi
11+
12+
if [ -v POSTGRESQL_ADMIN_PASSWORD ]; then
13+
psql --command "ALTER USER \"postgres\" WITH ENCRYPTED PASSWORD '${POSTGRESQL_ADMIN_PASSWORD}';"
14+
fi

0 commit comments

Comments
 (0)
Please sign in to comment.