2021-06-14 18:29:55 +02:00
|
|
|
# Kompetenzinventar Backend
|
2021-05-31 18:45:15 +02:00
|
|
|
|
2021-06-06 22:25:10 +02:00
|
|
|
## Entwicklung
|
|
|
|
|
|
|
|
### Abhängigkeiten
|
|
|
|
|
|
|
|
- Python 3.8
|
|
|
|
- [Pipenv](https://github.com/pypa/pipenv)
|
|
|
|
|
|
|
|
### Entwicklungsumgebung aufbauen und starten
|
|
|
|
|
|
|
|
```
|
|
|
|
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
|
2021-06-07 17:52:14 +02:00
|
|
|
export FLASK_APP=app.py
|
2021-06-06 22:25:10 +02:00
|
|
|
flask db upgrade
|
2021-06-12 13:24:26 +02:00
|
|
|
flask seed
|
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-13 21:41:01 +02:00
|
|
|
### Tests ausführen
|
|
|
|
|
|
|
|
```
|
|
|
|
python -m unittest discover ki
|
|
|
|
```
|
|
|
|
|
|
|
|
|
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-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-06-14 21:55:27 +02:00
|
|
|
|
|
|
|
## Docker
|
|
|
|
|
|
|
|
### Image bauen
|
|
|
|
|
|
|
|
```
|
|
|
|
docker build --tag ki .
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 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 \
|
|
|
|
ki
|
|
|
|
```
|
|
|
|
|
|
|
|
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-14 21:55:27 +02:00
|
|
|
## Quellen
|
2021-06-07 22:04:03 +02:00
|
|
|
|
|
|
|
* [`./data/iso_639_1.csv`](https://de.wikipedia.org/wiki/Liste_der_ISO-639-1-Codes)
|
|
|
|
* [`./data/imgs/flags`](https://github.com/gosquared/flags)
|