Skip to content
Snippets Groups Projects
Verified Commit 33b00b6b authored by hanfi's avatar hanfi
Browse files

added more docu

parent 4f86471e
No related branches found
No related tags found
1 merge request!9added more docu
This commit is part of merge request !9. Comments created here will be created in the context of that merge request.
# Chaos Parcel Serivce: Backend # Chaos Parcel Serivce: Backend
The backend is a simple FastAPI app (https://fastapi.tiangolo.com/) usign a sqlite database
## Development
To test and develop, you can run it on your computer.
check the repo out and change your workign directory into the top level
create a virtual env
```
python -m venv venv
```
activate the virtual env
```
. venv/bin/activate
```
install required dependencies
```
pip install -r requirements.txt
pip install -r requirements-dev.txt
```
for development, use the uvicorn server
```
pip install uvicorn
```
now you can run the app
```
uvicorn backend.main:app --reload
```
It will use the default setting from backend/config.py
you can override settings using a .env file in the working directory
## Deployment ## Deployment
This assumes you run the code as user *www-data* This assumes you run the code as user *www-data* and the code is checked out at /srv/backend
Do **not** checkout this code as the same user. Do **not** checkout this code as the user ruining the code. the **onyl** requried writeable location is the database directory/file
checkout the code (main branch for production) checkout the code (main branch for production)
cd into the directory cd into the directory
...@@ -48,8 +87,13 @@ create a runtime directory to allow the webserver to forward calls to ...@@ -48,8 +87,13 @@ create a runtime directory to allow the webserver to forward calls to
mdkir /run/bgp mdkir /run/bgp
chown www-data:www-data /run/bgp chown www-data:www-data /run/bgp
``` ```
on production systems you may want to create a /etc/tmpfiles.d/bgp_backend.conf
```
d /run/bgp/ 0750 www-data www-data - -
```
to create the file on boot
create a systemd service file to serve the app: create a systemd service file to serve the app in /etc/systemd/system/bgp_backend.service:
``` ```
[Unit] [Unit]
Description=Gunicorn instance to serve bgp backend fastapi app Description=Gunicorn instance to serve bgp backend fastapi app
...@@ -64,3 +108,15 @@ ExecStart=/srv/backend/venv/bin/gunicorn -k uvicorn.workers.UvicornWorker --bind ...@@ -64,3 +108,15 @@ ExecStart=/srv/backend/venv/bin/gunicorn -k uvicorn.workers.UvicornWorker --bind
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
``` ```
now you can run the app
```
systemctl daemon-reload
systemctl start bgp_backend
```
in your webserver use the socket at /run/bgp/socket to connect the webserver to the app
on nginx the backend url would look like this:
```
unix:/run/bgp/socket
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment