Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the container easily configurable #177

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 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,47 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about add notice about "how to supply custom configuration file"? This section is mainly about getting configuration template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! there's nothing about running postgres while using the custom template config; will add

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omron93 I added a commit which should address your comment.

--------------------

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. At this point, you can start editing the
template. 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).

Once you are done, you can run the PostgreSQL container with the custom configuration template:

$ docker run -v ${PWD}/openshift-custom-postgresql.conf.template:/usr/share/container-scripts/postgresql/openshift-custom-postgresql.conf.template:Z ...

If you want to check the current runtime configuration and be sure that all the
values were picked up, you can run this command which will output it:

$ docker exec postgresql-container bash -c 'psql --command "show all;"'

There is a shorter version where you can just see a single value, in this case `work_mem`:

$ docker exec postgresql-container bash -c 'psql --command "show work_mem;"'
work_mem
----------
128MB
(1 row)

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