Skip to content

Commit

Permalink
make the container easily configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
  • Loading branch information
TomasTomecek committed Jul 17, 2017
1 parent 30f6dd4 commit 4237745
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
23 changes: 23 additions & 0 deletions 9.5/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ or if it was already present, [`postgres`](http://www.postgresql.org/docs/9.2/st
is executed and will run as PID 1. You can stop the detached container by running
`docker stop postgresql_database`.

Supplying custom configuration file
--------------------

You are able to supply your custom configuration file. PostgreSQL container
image is using templating to fill in configuration file in container startup
script. You are able to override the default template. With this approach you
can even define your own variables which you can pass as envinronment variables
to the container.

The template is located within container image on path:

/usr/share/container-scripts/postgresql/openshift-custom-postgresql.conf.template

You can copy it like this:

$ docker create --name=pg registry.access.redhat.com/rhscl/postgresql-95-rhel7:latest
$ docker cp pg:/usr/share/container-scripts/postgresql/openshift-custom-postgresql.conf.template .

And then file `openshift-custom-postgresql.conf.template` will be present in
your current working directory.

For more information on the configuration file, please see [the upstream documentation for runtime configuration](https://www.postgresql.org/docs/9.5/static/runtime-config.html).

PostgreSQL auto-tuning
--------------------

Expand Down
56 changes: 55 additions & 1 deletion hack/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ run_general_tests
run_change_password_test
run_replication_test
run_master_restart_test
run_doc_test"
run_doc_test
run_config_change_test"

test $# -eq 1 -a "${1-}" == --list && echo "$TEST_LIST" && exit 0
test -n "${IMAGE_NAME-}" || false 'make sure $IMAGE_NAME is defined'
Expand Down Expand Up @@ -202,6 +203,14 @@ function test_config_option() {
docker exec $(get_cid ${name}) grep -q "${setting} = ${value}" /var/lib/pgsql/openshift-custom-postgresql.conf
}

function test_runtime_config_value() {
local name=$1 ; shift
local setting=$1 ; shift
local value=$1 ; shift

docker exec $(get_cid ${name}) bash -c "psql --command \"show ${setting};\"" | grep "${value}"
}

function run_configuration_tests() {
local name=$1 ; shift
echo " Testing image configuration settings"
Expand Down Expand Up @@ -523,6 +532,51 @@ run_doc_test() {
echo
}

function run_config_change_test() {
local tmpdir=$(mktemp -d)
local template_basename=openshift-custom-postgresql.conf.template
local template_local_tmp_path=${tmpdir}/${template_basename}
local template_container_dir=/usr/share/container-scripts/postgresql/
local template_container_path=${template_container_dir}/${template_basename}
local work_mem="128MB"
echo " Testing changing configuration file"

docker run --rm ${IMAGE_NAME} \
/bin/bash -c \
"cat ${template_container_path}" >${template_local_tmp_path}

printf "\nwork_mem = \${POSTGRESQL_WORK_MEM}\n" >>${template_local_tmp_path}
cat ${template_local_tmp_path}

local name="config_test"
local database='db'
local user='user'
local password='password'
local admin_password='adminPassword'
local volume_options="-v ${template_local_tmp_path}:${template_container_path}:Z"

DOCKER_ARGS="
-e POSTGRESQL_DATABASE=${database}
-e POSTGRESQL_USER=${user}
-e POSTGRESQL_PASSWORD=${password}
-e POSTGRESQL_WORK_MEM=${work_mem}
$volume_options
" create_container ${name}

# need to set these because `postgresql_cmd` relies on global variables
PGUSER=${user}
PASS=${password}

# need this to wait for the container to start up
CONTAINER_IP=$(get_container_ip ${name})
test_connection ${name}

test_runtime_config_value ${name} work_mem ${work_mem}

echo " Success!"
echo
}

function run_general_tests() {
PGUSER=user PASS=pass POSTGRESQL_MAX_CONNECTIONS=42 POSTGRESQL_MAX_PREPARED_TRANSACTIONS=42 POSTGRESQL_SHARED_BUFFERS=64MB run_tests no_admin
PGUSER=user1 PASS=pass1 ADMIN_PASS=r00t run_tests admin
Expand Down

0 comments on commit 4237745

Please sign in to comment.