sync with previous repo

This commit is contained in:
Michael Collins
2021-08-13 16:05:57 +08:00
parent 83a90f1cd1
commit 98e6cd685d
641 changed files with 43857 additions and 55 deletions

View File

@ -0,0 +1,91 @@
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: ""
# Users in form: ['@user1:domain.com', '@user2:domain.com']
matrix_dimension_admins: []
# Whether to allow Dimension widgets serve websites with invalid or self signed SSL certificates
matrix_dimension_widgets_allow_self_signed_ssl_certificates: false
matrix_dimension_base_path: "{{ matrix_base_data_path }}/dimension"
matrix_dimension_version: latest
matrix_dimension_docker_image: "{{ matrix_container_global_registry_prefix }}turt2live/matrix-dimension:{{ matrix_dimension_version }}"
matrix_dimension_docker_image_force_pull: "{{ matrix_dimension_docker_image.endswith(':latest') }}"
# List of systemd services that matrix-dimension.service depends on.
matrix_dimension_systemd_required_services_list: ['docker.service']
# List of systemd services that matrix-dimension.service wants
matrix_dimension_systemd_wanted_services_list: []
# 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'
# Controls whether the matrix-dimension container exposes its HTTP port (tcp/8184 in the container).
#
# Takes an "<ip>:<port>" or "<port>" value (e.g. "127.0.0.1:8184"), or empty string to not expose.
matrix_dimension_container_http_host_bind_port: ''
# A list of extra arguments to pass to the container
matrix_dimension_container_extra_arguments: []
matrix_dimension_integrations_ui_url: "https://{{ matrix_server_fqn_dimension }}/element"
matrix_dimension_integrations_rest_url: "https://{{ matrix_server_fqn_dimension }}/api/v1/scalar"
matrix_dimension_integrations_widgets_urls: ["https://{{ matrix_server_fqn_dimension }}/widgets"]
matrix_dimension_integrations_jitsi_widget_url: "https://{{ matrix_server_fqn_dimension }}/widgets/jitsi"
matrix_dimension_homeserver_federationUrl: "http://matrix-synapse:8048"
# Database-related configuration fields.
#
# To use SQLite, stick to these defaults.
#
# To use Postgres:
# - change the engine (`matrix_dimension_database_engine: 'postgres'`)
# - adjust your database credentials via the `matrix_dimension_postgres_*` variables
matrix_dimension_database_engine: 'sqlite'
matrix_dimension_sqlite_database_path_local: "{{ matrix_dimension_base_path }}/dimension.db"
matrix_dimension_sqlite_database_path_in_container: "dimension.db"
matrix_dimension_database_username: 'matrix_dimension'
matrix_dimension_database_password: 'some-password'
matrix_dimension_database_hostname: 'matrix-postgres'
matrix_dimension_database_port: 5432
matrix_dimension_database_name: 'matrix_dimension'
matrix_dimension_database_connection_string: 'postgres://{{ matrix_dimension_database_username }}:{{ matrix_dimension_database_password }}@{{ matrix_dimension_database_hostname }}:{{ matrix_dimension_database_port }}/{{ matrix_dimension_database_name }}'
# Default Dimension configuration template which covers the generic use case.
# You can customize it by controlling the various variables inside it.
#
# For a more advanced customization, you can extend the default (see `matrix_dimension_configuration_extension_yaml`)
# or completely replace this variable with your own template.
matrix_dimension_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}"
matrix_dimension_configuration_extension_yaml: |
# Your custom YAML configuration for Dimension goes here.
# This configuration extends the default starting configuration (`matrix_dimension_configuration_yaml`).
#
# You can override individual variables from the default configuration, or introduce new ones.
#
# If you need something more special, you can take full control by
# completely redefining `matrix_dimension_configuration_yaml`.
#
# Example configuration extension follows:
# telegram:
# botToken: "YourTokenHere"
#
matrix_dimension_configuration_extension: "{{ matrix_dimension_configuration_extension_yaml|from_yaml if matrix_dimension_configuration_extension_yaml|from_yaml is mapping else {} }}"
# Holds the final Dimension configuration (a combination of the default and its extension).
# You most likely don't need to touch this variable. Instead, see `matrix_dimension_configuration_yaml`.
matrix_dimension_configuration: "{{ matrix_dimension_configuration_yaml|from_yaml|combine(matrix_dimension_configuration_extension, recursive=True) }}"

View File

@ -0,0 +1,3 @@
- set_fact:
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-dimension.service'] }}"
when: matrix_dimension_enabled|bool

View File

@ -0,0 +1,21 @@
- import_tasks: "{{ role_path }}/tasks/init.yml"
tags:
- always
- import_tasks: "{{ role_path }}/tasks/validate_config.yml"
when: run_setup|bool
tags:
- setup-all
- setup-dimension
- import_tasks: "{{ role_path }}/tasks/setup_install.yml"
when: run_setup|bool and matrix_dimension_enabled|bool
tags:
- setup-all
- setup-dimension
- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml"
when: run_setup|bool and not matrix_dimension_enabled|bool
tags:
- setup-all
- setup-dimension

View File

@ -0,0 +1,110 @@
---
- set_fact:
matrix_dimension_requires_restart: false
- block:
- name: Check if an SQLite database already exists
stat:
path: "{{ matrix_dimension_sqlite_database_path_local }}"
register: matrix_dimension_sqlite_database_path_local_stat_result
- block:
# pgloader makes a few columns `smallint`, instead of `boolean`.
# We need to fix them up.
- set_fact:
matrix_dimension_pgloader_additional_psql_statements_list: []
- set_fact:
matrix_dimension_pgloader_additional_psql_statements_list: |
{{
matrix_dimension_pgloader_additional_psql_statements_list
+
([] if item.default == '' else ['ALTER TABLE ' + item.table + ' ALTER COLUMN "' + item.column + '" DROP default;'])
+
(['ALTER TABLE ' + item.table + ' ALTER COLUMN "' + item.column + '" TYPE BOOLEAN USING("' + item.column + '"::text::boolean);'])
+
([] if item.default == '' else ['ALTER TABLE ' + item.table + ' ALTER COLUMN "' + item.column + '" SET default ' + item.default + ';'])
}}
with_items:
- {'table': 'dimension_widgets', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_widgets', 'column': 'isPublic', 'default': ''}
- {'table': 'dimension_webhook_bridges', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_user_sticker_packs', 'column': 'isSelected', 'default': ''}
- {'table': 'dimension_scalar_tokens', 'column': 'isDimensionToken', 'default': ''}
- {'table': 'dimension_users', 'column': 'isSelfBot', 'default': 'false'}
- {'table': 'dimension_telegram_bridges', 'column': 'allowTgPuppets', 'default': ''}
- {'table': 'dimension_telegram_bridges', 'column': 'allowMxPuppets', 'default': ''}
- {'table': 'dimension_telegram_bridges', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_sticker_packs', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_sticker_packs', 'column': 'isPublic', 'default': ''}
- {'table': 'dimension_slack_bridges', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_neb_integrations', 'column': 'isPublic', 'default': ''}
- {'table': 'dimension_neb_integrations', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_irc_bridges', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_irc_bridge_networks', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_gitter_bridges', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_custom_simple_bots', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_custom_simple_bots', 'column': 'isPublic', 'default': ''}
- {'table': 'dimension_bridges', 'column': 'isEnabled', 'default': ''}
- {'table': 'dimension_bridges', 'column': 'isPublic', 'default': ''}
- set_fact:
matrix_postgres_db_migration_request:
src: "{{ matrix_dimension_sqlite_database_path_local }}"
dst: "{{ matrix_dimension_database_connection_string }}"
caller: "{{ role_path|basename }}"
engine_variable_name: 'matrix_dimension_database_engine'
engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-dimension.service']
pgloader_options: ['--with "quote identifiers"']
additional_psql_statements_list: "{{ matrix_dimension_pgloader_additional_psql_statements_list }}"
additional_psql_statements_db_name: "{{ matrix_dimension_database_name }}"
- import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
- set_fact:
matrix_dimension_requires_restart: true
when: "matrix_dimension_sqlite_database_path_local_stat_result.stat.exists|bool"
when: "matrix_dimension_database_engine == 'postgres'"
- name: Ensure Dimension base path exists
file:
path: "{{ matrix_dimension_base_path }}"
state: directory
mode: 0770
owner: "{{ matrix_user_username }}"
group: "{{ matrix_dimension_user_gid }}"
- name: Ensure Dimension config installed
copy:
content: "{{ matrix_dimension_configuration|to_nice_yaml }}"
dest: "{{ matrix_dimension_base_path }}/config.yaml"
mode: 0640
owner: "{{ matrix_user_username }}"
group: "{{ matrix_dimension_user_gid }}"
- name: Ensure Dimension image is pulled
docker_image:
name: "{{ matrix_dimension_docker_image }}"
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
force_source: "{{ matrix_dimension_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_dimension_docker_image_force_pull }}"
- name: Ensure matrix-dimension.service installed
template:
src: "{{ role_path }}/templates/systemd/matrix-dimension.service.j2"
dest: "{{ matrix_systemd_path }}/matrix-dimension.service"
mode: 0644
register: matrix_dimension_systemd_service_result
- name: Ensure systemd reloaded after matrix-dimension.service installation
service:
daemon_reload: yes
when: "matrix_dimension_systemd_service_result.changed|bool"
- name: Ensure matrix-dimension.service restarted, if necessary
service:
name: "matrix-dimension.service"
state: restarted
when: "matrix_dimension_requires_restart|bool"

View File

@ -0,0 +1,35 @@
---
- name: Check existence of matrix-dimension service
stat:
path: "{{ matrix_systemd_path }}/matrix-dimension.service"
register: matrix_dimension_service_stat
- name: Ensure matrix-dimension is stopped
service:
name: matrix-dimension
state: stopped
daemon_reload: yes
register: stopping_result
when: "matrix_dimension_service_stat.stat.exists|bool"
- name: Ensure matrix-dimension.service doesn't exist
file:
path: "{{ matrix_systemd_path }}/matrix-dimension.service"
state: absent
when: "matrix_dimension_service_stat.stat.exists|bool"
- name: Ensure systemd reloaded after matrix-dimension.service removal
service:
daemon_reload: yes
when: "matrix_dimension_service_stat.stat.exists|bool"
- name: Ensure Dimension base directory doesn't exist
file:
path: "{{ matrix_dimension_base_path }}"
state: absent
- name: Ensure Dimension Docker image doesn't exist
docker_image:
name: "{{ matrix_dimension_docker_image }}"
state: absent

View File

@ -0,0 +1,16 @@
- 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] == ''"
- name: (Deprecation) Catch and report renamed Dimension variables
fail:
msg: >-
Your configuration contains a variable, which now has a different name.
Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`).
when: "item.old in vars"
with_items:
- {'old': 'matrix_dimension_container_expose_port', 'new': '<superseded by matrix_dimension_container_http_host_bind_port>'}

View File

@ -0,0 +1,85 @@
#jinja2: lstrip_blocks: True
# The web settings for the service (API and UI).
# It is best to have this run on localhost and use a reverse proxy to access Dimension.
web:
port: 8184
address: '0.0.0.0'
# Homeserver configuration
homeserver:
# The domain name of the homeserver. This is used in many places, such as with go-neb
# setups, to identify the homeserver.
name: "{{ matrix_domain }}"
# The URL that Dimension, go-neb, and other services provisioned by Dimension should
# use to access the homeserver with.
clientServerUrl: "{{ matrix_homeserver_container_url }}"
# 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
# through the normal federation process.
federationUrl: "{{ matrix_dimension_homeserver_federationUrl }}"
# The URL that Dimension will redirect media requests to for downloading media such as
# stickers. If not supplied or left empty Dimension will use the clientServerUrl.
mediaUrl: "https://{{ matrix_server_fqn_matrix }}"
# The access token Dimension should use for miscellaneous access to the homeserver. This
# should be for a user on the configured homeserver: any user will do, however it is
# recommended to use a dedicated user (such as @dimension:t2bot.io). For information on
# how to acquire an access token, visit https://t2bot.io/docs/access_tokens
accessToken: "{{ matrix_dimension_access_token }}"
# These users can modify the integrations this Dimension supports.
# To access the admin interface, open Dimension in Element and click the settings icon.
admins: {{ matrix_dimension_admins|to_json }}
# IPs and CIDR ranges listed here will be blocked from being widgets.
# Note: Widgets may still be embedded with restricted content, although not through Dimension directly.
widgetBlacklist:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
- 127.0.0.0/8
# Where the database for Dimension is
database:
{% if matrix_dimension_database_engine == 'sqlite' %}
file: {{ matrix_dimension_sqlite_database_path_in_container|to_json }}
{% elif matrix_dimension_database_engine == 'postgres' %}
uri: {{ matrix_dimension_database_connection_string|to_json }}
{% endif %}
# Display settings that apply to self-hosted go-neb instances
goneb:
# The avatars to set for each bot. Usually these don't need to be changed, however if your homeserver
# is not able to reach t2bot.io then you should specify your own here. To not use an avatar for a bot,
# make the bot's avatar an empty string.
avatars:
giphy: "mxc://t2bot.io/c5eaab3ef0133c1a61d3c849026deb27"
imgur: "mxc://t2bot.io/6749eaf2b302bb2188ae931b2eeb1513"
github: "mxc://t2bot.io/905b64b3cd8e2347f91a60c5eb0832e1"
wikipedia: "mxc://t2bot.io/7edfb54e9ad9e13fec0df22636feedf1"
travisci: "mxc://t2bot.io/7f4703126906fab8bb27df34a17707a8"
rss: "mxc://t2bot.io/aace4fcbd045f30afc1b4e5f0928f2f3"
google: "mxc://t2bot.io/636ad10742b66c4729bf89881a505142"
guggy: "mxc://t2bot.io/e7ef0ed0ba651aaf907655704f9a7526"
echo: "mxc://t2bot.io/3407ff2db96b4e954fcbf2c6c0415a13"
circleci: "mxc://t2bot.io/cf7d875845a82a6b21f5f66de78f6bee"
jira: "mxc://t2bot.io/f4a38ebcc4280ba5b950163ca3e7c329"
# Settings for how Dimension is represented to the public
dimension:
# This is where Dimension is accessible from clients. Be sure to set this
# to your own Dimension instance.
publicUrl: "https://{{ matrix_server_fqn_dimension }}"
# Settings for controlling how logging works
logging:
file: /dev/null
console: true
consoleLevel: verbose
fileLevel: info
rotate:
size: 52428800 # bytes, default is 50mb
count: 5

View File

@ -0,0 +1,48 @@
#jinja2: lstrip_blocks: "True"
[Unit]
Description=Matrix Dimension
{% for service in matrix_dimension_systemd_required_services_list %}
Requires={{ service }}
After={{ service }}
{% endfor %}
{% for service in matrix_dimension_systemd_wanted_services_list %}
Wants={{ service }}
{% endfor %}
DefaultDependencies=no
[Service]
Type=simple
Environment="HOME={{ matrix_systemd_unit_home_path }}"
ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-dimension 2>/dev/null'
ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-dimension 2>/dev/null'
# Fixup database ownership if it got changed somehow (during a server migration, etc.)
{% if matrix_dimension_database_engine == 'sqlite' %}
ExecStartPre=-{{ matrix_host_command_chown }} {{ matrix_dimension_user_uid }}:{{ matrix_dimension_user_gid }} {{ matrix_dimension_sqlite_database_path_local }}
{% endif %}
ExecStart={{ matrix_host_command_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_widgets_allow_self_signed_ssl_certificates %}
-e NODE_TLS_REJECT_UNAUTHORIZED=0 \
{% endif %}
{% if matrix_dimension_container_http_host_bind_port %}
-p {{ matrix_dimension_container_http_host_bind_port }}:8184 \
{% endif %}
--mount type=bind,src={{ matrix_dimension_base_path }},dst=/data \
{% for arg in matrix_dimension_container_extra_arguments %}
{{ arg }} \
{% endfor %}
{{ matrix_dimension_docker_image }}
ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-dimension 2>/dev/null'
ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-dimension 2>/dev/null'
Restart=always
RestartSec=30
SyslogIdentifier=matrix-dimension
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,5 @@
---
# Doing `|from_yaml` when the extension contains nothing yields an empty string ("").
# We need to ensure it's a dictionary or `|combine` (when building `matrix_dimension_configuration`) will fail later.
matrix_dimension_configuration_extension: "{{ matrix_dimension_configuration_extension_yaml|from_yaml if matrix_dimension_configuration_extension_yaml|from_yaml else {} }}"