Go to file
Brandon Thomas 4db289c3c0 codegen db 2021-06-13 06:31:07 -04:00
.github/workflows Add docker file 2021-05-19 00:24:32 -04:00
db ban slurs from being said 2021-06-05 16:38:19 -04:00
debug synthetic IDs for TTS 2021-06-13 06:17:43 -04:00
migrations synthetic ids work (but need finishing and cleanup) 2021-06-13 06:11:18 -04:00
models Check TT2 model for validity and store file size 2021-06-07 22:56:56 -04:00
scripts rename download script 2021-05-31 14:54:21 -04:00
seed seed with new permissions 2021-06-09 22:41:22 -04:00
src synthetic ids for w2l 2021-06-13 06:30:28 -04:00
.dockerignore I needed to actually re-specify .gitignore to not pass to docker ctx 2021-05-30 13:22:57 -04:00
.env Check TT2 model for validity and store file size 2021-06-07 22:56:56 -04:00
.gitignore TTS inference queries+codegen, job/script WIP 2021-06-01 02:03:52 -04:00
Cargo.lock write redis with tts use count (needs connection config) 2021-06-13 02:56:24 -04:00
Cargo.toml write redis with tts use count (needs connection config) 2021-06-13 02:56:24 -04:00
Dockerfile simplify python install 2021-05-31 18:34:38 -04:00
README.md update docs on denying public listing on public buckets 2021-06-04 03:39:31 -04:00
codegen_database.sh add codegen cache for new queries 2021-05-24 03:21:03 -04:00
diesel.toml ignore diesel codegen 2021-05-17 20:33:08 -04:00
loc.sh sort results 2021-06-08 01:58:17 -04:00
sqlx-data.json codegen db 2021-06-13 06:31:07 -04:00

README.md

storyteller-web

This is our main user account monolith that we'll also bake other pieces into.

Local development

Setup development

Install the following libraries, and see the notes further below about MySQL on Ubuntu 20.04.

mysql-server
imagemagick

To manage the database and perform migrations, install the Rust tools diesel and sqlx.

We'll be using diesel to manage the migrations, but sqlx within the app to actually perform queries. Diesel is an ORM, which is dumb, so we use sqlx as at-compile-time typesafe SQL.

sudo apt-get install libmysqlclient-dev
cargo install sqlx-cli --no-default-features --features mysql
cargo install diesel_cli --no-default-features --features mysql

If MySql in local dev can't be connected to, reset the accounts:

https://linuxconfig.org/how-to-reset-root-mysql-mariadb-password-on-ubuntu-20-04-focal-fossa-linux

Database migrations

To reset the entire database (drop, migrate), run:

diesel database reset

To migrate at the current step and beyond:

diesel migration run

To undo migrations at the current step:

diesel migration redo

To save sqlx database state to cache file (necessary for builds):

SQLX_OFFLINE=true cargo sqlx prepare

Now that we have multiple binaries, it's required to include all the queries in the main binary so we can generate the cached queries as a single target. That's then executed with:

SQLX_OFFLINE=true cargo sqlx prepare -- --bin storyteller-web

Production

Database migrations

  1. Set DATABASE_URL in .env to the production secrets (DO NOT COMMIT!)
  2. Run diesel migration run

Actix notes

json request

async fn handler(request: web::Json<Mytype>) -> impl Responder { "whatever" }

form-multipart request

async fn handler(request: web::Form<Mytype>) -> impl Responder { "whatever" }

route parameters

#[get("/{name}")]
async fn hello(name: web::Path<String>) -> impl Responder { format!("Hi {}", name) }

TODO

  • Make all "token" types correct
  • Use correct collation for all tables
  • Install indexes on all foreign keys
  • Make sure unique indexes are correct

Notes / TODOs:

Docker builds

The repository needs to be given read access to the base docker image:

https://github.com/orgs/storytold/packages/container/docker-base-images-rust-ssl/settings

Local Nginx Proxy

Set up a local nginx to proxy to the frontend and backend so cookie issues aren't annoying

Edit, /etc/nginx/sites-enabled/storyteller

server {
    listen 80;
    server_name api.jungle.horse;
    location / {
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:12345;
        proxy_redirect off;
    }
}
server {
    listen 80;
    server_name jungle.horse;
    location / {
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:7000;
        proxy_redirect off;
    }
}

And in /etc/hosts,

127.0.0.1  jungle.horse
127.0.0.1  api.jungle.horse

Fixing dev MySql on Ubuntu 20.04

For some reason, the MySql default install on 20.04 gave me a bunch of trouble.

In retrospect, I think this is because 'root@localhost' requires sudo to access, but if this gives any trouble in the future, here's how I got around it (two full hours of distraction!)

sudo apt-get install mysql-server

# But for some reason the default password doesn't work and diesel/sqlx can't connect?

# Kill everything

sudo apt purge mysql-server mysql-client mysql-common
sudo apt autoremove
sudo mv -iv /var/lib/mysql /var/tmp/mysql-backup
sudo rm -rf /var/lib/mysql*

sudo /usr/bin/mysql_secure_installation

# still no work...

sudo systemctl stop mysql.service

# ugh, it wasn't chowned or created (both states observed in different installs)…
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

sudo mysqld_safe --skip-grant-tables --skip-networking &

mysql -u root

flush privileges;
USE mysql;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

sudo killall -u mysql
sudo systemctl restart mysql.service

# now it works
sudo mysql -u root -p

# but now I have to use "sudo" !?!?

use mysql;

CREATE USER 'storyteller'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON storyteller.* TO 'storyteller'@'localhost';

Production

Public buckets without list permission

Public buckets that deny the list action should use the following Role:

roles/storage.legacyObjectReader

See: