From 6fce809d1098300fdc6ef8f8c40210db625251b6 Mon Sep 17 00:00:00 2001 From: Aaron Raimist Date: Sun, 9 Jun 2019 20:35:35 -0500 Subject: [PATCH 1/2] Add config option to be able to access database outside of container --- roles/matrix-postgres/defaults/main.yml | 8 ++++++++ .../templates/systemd/matrix-postgres.service.j2 | 3 +++ 2 files changed, 11 insertions(+) diff --git a/roles/matrix-postgres/defaults/main.yml b/roles/matrix-postgres/defaults/main.yml index b3dc1e8fd..f04452e21 100644 --- a/roles/matrix-postgres/defaults/main.yml +++ b/roles/matrix-postgres/defaults/main.yml @@ -15,3 +15,11 @@ matrix_postgres_docker_image_latest: "{{ matrix_postgres_docker_image_v11 }}" # A list of extra arguments to pass to the container matrix_postgres_container_extra_arguments: [] + +# Controls whether the matrix-postgres container exposes a port (tcp/5432 in the +# container) that can be used to access the database with psql. +# +# psql postgresql://username:password@localhost:/database_name +# +# Takes an ":" or "" value (e.g. "127.0.0.1:5432"), or empty string to not expose. +matrix_postgres_container_postgres_bind_port: "" diff --git a/roles/matrix-postgres/templates/systemd/matrix-postgres.service.j2 b/roles/matrix-postgres/templates/systemd/matrix-postgres.service.j2 index 52fefa8cf..4a1970034 100644 --- a/roles/matrix-postgres/templates/systemd/matrix-postgres.service.j2 +++ b/roles/matrix-postgres/templates/systemd/matrix-postgres.service.j2 @@ -17,6 +17,9 @@ ExecStart=/usr/bin/docker run --rm --name matrix-postgres \ --tmpfs=/tmp:rw,noexec,nosuid,size=100m \ --tmpfs=/run/postgresql:rw,noexec,nosuid,size=100m \ --network={{ matrix_docker_network }} \ + {% if matrix_postgres_container_postgres_bind_port %} + -p {{ matrix_postgres_container_postgres_bind_port }}:5432 \ + {% endif %} --env-file={{ matrix_postgres_base_path }}/env-postgres-server \ -v {{ matrix_postgres_data_path }}:/var/lib/postgresql/data:rw \ -v /etc/passwd:/etc/passwd:ro \ From 4f87f7e43e5389cb9bd835d55b652b261cad42b6 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Mon, 10 Jun 2019 08:24:37 +0300 Subject: [PATCH 2/2] Explain matrix_postgres_container_postgres_bind_port a little more Previously, it only mentioned exposing for psql-usage purposes. Realistically, it can be used for much more. Especially given that psql can be easily accessed via our matrix-postgres-cli script, without exposing the container port. --- roles/matrix-postgres/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/matrix-postgres/defaults/main.yml b/roles/matrix-postgres/defaults/main.yml index f04452e21..9e951fb42 100644 --- a/roles/matrix-postgres/defaults/main.yml +++ b/roles/matrix-postgres/defaults/main.yml @@ -17,7 +17,7 @@ matrix_postgres_docker_image_latest: "{{ matrix_postgres_docker_image_v11 }}" matrix_postgres_container_extra_arguments: [] # Controls whether the matrix-postgres container exposes a port (tcp/5432 in the -# container) that can be used to access the database with psql. +# container) that can be used to access the database from outside the container (e.g. with psql) # # psql postgresql://username:password@localhost:/database_name #