diff --git a/roles/matrix-server/defaults/main.yml b/roles/matrix-server/defaults/main.yml index 9ba39dd2..de7e01dd 100644 --- a/roles/matrix-server/defaults/main.yml +++ b/roles/matrix-server/defaults/main.yml @@ -40,7 +40,11 @@ matrix_coturn_base_path: "{{ matrix_base_data_path }}/coturn" matrix_coturn_config_path: "{{ matrix_coturn_base_path }}/turnserver.conf" matrix_scratchpad_dir: "{{ matrix_base_data_path }}/scratchpad" -docker_postgres_image: "postgres:9.6.8-alpine" + +docker_postgres_image_v9: "postgres:9.6.8-alpine" +docker_postgres_image_v10: "postgres:10.4-alpine" +docker_postgres_image_latest: "{{ docker_postgres_image_v10 }}" + docker_matrix_image: "matrixdotorg/synapse:v0.30.0" docker_nginx_image: "nginx:1.13.12-alpine" docker_riot_image: "avhost/docker-matrix-riot:v0.15.4" @@ -48,6 +52,7 @@ docker_s3fs_image: "xueshanf/s3fs:latest" docker_goofys_image: "cloudproto/goofys:latest" docker_coturn_image: "instrumentisto/coturn:4.5.0.7" + # To avoid Synapse's macaroon secret key from changing every time # a new config is built from scratch, you can specify one here. matrix_synapse_macaroon_secret_key: null diff --git a/roles/matrix-server/tasks/setup_postgres.yml b/roles/matrix-server/tasks/setup_postgres.yml index c52e0b6a..a231b902 100644 --- a/roles/matrix-server/tasks/setup_postgres.yml +++ b/roles/matrix-server/tasks/setup_postgres.yml @@ -4,10 +4,39 @@ # Generic tasks, no matter what kind of server we're using (internal/external) # +- name: Determine existing Postgres version (check PG_VERSION file) + stat: + path: "{{ matrix_postgres_data_path }}/PG_VERSION" + register: result_pg_version_stat + +- name: Determine existing Postgres version (read PG_VERSION file) + slurp: + src: "{{ matrix_postgres_data_path }}/PG_VERSION" + register: result_pg_version + when: "result_pg_version_stat.stat.exists" + +- name: Determine existing Postgres version (default to empty) + set_fact: + pg_version: "" + +- name: Determine existing Postgres version (make sense of PG_VERSION file) + set_fact: + pg_version: "{{ result_pg_version['content']|b64decode|replace('\n', '') }}" + when: "result_pg_version_stat.stat.exists" + +- name: Determine Postgres version to use (default to latest) + set_fact: + docker_postgres_image_to_use: "{{ docker_postgres_image_latest }}" + +- name: Determine Postgres version to use (use 9.x, if detected) + set_fact: + docker_postgres_image_to_use: "{{ docker_postgres_image_v9 }}" + when: "pg_version.startswith('9.')" + # Even if we don't run the internal server, we still need this for running the CLI - name: Ensure postgres Docker image is pulled docker_image: - name: "{{ docker_postgres_image }}" + name: "{{ docker_postgres_image_to_use }}" - name: Ensure Postgres environment variables file created template: diff --git a/roles/matrix-server/templates/systemd/matrix-postgres.service.j2 b/roles/matrix-server/templates/systemd/matrix-postgres.service.j2 index 846d7355..f0bc4bd4 100644 --- a/roles/matrix-server/templates/systemd/matrix-postgres.service.j2 +++ b/roles/matrix-server/templates/systemd/matrix-postgres.service.j2 @@ -14,7 +14,7 @@ ExecStart=/usr/bin/docker run --rm --name matrix-postgres \ --env-file={{ matrix_environment_variables_data_path }}/env-postgres-server-docker \ -v {{ matrix_postgres_data_path }}:/var/lib/postgresql/data \ -v /etc/passwd:/etc/passwd:ro \ - {{ docker_postgres_image }} + {{ docker_postgres_image_to_use }} ExecStop=-/usr/bin/docker stop matrix-postgres ExecStop=-/usr/bin/docker rm matrix-postgres Restart=always diff --git a/roles/matrix-server/templates/usr-local-bin/matrix-postgres-cli.j2 b/roles/matrix-server/templates/usr-local-bin/matrix-postgres-cli.j2 index 2e6a15ce..f2379276 100644 --- a/roles/matrix-server/templates/usr-local-bin/matrix-postgres-cli.j2 +++ b/roles/matrix-server/templates/usr-local-bin/matrix-postgres-cli.j2 @@ -7,5 +7,5 @@ docker run \ {% if not matrix_postgres_use_external %} --link=matrix-postgres:{{ matrix_postgres_connection_hostname }} \ {% endif %} - {{ docker_postgres_image }} \ + {{ docker_postgres_image_to_use }} \ psql -h {{ matrix_postgres_connection_hostname }} \ No newline at end of file