From 4f86471e03fc3543bb102c683c149d923a21141b Mon Sep 17 00:00:00 2001 From: hanfi <ccc@spahan.ch> Date: Wed, 20 Sep 2023 20:54:34 +0200 Subject: [PATCH] add a README --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..0160de2 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# Chaos Parcel Serivce: Backend + +## Deployment +This assumes you run the code as user *www-data* +Do **not** checkout this code as the same user. +checkout the code (main branch for production) +cd into the directory + +``` +mkdir instance +chown www-data:www-data instance +``` + +create a file .env with content +``` +# the database location relative to the repository root +database_url = "sqlite:///instance/paketshop.db" +# the url for the customer frontend (the people sending parcels) +customer_url = "https://bgp.events.ccc.de" +# the url this app will be run under +backend_url = "https://backend.bgp.events.ccc.de" +# the url for the people handling the parcels +worker_url = "https://intern.bgp.events.ccc.de" +# a shared secret for the workers +shared_secret = "{{ bgp_secrets.shared_secret }}" +# a deployment wide secret key. +# can be created with: +# python3 -c 'import os; print(os.urandom(16).hex())' +signing_key = "{{ bgp_secrets.signing_key }}" +# how long workers are logged in. +token_lifetime = "180" +``` + +create a venv and install requirements: +``` +python -m venv venv +. venv/bin/activate +pip install -r requirements.txt +``` + +We suggest to use gunicorn to server the python app, so install it +``` +pip install gunicorn +``` + +create a runtime directory to allow the webserver to forward calls to +``` +mdkir /run/bgp +chown www-data:www-data /run/bgp +``` + +create a systemd service file to serve the app: +``` +[Unit] +Description=Gunicorn instance to serve bgp backend fastapi app +After=network.target + +[Service] +User=www-data +Group=www-data +WorkingDirectory=/srv/backend +ExecStart=/srv/backend/venv/bin/gunicorn -k uvicorn.workers.UvicornWorker --bind unix:/run/bgp/socket backend.main:app + +[Install] +WantedBy=multi-user.target +``` -- GitLab