Basic ansible role for installation and some skeleton structure for the server app
This commit is contained in:
parent
8782834c04
commit
84752f1b30
29 changed files with 8314 additions and 67 deletions
17
.gitignore
vendored
17
.gitignore
vendored
|
@ -129,3 +129,20 @@ dist
|
||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
|
|
||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# ucla-chat
|
# chatbridge
|
||||||
|
|
||||||
Invite people to a bridged nextcloud chat with a token
|
Invite people to a bridged nextcloud chat with a token
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@ Use the ansible role!!!
|
||||||
## References
|
## References
|
||||||
|
|
||||||
idk i'm just learnin
|
idk i'm just learnin
|
||||||
|
|
||||||
|
- https://typeorm.io/active-record-data-mapper#what-is-the-active-record-pattern
|
||||||
|
- https://typeorm.io/example-with-express
|
||||||
- https://github.com/wpcodevo/node_typeorm/tree/restapi-node-typeorm
|
- https://github.com/wpcodevo/node_typeorm/tree/restapi-node-typeorm
|
||||||
- https://www.axllent.org/docs/nodejs-service-with-systemd/
|
- https://www.axllent.org/docs/nodejs-service-with-systemd/
|
||||||
- https://github.com/wpcodevo/Blog_MUI_React-hook-form/tree/login-signup-form
|
- https://github.com/wpcodevo/Blog_MUI_React-hook-form/tree/login-signup-form
|
||||||
|
|
10
config/defaults.ts
Normal file
10
config/defaults.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
export default {
|
||||||
|
port: '8999',
|
||||||
|
postgresConfig: {
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: '6500',
|
||||||
|
username: 'POSTGRES_USER',
|
||||||
|
password: 'POSTGRES_PASSWORD',
|
||||||
|
database: 'POSTGRES_DB',
|
||||||
|
},
|
||||||
|
}
|
8
example.env
Normal file
8
example.env
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
PORT=8999
|
||||||
|
NODE_ENV=development
|
||||||
|
|
||||||
|
POSTGRES_HOST=127.0.0.1
|
||||||
|
POSTGRES_PORT=6500
|
||||||
|
POSTGRES_USER=
|
||||||
|
POSTGRES_PASSWORD=
|
||||||
|
POSTGRES_DB=
|
11
galaxy.yml
Normal file
11
galaxy.yml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
namespace: "sneakers_the_rat"
|
||||||
|
name: "chatbridge"
|
||||||
|
version: 0.1.0
|
||||||
|
readme: README.md
|
||||||
|
authors: ["Jonny Saunders <j@nny.fyi>"]
|
||||||
|
description: Ansible roles for managing chatbridge!
|
||||||
|
repository: https://git.jon-e.net/jonny/chatbridge
|
||||||
|
|
||||||
|
manifest:
|
||||||
|
directives:
|
||||||
|
- graft roles
|
15
package.json
15
package.json
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "ucla-chat",
|
"name": "chatbridge",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "bridging a bunch of chats together",
|
"description": "bridging a bunch of chats together",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
@ -12,10 +12,14 @@
|
||||||
"typeorm": "typeorm-ts-node-commonjs",
|
"typeorm": "typeorm-ts-node-commonjs",
|
||||||
"migrate": "rm -rf build && yarn build && yarn typeorm migration:generate ./src/migrations/added-user-entity -d ./src/utils/data-source.ts",
|
"migrate": "rm -rf build && yarn build && yarn typeorm migration:generate ./src/migrations/added-user-entity -d ./src/utils/data-source.ts",
|
||||||
"db:push": "rm -rf build && yarn build && yarn typeorm migration:run -d src/utils/data-source.ts",
|
"db:push": "rm -rf build && yarn build && yarn typeorm migration:run -d src/utils/data-source.ts",
|
||||||
"importData": "npx ts-node-dev --transpile-only --exit-child src/data/seeder.ts"
|
"importData": "npx ts-node-dev --transpile-only --exit-child src/data/seeder.ts",
|
||||||
|
"client_start": "react-scripts start",
|
||||||
|
"client_build": "react-scripts build",
|
||||||
|
"client_eject": "react-scripts eject"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@slack/oauth": "^2.6.1",
|
"@slack/oauth": "^2.6.1",
|
||||||
|
"config": "^3.3.9",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
|
@ -26,6 +30,7 @@
|
||||||
"pug": "^3.0.2",
|
"pug": "^3.0.2",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
"react-scripts": "^5.0.1",
|
||||||
"redis": "^4.6.7",
|
"redis": "^4.6.7",
|
||||||
"typeorm": "^0.3.17",
|
"typeorm": "^0.3.17",
|
||||||
"typescript": "^5.1.6",
|
"typescript": "^5.1.6",
|
||||||
|
@ -40,5 +45,11 @@
|
||||||
"@types/pug": "^2.0.6",
|
"@types/pug": "^2.0.6",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"ts-node-dev": "^2.0.0"
|
"ts-node-dev": "^2.0.0"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": [
|
||||||
|
"react-app",
|
||||||
|
"react-app/jest"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
roles/chatbridge/defaults/main.yml
Normal file
17
roles/chatbridge/defaults/main.yml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
# defaults file for chatbridge
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# Where, beneath the root domain, we should host the site
|
||||||
|
# (used in nginx configs)
|
||||||
|
chatbridge_fqdn: localhost
|
||||||
|
chatbridge_webroot: ""
|
||||||
|
chatbridge_api_port: 8999
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
galaxy_info:
|
galaxy_info:
|
||||||
author: your name
|
author: Jonny Saunders
|
||||||
description: your role description
|
description: Install chatbridge :)
|
||||||
company: your company (optional)
|
|
||||||
|
|
||||||
# If the issue tracker for your role is not on github, uncomment the
|
# If the issue tracker for your role is not on github, uncomment the
|
||||||
# next line and provide a value
|
# next line and provide a value
|
||||||
|
@ -14,7 +13,7 @@ galaxy_info:
|
||||||
# - GPL-3.0-only
|
# - GPL-3.0-only
|
||||||
# - Apache-2.0
|
# - Apache-2.0
|
||||||
# - CC-BY-4.0
|
# - CC-BY-4.0
|
||||||
license: license (GPL-2.0-or-later, MIT, etc)
|
license: AGPL-3.0-or-later
|
||||||
|
|
||||||
min_ansible_version: 2.1
|
min_ansible_version: 2.1
|
||||||
|
|
10
roles/chatbridge/tasks/chatbridge.yml
Normal file
10
roles/chatbridge/tasks/chatbridge.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
- name: clone repository
|
||||||
|
become: yes
|
||||||
|
become_user: "{{ chatbridge_user }}"
|
||||||
|
git:
|
||||||
|
repo: https://git.jon-e.net/jonny/chatbridge
|
||||||
|
dest: "{{ chatbridge_user_home }}/chatbridge"
|
||||||
|
version: "HEAD"
|
||||||
|
failed_when: "command_result.failed and 'Local modifications' not in command_result.msg"
|
||||||
|
|
||||||
|
|
24
roles/chatbridge/tasks/config.yml
Normal file
24
roles/chatbridge/tasks/config.yml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
- name: create development .env
|
||||||
|
become: yes
|
||||||
|
become_user: "{{ chatbridge_user }}"
|
||||||
|
template:
|
||||||
|
src: chatbridge_env.j2
|
||||||
|
dest: "{{ chatbridge_user_home}}/.env"
|
||||||
|
|
||||||
|
- name: create nginx config
|
||||||
|
become: yes
|
||||||
|
template:
|
||||||
|
src: nginx_chatbridge.conf.j2
|
||||||
|
dest: /etc/nginx/sites-available/chatbridge.conf
|
||||||
|
|
||||||
|
- name: link nginx config
|
||||||
|
become: yes
|
||||||
|
file:
|
||||||
|
state: link
|
||||||
|
src: /etc/nginx/sites-available/chatbridge.conf
|
||||||
|
dest: /etc/nginx/sites-enabled/chatbridge.conf
|
||||||
|
|
||||||
|
- name: restart nginx
|
||||||
|
service:
|
||||||
|
name: nginx
|
||||||
|
state: restarted
|
16
roles/chatbridge/tasks/main.yml
Normal file
16
roles/chatbridge/tasks/main.yml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
- name: include variable checks
|
||||||
|
import_tasks: checks.yml
|
||||||
|
|
||||||
|
- name: include user config
|
||||||
|
import_tasks: user.yml
|
||||||
|
|
||||||
|
- name: include postgres config
|
||||||
|
import_tasks: postgres.yml
|
||||||
|
|
||||||
|
- name: install chatbridge
|
||||||
|
import_tasks: chatbridge.yml
|
||||||
|
|
||||||
|
- name: configure chatbridge
|
||||||
|
import_tasks: config.yml
|
||||||
|
|
8
roles/chatbridge/templates/chatbridge_env.j2
Normal file
8
roles/chatbridge/templates/chatbridge_env.j2
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
PORT={{ chatbridge_api_port }}
|
||||||
|
NODE_ENV=development
|
||||||
|
|
||||||
|
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 }}
|
36
roles/chatbridge/templates/nginx_chatbridge.conf.j2
Normal file
36
roles/chatbridge/templates/nginx_chatbridge.conf.j2
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
server {
|
||||||
|
listen 443 ssl;
|
||||||
|
listen [::]:443 ssl;
|
||||||
|
server_name {{ chatbridge_fqdn }};
|
||||||
|
|
||||||
|
location {{ chatbridge_webroot }}/api/ {
|
||||||
|
proxy_pass http://127.0.0.1:{{ chatbridge_api_port }}/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location {{ chatbridge_webroot }}/ {
|
||||||
|
root {{ chatbridge_user_home }}/public;
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssl_certificate /etc/letsencrypt/live/{{ chatbridge_fqdn }}/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/{{ chatbridge_fqdn }}/privkey.pem;
|
||||||
|
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||||
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
|
||||||
|
server_name {{ chatbridge_fqdn }};
|
||||||
|
|
||||||
|
location /.well-known/acme-challenge {
|
||||||
|
root /var/www/letsencrypt;
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
rewrite ^ https://{{ chatbridge_fqdn }}$request_uri? permanent;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,2 +0,0 @@
|
||||||
---
|
|
||||||
# defaults file for ucla_chat
|
|
|
@ -1,2 +0,0 @@
|
||||||
---
|
|
||||||
# tasks file for ucla_chat
|
|
20
server/app.ts
Normal file
20
server/app.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
require('dotenv').config();
|
||||||
|
import express, { NextFunction, Request, Response } from 'express';
|
||||||
|
import config from 'config';
|
||||||
|
import cors from 'cors';
|
||||||
|
import { AppDataSource } from './db/data-source';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AppDataSource.initialize()
|
||||||
|
.then(async () => {
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.all('*', (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
next(new AppError(404, `Route ${req.originalUrl} not found`));
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
22
server/db/data-source.ts
Normal file
22
server/db/data-source.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
require('dotenv').config();
|
||||||
|
import 'reflect-metadata';
|
||||||
|
import { DataSource } from 'typeorm';
|
||||||
|
import config from 'config';
|
||||||
|
|
||||||
|
const postgresConfig = config.get<{
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
database: string;
|
||||||
|
}>('postgresConfig');
|
||||||
|
|
||||||
|
export const AppDataSource = new DataSource({
|
||||||
|
...postgresConfig,
|
||||||
|
type: 'postgres',
|
||||||
|
synchronize: false,
|
||||||
|
logging: false,
|
||||||
|
entities: ['server/entities/**/*.entity{.ts,.js}'],
|
||||||
|
migrations: ['server/migrations/**/*{.ts,.js}'],
|
||||||
|
// subscribers: ['server/subscribers/**/*{.ts,.js}'],
|
||||||
|
});
|
0
server/entities/group.entity.ts
Normal file
0
server/entities/group.entity.ts
Normal file
17
server/entities/model.entity.ts
Normal file
17
server/entities/model.entity.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import {
|
||||||
|
CreateDateColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
BaseEntity,
|
||||||
|
} from 'typeorm';
|
||||||
|
|
||||||
|
export default abstract class Model extends BaseEntity {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
created_at: Date;
|
||||||
|
|
||||||
|
@UpdateDateColumn()
|
||||||
|
updated_at: Date;
|
||||||
|
}
|
4
server/matterbridge/config.ts
Normal file
4
server/matterbridge/config.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/*
|
||||||
|
Creating and synchronizing the .toml configuration files for matterbridge
|
||||||
|
|
||||||
|
*/
|
5
server/matterbridge/process.ts
Normal file
5
server/matterbridge/process.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
Managing the matterbridge processes
|
||||||
|
|
||||||
|
*/
|
17
tsconfig.json
Normal file
17
tsconfig.json
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2016",
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"module": "commonjs",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"strictPropertyInitialization": false,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"outDir": "./build",
|
||||||
|
"rootDir": ".",
|
||||||
|
"include": ["server/**/*"],
|
||||||
|
"exclude": ["node_modules", "roles"]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue