add Dockerfile

This commit is contained in:
2021-01-15 17:03:33 +01:00
parent e031660df9
commit b9031157fb
6 changed files with 37 additions and 52 deletions

33
tools/ws/Dockerfile Normal file
View File

@ -0,0 +1,33 @@
FROM python:latest
LABEL Maintainer="Wolfgang Hottgenroth wolfgang.hottgenroth@icloud.com"
ARG APP_DIR="/opt/app"
RUN \
apt update && \
apt install -y libmariadbclient-dev && \
pip3 install mariadb && \
pip3 install connexion && \
pip3 install connexion[swagger-ui] && \
pip3 install uwsgi && \
pip3 install flask-cors
RUN \
mkdir -p ${APP_DIR} && \
useradd -d ${APP_DIR} -u 1000 user
COPY *.py ${APP_DIR}/
COPY swagger.yaml ${APP_DIR}/
COPY server.ini ${APP_DIR}/
USER 1000:1000
WORKDIR ${APP_DIR}
EXPOSE 5000
EXPOSE 9191
CMD [ "uwsgi", "server.ini" ]

View File

@ -1,5 +1,4 @@
from dbpool import getConnection from dbpool import getConnection
from heroes_mock import HEROES
def get_heroes(): def get_heroes():
try: try:

View File

@ -1,47 +0,0 @@
HEROES = [
{ "id": 1, "name": "Wolfgang" },
{ "id": 2, "name": "Andreas" },
{ "id": 3, "name": "Frank" },
{ "id": 4, "name": "Thomas" },
{ "id": 5, "name": "Barbara" },
{ "id": 6, "name": "Robert" },
{ "id": 7, "name": "Raphael" },
{ "id": 8, "name": "Lucia" },
{ "id": 9, "name": "Gregor" },
]
def get_heroes():
if HEROES:
return HEROES
else:
return 'No heroes available', 404
def get_hero(id=None):
try:
hero = next(x for x in HEROES if x["id"] == id)
return { "id": hero["id"], "name": hero["name"] }
except StopIteration:
return 'Hero not found', 404
def put_hero(id=None, hero=None):
try:
heroToUpdate = next(x for x in HEROES if x["id"] == id)
checkNewName = next((x for x in HEROES if x["name"] == hero["name"]), None)
if (checkNewName):
return 'Duplicate name', 403
heroToUpdate["name"] = hero["name"]
return 'Hero updated', 200
except StopIteration:
return 'Hero not found', 404
except Exception:
return 'Some error', 403
def post_hero(hero=None):
try:
newHeroId = len(HEROES)
hero["id"] = newHeroId
HEROES.append(hero)
return 'Hero inserted', 201
except Exception:
return 'Some error', 403

View File

@ -1,7 +1,7 @@
[uwsgi] [uwsgi]
http = :5000 http = :5000
wsgi-file = server.py wsgi-file = server.py
processes = 1 processes = 4
threads = 1 threads = 2
stats = 127.0.0.1:9191 stats = :9191

View File

@ -7,7 +7,7 @@ paths:
/greeting/hello: /greeting/hello:
get: get:
tags: [ "greeting" ] tags: [ "greeting" ]
operationId: api.say_hello operationId: greeting.say_hello
summary: Returns a greeting summary: Returns a greeting
parameters: parameters:
- name: name - name: name