diff --git a/bundles/mx-puppet-discord/files/config.yaml b/bundles/mx-puppet-discord/files/config.yaml new file mode 100644 index 0000000..56a45c1 --- /dev/null +++ b/bundles/mx-puppet-discord/files/config.yaml @@ -0,0 +1,28 @@ +bridge: + port: ${node.metadata['mx-puppet-discord'].get('port', 20000)} + bindAddress: ${node.metadata['mx-puppet-discord'].get('listen-addr', '[::1]')} + domain: ${node.metadata['mx-puppet-discord']['homeserver']['domain']} + homeserverUrl: ${node.metadata['mx-puppet-discord']['homeserver']['url']} + +presence: + enabled: true + interval: 500 + +provisioning: + whitelist: +% for regex in node.metadata['mx-puppet-discord']['allowed-users']: + - "${regex}" +% endfor + +database: + connString: "postgres://${node.metadata['mx-puppet-discord']['database']['user']}:${node.metadata['mx-puppet-discord']['database']['password']}@${node.metadata['mx-puppet-discord']['database'].get('host', 'localhost')}/${node.metadata['mx-puppet-discord']['database']['database']}?sslmode=disable" + +logging: + console: info + lineDateFormat: YYYY-MM-DD HH:mm:ss.SSS + files: + - file: "/var/log/mx-puppet-discord/bridge.log" + level: info + datePattern: YYYY-MM-DD + maxFiles: 14d + maxSize: 50m diff --git a/bundles/mx-puppet-discord/items.py b/bundles/mx-puppet-discord/items.py new file mode 100644 index 0000000..8c5d583 --- /dev/null +++ b/bundles/mx-puppet-discord/items.py @@ -0,0 +1,69 @@ +assert node.has_bundle('nodejs') + +directories = { + '/var/log/mx-puppet-discord': { + 'owner': 'mx-puppet-discord', + }, +} + +files = { + '/opt/mx-puppet-discord/config.yaml': { + 'owner': 'mx-puppet-discord', + 'content_type': 'mako', + 'needs': { + 'git_deploy:/opt/mx-puppet-discord', + }, + 'triggers': { + 'action:mx-puppet-discord_generate_registration', + }, + }, +} + +git_deploy = { + '/opt/mx-puppet-discord': { + 'repo': 'https://github.com/matrix-discord/mx-puppet-discord.git', + 'rev': 'master', + 'needs': { + 'directory:/opt/mx-puppet-discord', + }, + 'triggers': { + 'action:mx-puppet-discord_chown', + 'action:mx-puppet-discord_npm_install', + 'action:mx-puppet-discord_npm_build', + }, + }, +} + +actions = { + 'mx-puppet-discord_chown': { + 'command': 'chown -R mx-puppet-discord:mx-puppet-discord /opt/mx-puppet-discord/*', + 'needed_by': { + 'action:mx-puppet-discord_npm_install', + }, + 'triggered': True, + }, + 'mx-puppet-discord_npm_install': { + 'command': 'cd /opt/mx-puppet-discord && sudo -u mx-puppet-discord npm install', + 'needs': { + 'pkg_apt:nodejs', + 'user:mx-puppet-discord', + }, + 'triggered': True, + }, + 'mx-puppet-discord_npm_build': { + 'command': 'cd /opt/mx-puppet-discord && sudo -u mx-puppet-discord npm run-script build', + 'needs': { + 'action:mx-puppet-discord_npm_install', + }, + 'triggered': True, + }, + 'mx-puppet-discord_generate_registration': { + 'command': 'cd /opt/mx-puppet-discord && sudo -u mx-puppet-discord node ./build/index.js -r -c /opt/mx-puppet-discord/config.yaml -f /opt/mx-puppet-discord/registration.yaml', + 'needs': { + 'user:mx-puppet-discord', + 'action:mx-puppet-discord_npm_build', + 'directory:/var/log/mx-puppet-discord', + }, + 'triggered': True, + }, +} diff --git a/bundles/mx-puppet-discord/metadata.py b/bundles/mx-puppet-discord/metadata.py new file mode 100644 index 0000000..6982d50 --- /dev/null +++ b/bundles/mx-puppet-discord/metadata.py @@ -0,0 +1,10 @@ +@metadata_processor +def mx_puppet_discord_user(metadata): + return { + 'users': { + 'mx-puppet-discord': { + 'home': '/opt/mx-puppet-discord', + 'deploy_configs': False, + }, + }, + }, DEFAULTS, DONE diff --git a/nodes/htz/ex42-1048908.py b/nodes/htz/ex42-1048908.py index b6f8bd8..410c400 100644 --- a/nodes/htz/ex42-1048908.py +++ b/nodes/htz/ex42-1048908.py @@ -1,8 +1,10 @@ nodes['htz.ex42-1048908'] = { 'bundles': [ + 'mx-puppet-discord', 'nginx', 'nodejs', 'riot-web', + 'postgresql', 'vmhost', 'voc-loudness-monitor', ], @@ -20,6 +22,20 @@ nodes['htz.ex42-1048908'] = { }, }, }, + 'mx-puppet-discord': { + 'homeserver': { + 'domain': 'franzi.business', + 'url': 'http://[::1]:8008', + }, + 'database': { + 'user': 'mx-puppet-discord', + 'password': vault.password_for('htz.ex42.1048908 postgres mx-puppet-discord'), + 'database': 'mx-puppet-discord', + }, + 'allowed-users': { + '@.*:franzi\\\\.business', + }, + }, 'riot-web': { 'url': 'chat.franzi.business', 'config': { @@ -34,6 +50,18 @@ nodes['htz.ex42-1048908'] = { 'permalinkPrefix': 'https://chat.franzi.business', }, }, + 'postgresql': { + 'users': { + 'mx-puppet-discord': { + 'password': vault.password_for('htz.ex42.1048908 postgres mx-puppet-discord'), + }, + }, + 'databases': { + 'mx-puppet-discord': { + 'owner': 'mx-puppet-discord', + }, + }, + }, 'users': { 'feli': { 'ssh_pubkey': [