Michael Weimann
ace51851de
All checks were successful
continuous-integration/drone/push Build is passing
144 lines
2.5 KiB
Markdown
144 lines
2.5 KiB
Markdown
# Kompetenzinventar Backend
|
|
|
|
[![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)
|
|
|
|
## Entwicklung
|
|
|
|
### Abhängigkeiten
|
|
|
|
- Python 3.8
|
|
- [Pipenv](https://github.com/pypa/pipenv)
|
|
|
|
### Entwicklungsumgebung aufbauen und starten
|
|
|
|
Ggf. vorher aufräumen
|
|
|
|
```
|
|
rm data/ki.sqlite
|
|
```
|
|
|
|
```
|
|
cp env.dev .env
|
|
pipenv install --dev
|
|
pipenv shell
|
|
export FLASK_APP=app.py
|
|
flask db upgrade
|
|
flask seed
|
|
flask run
|
|
```
|
|
|
|
http://localhost:5000/
|
|
|
|
|
|
### Tests ausführen
|
|
|
|
```
|
|
python -m unittest discover ki
|
|
```
|
|
|
|
|
|
### Linting
|
|
|
|
```
|
|
flake8
|
|
```
|
|
|
|
|
|
### Testbenutzer
|
|
|
|
Für ein Login ohne LDAP werden die Benutzer aus der [`auth.yml`](./data/auth.yml) benutzt.
|
|
|
|
|
|
### Beispiel-Requests
|
|
|
|
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
|
|
```
|
|
|
|
```
|
|
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
|
|
```
|
|
|
|
```
|
|
curl -s \
|
|
-D "/dev/stderr" \
|
|
-H "Authorization: Bearer 22e6c5fc-8a5a-440e-b1f4-018deb9fd24e" \
|
|
http://localhost:5000/users/1/profile
|
|
```
|
|
|
|
|
|
## Docker
|
|
|
|
### Image bauen
|
|
|
|
```
|
|
docker build --tag ki_backed .
|
|
```
|
|
|
|
|
|
### 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_backend
|
|
```
|
|
|
|
Skills und Sprachen importieren
|
|
|
|
```
|
|
docker exec ki_backend sh -c "cd /app && /pyroot/bin/flask seed"
|
|
```
|
|
|
|
|
|
## Produktionsumgebung
|
|
|
|
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.
|
|
|
|
|
|
## Quellen
|
|
|
|
* [`./data/iso_639_1.csv`](https://de.wikipedia.org/wiki/Liste_der_ISO-639-1-Codes)
|
|
* [`./data/imgs/flags`](https://github.com/gosquared/flags)
|