working on ansible role, fixing switch from bridgeRepository to slackBridgeRepository and etc

This commit is contained in:
sneakers-the-rat 2023-08-07 15:11:47 -07:00
parent bcc032413c
commit d43add046d
13 changed files with 176 additions and 19 deletions

View file

@ -1,6 +1,5 @@
export interface bridgeType {
Label: string;
Protocol: string;
team_name: string;
id: string;
}

View file

@ -30,8 +30,6 @@ MATTERBRIDGE_CONFIG_DIR=
# Slack -----------------
SLACK_CLIENT_ID=
SLACK_CLIENT_SECRET=
SLACK_SIGNING_SECRET=
SLACK_STATE_SECRET=
# Discord ----------------
DISCORD_TOKEN=

View file

@ -5,19 +5,44 @@ CHATBRIDGE_MODE: development
# development options
chatbridge_webpack_port: 8080
# general options
chatbridge_user: chatbridge
chatbridge_user_home: /var/lib/chatbridge
chatbridge_log_dir: /var/lib/chatbridge/logs
chatbridge_matterbridge_binary: /var/lib/chatbridge/matterbridge
chatbridge_matterbridge_configs: /var/lib/chatbridge/configs
# directory that the public web content should be deployed to on build
chatbridge_public_dir: /var/www/html/chatbridge
# public URL used in discord API callbacks
chatbridge_base_url: CHANGEME
# admin token used to create groups
chatbridge_admin_token: CHANGEME
# postgres config
chatbridge_postgres_user: chatbridge
chatbridge_postgres_password: CHANGEME
chatbridge_postgres_db: chatbridge
chatbridge_postgres_port: 6500
chatbridge_user: chatbridge
chatbridge_user_home: /var/lib/chatbridge
# slack config
chatbridge_slack_client_id: CHANGEME
chatbridge_slack_client_secret: CHANGEME
# discord config
chatbridge_discord_token: CHANGEME
chatbridge_discord_client_id: CHANGEME
chatbridge_discord_client_secret: CHANGEME
# Where, beneath the root domain, we should host the site
# (used in nginx configs)
# (used in nginx configs, distinct from baseurl, which is used by discord)
chatbridge_fqdn: localhost
chatbridge_webroot: ""
chatbridge_api_port: 8999
# false gives you an http-only nginx config
chatbridge_https: true

View file

@ -8,4 +8,40 @@
register: command_result
failed_when: "command_result.failed and 'Local modifications' not in command_result.msg"
- name: ensure npm present
become: yes
apt:
name: npm
state: present
- name: ensure yarn present
become: yes
npm:
global: true
name: yarn
- name: install yarn dependencies
become: yes
become_user: "{{ chatbridge_user }}"
community.general.yarn:
path: "{{chatbridge_user_home }}/chatbridge"
- name: build package
become: yes
become_user: "{{ chatbridge_user }}"
shell:
chdir: "{{ chatbridge_user_home }}/chatbridge"
cmd: npm run build
creates: "{{ chatbridge_user_home }}/chatbridge/server/dist"
- name: copy client to public directory
become: yes
copy:
remote_src: true
src: "{{ chatbridge_user_home }}/chatbridge/client/dist/"
dest: "{{ chatbridge_public_dir }}"

View file

@ -5,3 +5,10 @@
fail_msg: "One or more variables are not correctly defined. Check role documentation: https://gitlab.com/nodiscc/xsrv/-/tree/master/roles/matrix_synapse"
with_items:
- chatbridge_postgres_password is not search("CHANGEME")
- chatbridge_base_url is not search("CHANGEME")
- chatbridge_admin_token is not search("CHANGEME")
- chatbridge_slack_client_id is not search("CHANGEME")
- chatbridge_slack_client_secret is not search("CHANGEME")
- chatbridge_discord_token is not search("CHANGEME")
- chatbridge_discord_client_id is not search("CHANGEME")
- chatbridge_discord_client_secret is not search("CHANGEME")

View file

@ -3,7 +3,7 @@
become_user: "{{ chatbridge_user }}"
template:
src: chatbridge_env.j2
dest: "{{ chatbridge_user_home}}/.env"
dest: "{{ chatbridge_user_home}}/chatbridge/server/.env"
mode: "600"
- name: create https nginx config
@ -35,3 +35,22 @@
src: /etc/nginx/sites-available/chatbridge.conf
dest: /etc/nginx/sites-enabled/chatbridge.conf
- name: create systemd service
become: yes
template:
src: systemd_chatbridge.service.j2
dest: /etc/systemd/system/chatbridge.service
- name: enable service
become: yes
service:
name: chatbridge
enabled: yes
state: started
- name: restart service
become: yes
service:
name: chatbridge
state: restarted

View file

@ -11,6 +11,9 @@
- name: install chatbridge
import_tasks: chatbridge.yml
- name: install matterbridge
import_tasks: matterbridge.yml
- name: configure chatbridge
import_tasks: config.yml

View file

@ -0,0 +1,16 @@
- name: Get Latest matterbridge version info
uri:
url: https://api.github.com/repos/42wim/matterbridge/releases/latest
return_content: true
register: matterbridge_latest
- name: Download matterbridge binary
become: yes
become_user: "{{ chatbridge_user }}"
loop: "{{ matterbridge_latest.json.assets }}"
when:
- "'linux-64bit' in item.name"
get_url:
url: "{{ item.browser_download_url }}"
dest: "{{ chatbridge_matterbridge_binary }}"
creates: "{{ chatbridge_matterbridge_binary }}"

View file

@ -13,6 +13,21 @@
home: "{{ chatbridge_user_home }}"
system: true
- name: create chatbridge log directory
become: yes
file:
mode: '700'
state: directory
owner: "{{ chatbridge_user }}"
path: "{{ chatbridge_log_dir }}"
- name: create chatbridge matterbridge config directory
become: yes
file:
mode: '700'
state: directory
owner: "{{ chatbridge_user }}"
path: "{{ chatbridge_matterbridge_configs }}"
- name: Create public directory and give permissions to www-data
@ -22,12 +37,12 @@
state: directory
group: "www-data"
owner: "{{ chatbridge_user }}"
path: "{{ chatbridge_user_home }}/public"
path: "{{ chatbridge_public_dir }}"
- name: Chmod home directory
become: yes
file:
mode: '755'
mode: '700'
state: directory
group: "www-data"
path: "{{ chatbridge_user_home }}"

View file

@ -1,9 +1,40 @@
PORT={{ chatbridge_api_port }}
NODE_ENV=development
NODE_ENV={{ CHATBRIDGE_MODE }}
NODE_CONFIG_DIR={{ chatbridge_user_home}}/chatbridge/server/config
LOG_DIR={{ chatbridge_log_dir }}
# Full URL that chatbridge is hosted at, including any sub-paths
# Used in the discord handler to generate an OAUTH2 callback URL
BASE_URL={{ chatbridge_base_url }}
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT={{ chatbridge_postgres_port }}
POSTGRES_USER={{ chatbridge_postgres_user }}
POSTGRES_PASSWORD={{ chatbridge_postgres_password }}
POSTGRES_DB={{ chatbridge_postgres_db }}
# Used to log in to create and manage groups
ADMIN_TOKEN={{ chatbridge_admin_token }}
# Keys used to sign cookies used for authentication
COOKIE_KEY_1={{ lookup('community.general.random_string', base64=True, length=24) }}
COOKIE_KEY_2={{ lookup('community.general.random_string', base64=True, length=24) }}
# Location of the matterbridge binary!
MATTERBRIDGE_BINARY={{ chatbridge_matterbridge_binary }}
MATTERBRIDGE_CONFIG_DIR={{ chatbridge_matterbridge_configs }}
# ---------------
## Platforms
# ---------------
# Slack -----------------
SLACK_CLIENT_ID={{ chatbridge_slack_client_id }}
SLACK_CLIENT_SECRET={{ chatbridge_slack_client_secret }}
# Discord ----------------
DISCORD_TOKEN={{ chatbridge_discord_token }}
DISCORD_CLIENT_ID={{ chatbridge_discord_client_id }}
DISCORD_CLIENT_SECRET={{ chatbridge_discord_client_secret }}

View file

@ -15,15 +15,10 @@ server {
{% else %}
location {{ chatbridge_webroot }} {
root {{ chatbridge_user_home }}/public;
root {{ chatbridge_public_dir }};
try_files $uri $uri/ $uri/index.html /index.html index.html;
}
location {{ chatbridge_webroot }}/ {
rewrite ^{{ chatbridge_webroot }}?(/.*)$ $1 break;
root {{ chatbridge_user_home }}/public;
try_files $uri $uri/ $uri/index.html =404;
}
{% endif %}
}

View file

@ -0,0 +1,14 @@
[Unit]
Description=Chatbridge
[Service]
ExecStart=/usr/local/bin/node {{ chatbridge_user_home }}/chatbridge/server/dist/src/app.js
Restart=always
User={{ chatbridge_user }}
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory={{ chatbridge_user_home }}/chatbridge/server/dist/src/
[Install]
WantedBy=multi-user.target

View file

@ -16,7 +16,6 @@ export const getBridgeHandler = async(
select: {
Protocol: true,
Label: true,
team_name: true,
id: true
}
})
@ -63,4 +62,4 @@ export const setBridgeHandler = async(
message: 'No state token found'
})
}
}
}