diff --git a/README.md b/README.md index 0160de286dfe601ae0590f0cf90d1c6ecc375628..bf886cee23896bb5aa74f94767f4e999eef12553 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,47 @@ # 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 -This assumes you run the code as user *www-data* -Do **not** checkout this code as the same user. +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 user ruining the code. the **onyl** requried writeable location is the database directory/file + checkout the code (main branch for production) cd into the directory @@ -48,8 +87,13 @@ create a runtime directory to allow the webserver to forward calls to mdkir /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] Description=Gunicorn instance to serve bgp backend fastapi app @@ -64,3 +108,15 @@ ExecStart=/srv/backend/venv/bin/gunicorn -k uvicorn.workers.UvicornWorker --bind [Install] 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 +```