From 1eb78ca93e328ab1f242796bb9d77106a8d6d8d0 Mon Sep 17 00:00:00 2001 From: Edgars Voroboks Date: Fri, 8 Mar 2019 15:00:53 +0200 Subject: [PATCH] Add additional changes for Dimension to work --- group_vars/matrix-servers | 21 +++++++++++++++++++ roles/matrix-dimension/defaults/main.yml | 11 ++++++++-- roles/matrix-dimension/tasks/main.yml | 6 ++++++ .../tasks/setup_dimension.yml | 9 +++++--- .../tasks/validate_config.yml | 7 +++++++ .../matrix-dimension/templates/config.yaml.j2 | 2 +- .../systemd/matrix-dimension.service.j2 | 3 +++ 7 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 roles/matrix-dimension/tasks/validate_config.yml diff --git a/group_vars/matrix-servers b/group_vars/matrix-servers index 9e685b98..773150ce 100755 --- a/group_vars/matrix-servers +++ b/group_vars/matrix-servers @@ -99,6 +99,27 @@ matrix_coturn_enabled: true +###################################################################### +# +# matrix-dimension +# +###################################################################### + +matrix_dimension_enabled: false + +# Normally, matrix-nginx-proxy is enabled and nginx can reach Dimension over the container network. +# If matrix-nginx-proxy is not enabled, or you otherwise have a need for it, you can expose +# the Dimension HTTP port to the local host (`127.0.0.1:8184`). +matrix_dimension_container_expose_port: {{ not matrix_nginx_proxy_enabled }} + +###################################################################### +# +# /matrix-dimension +# +###################################################################### + + + ###################################################################### # # matrix-mailer diff --git a/roles/matrix-dimension/defaults/main.yml b/roles/matrix-dimension/defaults/main.yml index 5c1459d3..6b0bf87f 100755 --- a/roles/matrix-dimension/defaults/main.yml +++ b/roles/matrix-dimension/defaults/main.yml @@ -1,15 +1,22 @@ matrix_dimension_enabled: false +# You are required to specify an access token for Dimension to work. # For information on how to acquire an access token, visit https://t2bot.io/docs/access_tokens -matrix_dimension_access_token: CHANGEME +matrix_dimension_access_token: "" # Users in form: ['@user1:domain.com', '@user2:domain.com'] -matrix_dimension_admin: [] +matrix_dimension_admins: [] matrix_dimension_base_path: "{{ matrix_base_data_path }}/dimension" matrix_dimension_docker_image: "turt2live/matrix-dimension:latest" +# The user and group id correspond to the node user in the `turt2live/matrix-dimension` image. +matrix_dimension_user_uid: 1000 +matrix_dimension_user_gid: 1000 + +matrix_dimension_container_expose_port: false + matrix_dimension_integrations_ui_url: "https://{{ matrix_server_fqn_dimension }}/riot" matrix_dimension_integrations_rest_url: "https://{{ matrix_server_fqn_dimension }}/api/v1/scalar" matrix_dimension_integrations_widgets_urls: ["https://{{ matrix_server_fqn_dimension }}/widgets"] diff --git a/roles/matrix-dimension/tasks/main.yml b/roles/matrix-dimension/tasks/main.yml index 4aa0d081..dd3bfc51 100755 --- a/roles/matrix-dimension/tasks/main.yml +++ b/roles/matrix-dimension/tasks/main.yml @@ -2,6 +2,12 @@ tags: - always +- import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup + tags: + - setup-all + - setup-dimension + - import_tasks: "{{ role_path }}/tasks/setup_dimension.yml" when: run_setup tags: diff --git a/roles/matrix-dimension/tasks/setup_dimension.yml b/roles/matrix-dimension/tasks/setup_dimension.yml index 83d01dda..30ed5a83 100755 --- a/roles/matrix-dimension/tasks/setup_dimension.yml +++ b/roles/matrix-dimension/tasks/setup_dimension.yml @@ -8,16 +8,18 @@ file: path: "{{ matrix_dimension_base_path }}" state: directory - mode: 0750 + mode: 0770 owner: "{{ matrix_user_username }}" - group: "{{ matrix_user_username }}" + group: "{{ matrix_dimension_user_gid }}" when: matrix_dimension_enabled - name: Ensure dimension environment variables file created template: src: "{{ role_path }}/templates/config.yaml.j2" dest: "{{ matrix_dimension_base_path }}/config.yaml" - mode: 0644 + mode: 0640 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_dimension_user_gid }}" when: matrix_dimension_enabled - name: Ensure dimension image is pulled @@ -46,6 +48,7 @@ stat: path: "/etc/systemd/system/matrix-dimension.service" register: matrix_dimension_service_stat + when: not matrix_dimension_enabled - name: Ensure matrix-dimension is stopped service: diff --git a/roles/matrix-dimension/tasks/validate_config.yml b/roles/matrix-dimension/tasks/validate_config.yml new file mode 100644 index 00000000..f5960142 --- /dev/null +++ b/roles/matrix-dimension/tasks/validate_config.yml @@ -0,0 +1,7 @@ +- name: Fail if required Dimension settings not defined + fail: + msg: >- + You need to define a required configuration setting (`{{ item }}`) for using Dimension. + with_items: + - "matrix_dimension_access_token" + when: "matrix_dimension_enabled and vars[item] == ''" diff --git a/roles/matrix-dimension/templates/config.yaml.j2 b/roles/matrix-dimension/templates/config.yaml.j2 index 887ecf68..4eb2ae93 100755 --- a/roles/matrix-dimension/templates/config.yaml.j2 +++ b/roles/matrix-dimension/templates/config.yaml.j2 @@ -12,7 +12,7 @@ homeserver: # The URL that Dimension, go-neb, and other services provisioned by Dimension should # use to access the homeserver with. - clientServerUrl: "https://{{ matrix_domain }}" + clientServerUrl: "https://{{ matrix_server_fqn_matrix }}" # The URL that Dimension should use when trying to communicate with federated APIs on # the homeserver. If not supplied or left empty Dimension will try to resolve the address diff --git a/roles/matrix-dimension/templates/systemd/matrix-dimension.service.j2 b/roles/matrix-dimension/templates/systemd/matrix-dimension.service.j2 index 04c70d7d..554713d8 100755 --- a/roles/matrix-dimension/templates/systemd/matrix-dimension.service.j2 +++ b/roles/matrix-dimension/templates/systemd/matrix-dimension.service.j2 @@ -9,9 +9,12 @@ ExecStartPre=-/usr/bin/docker kill matrix-dimension ExecStartPre=-/usr/bin/docker rm matrix-dimension ExecStart=/usr/bin/docker run --rm --name matrix-dimension \ --log-driver=none \ + --user={{ matrix_dimension_user_uid }}:{{ matrix_dimension_user_gid }} \ --cap-drop=ALL \ --network={{ matrix_docker_network }} \ + {% if matrix_dimension_container_expose_port %} -p 127.0.0.1:8184:8184 \ + {% endif %} -v {{ matrix_dimension_base_path }}:/data:rw \ {{ matrix_dimension_docker_image }} ExecStop=-/usr/bin/docker kill matrix-dimension