2021-07-05 19:37:05 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
-->
|
|
|
|
|
2021-06-14 18:29:55 +02:00
|
|
|
# Kompetenzinventar Backend
|
2021-05-31 18:45:15 +02:00
|
|
|
|
2021-06-15 18:31:39 +02:00
|
|
|
[![Build Status](https://drone.wtf-eg.de/api/badges/kompetenzinventar/ki-backend/status.svg?ref=refs/heads/main)](https://drone.wtf-eg.de/kompetenzinventar/ki-backend)
|
2021-07-05 19:40:00 +02:00
|
|
|
[![REUSE status](https://api.reuse.software/badge/git.wtf-eg.de/kompetenzinventar/ki-backend)](https://api.reuse.software/info/git.wtf-eg.de/kompetenzinventar/ki-backend)
|
2021-06-15 18:31:39 +02:00
|
|
|
|
2021-06-06 22:25:10 +02:00
|
|
|
## Entwicklung
|
|
|
|
|
|
|
|
### Abhängigkeiten
|
|
|
|
|
|
|
|
- Python 3.8
|
|
|
|
- [Pipenv](https://github.com/pypa/pipenv)
|
|
|
|
|
2021-06-26 09:48:49 +02:00
|
|
|
|
2021-06-06 22:25:10 +02:00
|
|
|
### Entwicklungsumgebung aufbauen und starten
|
|
|
|
|
2021-06-15 18:16:23 +02:00
|
|
|
Ggf. vorher aufräumen
|
|
|
|
|
|
|
|
```
|
|
|
|
rm data/ki.sqlite
|
|
|
|
```
|
|
|
|
|
2021-06-06 22:25:10 +02:00
|
|
|
```
|
|
|
|
cp env.dev .env
|
2021-06-12 13:24:26 +02:00
|
|
|
pipenv install --dev
|
2021-06-06 22:25:10 +02:00
|
|
|
pipenv shell
|
|
|
|
flask db upgrade
|
2021-06-26 10:51:39 +02:00
|
|
|
flask seed --dev
|
2021-06-06 22:25:10 +02:00
|
|
|
flask run
|
|
|
|
```
|
|
|
|
|
|
|
|
http://localhost:5000/
|
2021-06-07 22:04:03 +02:00
|
|
|
|
2021-06-12 13:24:26 +02:00
|
|
|
|
2021-06-21 21:43:49 +02:00
|
|
|
### pre-commit einrichten
|
|
|
|
|
|
|
|
Damit mensch nicht verpeilt kaputten Code Style zu commiten,
|
|
|
|
kann pre-commit benutzt werden. Einmal im Virtualenv ausführen:
|
|
|
|
|
|
|
|
```
|
|
|
|
pre-commit install
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2021-06-26 09:48:49 +02:00
|
|
|
### `alembic` Befehle
|
2021-06-13 21:41:01 +02:00
|
|
|
|
2021-06-26 09:48:49 +02:00
|
|
|
`alembic` ist über [Flask-Migrate](https://flask-migrate.readthedocs.io/en/latest/index.html) eingebunden.
|
|
|
|
Es wird über `flask db ...` aufgerufen.
|
2021-06-13 21:41:01 +02:00
|
|
|
|
|
|
|
|
2021-06-26 09:48:49 +02:00
|
|
|
### QA
|
2021-06-15 18:16:23 +02:00
|
|
|
|
|
|
|
```
|
2021-06-26 09:48:49 +02:00
|
|
|
python -m unittest discover ki
|
2021-06-21 16:06:06 +02:00
|
|
|
|
2021-06-26 09:48:49 +02:00
|
|
|
# Code formatieren
|
2021-06-21 16:06:06 +02:00
|
|
|
yapf -i --recursive ki/
|
2021-06-26 09:48:49 +02:00
|
|
|
|
|
|
|
# Code-Style prüfen
|
|
|
|
flake8
|
2021-06-21 21:22:39 +02:00
|
|
|
```
|
2021-06-15 18:16:23 +02:00
|
|
|
|
2021-06-26 09:48:49 +02:00
|
|
|
|
2021-06-12 13:24:26 +02:00
|
|
|
### Testbenutzer
|
|
|
|
|
|
|
|
Für ein Login ohne LDAP werden die Benutzer aus der [`auth.yml`](./data/auth.yml) benutzt.
|
|
|
|
|
|
|
|
|
2021-06-14 21:55:27 +02:00
|
|
|
### Beispiel-Requests
|
2021-06-12 13:24:26 +02:00
|
|
|
|
|
|
|
Beispiele brauchen curl und jq.
|
|
|
|
|
|
|
|
```
|
|
|
|
curl -s \
|
|
|
|
-D "/dev/stderr" \
|
|
|
|
http://localhost:5000/skills?search=ph | jq
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
curl -s \
|
|
|
|
-D "/dev/stderr" \
|
|
|
|
http://localhost:5000/languages?search=fr | jq
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
curl -s \
|
|
|
|
-D "/dev/stderr" \
|
|
|
|
-X POST \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-d '{"username": "peter", "password": "geheim"}' \
|
|
|
|
http://localhost:5000/users/login | jq
|
|
|
|
```
|
|
|
|
|
2021-06-20 20:13:19 +02:00
|
|
|
```
|
|
|
|
curl -s \
|
|
|
|
-D "/dev/stderr" \
|
|
|
|
-X POST \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "Authorization: Bearer 22e6c5fc-8a5a-440e-b1f4-018deb9fd24e" \
|
|
|
|
-d '{"pronouns": "Herr Dr. Dr."}' \
|
|
|
|
http://localhost:5000/users/1/profile | jq
|
|
|
|
```
|
|
|
|
|
2021-06-13 19:41:32 +02:00
|
|
|
```
|
|
|
|
curl -s \
|
|
|
|
-D "/dev/stderr" \
|
|
|
|
-H "Authorization: Bearer 22e6c5fc-8a5a-440e-b1f4-018deb9fd24e" \
|
|
|
|
http://localhost:5000/users/1/profile
|
|
|
|
```
|
2021-07-12 21:13:12 +02:00
|
|
|
|
|
|
|
Profilsuche nach Nickname:
|
|
|
|
|
|
|
|
```
|
|
|
|
curl -s \
|
|
|
|
-D "/dev/stderr" \
|
|
|
|
-H "Authorization: Bearer 22e6c5fc-8a5a-440e-b1f4-018deb9fd24e" \
|
|
|
|
http://localhost:5000/users/profiles
|
|
|
|
```
|
2021-06-13 19:41:32 +02:00
|
|
|
|
2021-06-14 21:55:27 +02:00
|
|
|
|
|
|
|
## Docker
|
|
|
|
|
|
|
|
### Image bauen
|
|
|
|
|
|
|
|
```
|
2021-06-14 22:10:24 +02:00
|
|
|
docker build --tag ki_backed .
|
2021-06-14 21:55:27 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Container starten
|
|
|
|
|
|
|
|
Im Beispiel wird die SQLite Datenbank `./data/ki_backend.sqlite` verwendet.
|
|
|
|
|
|
|
|
DB-Datei anlegen
|
|
|
|
|
|
|
|
```
|
|
|
|
touch data/ki_docker.sqlite
|
|
|
|
chmod a+rw data/ki_docker.sqlite
|
|
|
|
```
|
|
|
|
|
|
|
|
Container starten
|
|
|
|
|
|
|
|
```
|
|
|
|
docker run \
|
|
|
|
--name=ki_backend \
|
|
|
|
-v ${PWD}/data/ki_docker.sqlite:/app/data/ki_docker.sqlite \
|
|
|
|
-e SQLALCHEMY_DATABASE_URI='sqlite:///data/ki_docker.sqlite' \
|
|
|
|
-p 5000:5000 \
|
2021-06-14 22:10:24 +02:00
|
|
|
ki_backend
|
2021-06-14 21:55:27 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Skills und Sprachen importieren
|
|
|
|
|
|
|
|
```
|
|
|
|
docker exec ki_backend sh -c "cd /app && /pyroot/bin/flask seed"
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Produktionsumgebung
|
2021-06-12 10:06:40 +02:00
|
|
|
|
|
|
|
Für die Produktionsumgebung wird [waitress](https://docs.pylonsproject.org/projects/waitress/en/latest/) benutzt.
|
|
|
|
|
|
|
|
[`run_prod.py`](./run_prod.py) führt die DB Migrationen aus und startet den Server.
|
|
|
|
|
2021-06-15 18:16:23 +02:00
|
|
|
|
2021-07-05 19:37:05 +02:00
|
|
|
## Lizenzen
|
|
|
|
|
|
|
|
Dieses Projekt erfüllt die [REUSE](https://reuse.software/) Spezifikation.
|
2021-06-07 22:04:03 +02:00
|
|
|
|
2021-07-05 19:37:05 +02:00
|
|
|
Die Lizenzen aller Dateien im Projekt können mit diesem Kommando aufgelistet werden:
|
|
|
|
|
|
|
|
```
|
|
|
|
reuse spdx
|
|
|
|
```
|