cjvt-valency/README.md

225 lines
5.6 KiB
Markdown
Raw Normal View History

# cjvt-valency
2019-03-17 16:25:59 +00:00
Required submodules:
* `https://gitea.cjvt.si/kristjan/cjvt-corpusparser.git`
```bash
$ git submodule init
2019-03-23 19:27:23 +00:00
$ git submodule update
2019-03-17 16:25:59 +00:00
```
2019-03-07 08:00:01 +00:00
## Components
### Credentials
Copy `env.default` to `env.local` (gitignored).
Modify database credentials in `env.local`.
The file is used by `make`.
2019-03-07 08:00:01 +00:00
### Database (2 containers)
Set db admin, user, pass, etc in 'Makefile'.
2019-03-23 19:27:23 +00:00
Spin up the database service and create users:
2019-04-05 14:45:40 +00:00
Make sure you create a folder for the data on host machine (see `mongodb-stack.yml` `volumes`.
2019-03-17 16:25:59 +00:00
```bash
2019-04-05 14:45:40 +00:00
$ mkdir -p ${HOME}/mongo_container/data/ # default one
# $ make database-clean # opt, removes docker services, not data
2019-03-17 16:25:59 +00:00
$ make database-service
$ make database-users # only first time; user data persists too
2019-03-17 16:25:59 +00:00
```
Populate the database with data form files:
2019-03-07 08:00:01 +00:00
* ssj500k.xml
* kres.xml
* kres_SRL.json
2019-03-17 16:25:59 +00:00
Set path to files in `Makefile`.
```bash
# spin up a container with python env
$ make python-env
2019-03-07 08:00:01 +00:00
2019-03-17 16:25:59 +00:00
# install our packages
$ make python-env-install
2019-03-07 08:00:01 +00:00
2019-03-17 16:25:59 +00:00
# run the code
2019-04-13 22:26:15 +00:00
# beforehand, set the data files in Makefile
2019-04-21 11:42:17 +00:00
# instead of mounting directories into the container, you can
# create a link inside ./data, that points to the desired location
2019-04-21 17:18:40 +00:00
# I've separated the processes for better memory management
$ make fill-database-ssj
$ make fill-database-kres
# You can detach from the running process using Ctrl-p + Ctrl-q
2019-04-21 11:14:34 +00:00
# this is a long operation
# if running on a remote server, use nohup:
$ nohup $(make fill-database > fill-database.log) &
2019-03-17 16:25:59 +00:00
```
2019-03-07 08:00:01 +00:00
If all goes well, we should be able to inspect the database, filled with corpora, on `0.0.0.0:8087`.
2019-03-07 08:00:01 +00:00
### Flask backend (1 container)
Relies heavily on the database. Set that up first.
```bash
# spin up container
2019-03-28 18:17:45 +00:00
$ make python-env
# install our packages
$ make python-env-install
# needs to be ran once to modify a new database
$ make backend-prepare-db
2019-04-13 22:26:15 +00:00
2019-04-28 19:59:20 +00:00
# if you have the file prepared (sskj_senses.json), you can
# fill the database with some senses
$ make sskj-senses
# with debugger
$ make backend-dev
2019-04-06 17:38:36 +00:00
# production
$ make backend-prod
```
2019-03-07 08:00:01 +00:00
API endpoints:
* GET word list (pre-cached)
* GET reduced frames (pre-cached)
* POST senses
* User auth logic
### Vue frontend (1 container)
Relies on Flask backend.
Before running `make`, you might need to set the correct api address.
Check `./src/frontend_vue/config/config_prod.json`.
bash
```
# $ make frontend-dev # development
$ make frontend-prod
```
2019-03-07 08:00:01 +00:00
App available on: `http://0.0.0.0:8080`.
2019-05-05 13:50:48 +00:00
## Production deployment
Prerequisite: machine with free ports 80 and 8084.
### Database
Either build the database from scratch (lenghty process) using above instructions or just migrate the database from the faculty server (recommended).
2019-05-06 21:13:10 +00:00
Build container my-mongo:
```bash
# run once and destroy containers
$ make database-service
```
2019-05-05 13:50:48 +00:00
### Backend
Set database connection details in `/src/backend_flask/db_config.py`.
2019-05-06 21:13:10 +00:00
Change 'valuser' and 'valuserpass' to the database user.
```bash
mongodb://valuser:valuserpass@my_mongo/valdb
2019-05-05 13:50:48 +00:00
```
In the above line, replace `valuser` with the username and `valuserpass` with the password that was used to create the database tables (the values were set in the root Makefile).
You can also set the number of workers in `/src/backend_flask/entrypoint.sh`.
In line with `gunicorn -t 4 -b 127.0.0.1:8084 app:app`, edit the `-t` parameter.
Rule of thumb is 2x number of available CPU cores.
Build the backend container:
```bash
# From git root
$ make build-backend-flask
```
### Frontend
Set the server address (where backend will be runnig) in `src/frontend_vue/config/config_prod.json`.
Build the `/dist` folder that contains the static app (we will be using Nginx to serve it).
```bash
# From git root
$ make build-frontend-prod
```
All set, now run the stack.
2019-05-06 21:13:10 +00:00
Stack configuration in `production.yaml`.
2019-05-05 13:50:48 +00:00
```bash
# From git root
$ make deploy-prod-stack
2019-05-06 20:10:33 +00:00
```
2019-05-06 21:13:10 +00:00
## Uploading a mongo dump
2019-05-06 20:10:33 +00:00
There's a 15GB mongo dump containing the fully processed kres and ssj data.
We can use that file to deploy our aplication.
2019-05-06 21:13:10 +00:00
With this database, we will need a minimum of 8GB ram to serve the app.
If the server is struggling, frontend will throw "Network errors".
2019-05-06 20:10:33 +00:00
Check `0.0.0.0:8081` and remove (or backup) the current example database `valdb`.
Run the stack with mongo port mapped:
(uncomment the lines in `production.yaml`)
```yml
ports:
- 27017:27017
```
Run a separate my-mongo container with the mounted data:
```bash
$ mongo run -it --net host -v <local_dump_path>/dumps my-mongo /bin/bash
```
Inside the container (edit the uesrname, password):
```bash
$ mongorestore /dumps/valdb --db valdb --uri=mongodb://valuser:valuserpass@0.0.0.0:27017
```
After uploading, restart the stack with `27017` commented out.
2020-09-15 12:08:16 +00:00
## Script running
2020-09-15 12:08:16 +00:00
### Environment setup
```bash
pip install -r requirements.txt
pip install git+https://gitea.cjvt.si/ozbolt/luscenje_struktur.git
pip install git+https://gitea.cjvt.si/kristjan/cjvt-corpusparser.git
```
### Running on already setup environment
2020-09-15 12:08:16 +00:00
```bash
make database-service
```
2020-11-23 10:24:50 +00:00
### Setting up environment for running on ramdisk
```bash
# create ramdisk
sudo mount -t tmpfs tmpfs /mnt/tmp
sudo mount -o remount,size=120G,noexec,nosuid,nodev,noatime /mnt/tmp
# change volumes to /mnt/tmp:/data/db
2020-11-23 10:24:50 +00:00
vim dockerfiles/database/valency-stack.yml
# change Makefile -runStack to mkdir -p /mnt/tmp
2020-11-23 10:24:50 +00:00
vim dockerfiles/database/Makefile
2020-11-23 10:24:50 +00:00
# run service
make database-service
2020-11-23 10:24:50 +00:00
# run ONLY ONCE to create users and restore database
make database-users
2020-11-23 10:24:50 +00:00
make database-restore
2020-11-23 10:24:50 +00:00
# double check if it worked
docker exec -it ef0a /bin/bash
# following steps in docker bash:
# check if it worked by
mongo --username <REGULAR USER> --password --authenticationDatabase valdb
2020-11-23 10:24:50 +00:00
db.getRoles()
```