diff --git a/tools/ws/Dockerfile b/tools/ws/Dockerfile new file mode 100644 index 0000000..8a67448 --- /dev/null +++ b/tools/ws/Dockerfile @@ -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" ] + + + diff --git a/tools/ws/api.py b/tools/ws/greeting.py similarity index 100% rename from tools/ws/api.py rename to tools/ws/greeting.py diff --git a/tools/ws/heroes.py b/tools/ws/heroes.py index a5a831b..4390227 100644 --- a/tools/ws/heroes.py +++ b/tools/ws/heroes.py @@ -1,5 +1,4 @@ from dbpool import getConnection -from heroes_mock import HEROES def get_heroes(): try: diff --git a/tools/ws/heroes_mock.py b/tools/ws/heroes_mock.py deleted file mode 100644 index 25d06a9..0000000 --- a/tools/ws/heroes_mock.py +++ /dev/null @@ -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 diff --git a/tools/ws/server.ini b/tools/ws/server.ini index 2822e09..81f216b 100644 --- a/tools/ws/server.ini +++ b/tools/ws/server.ini @@ -1,7 +1,7 @@ [uwsgi] http = :5000 wsgi-file = server.py -processes = 1 -threads = 1 -stats = 127.0.0.1:9191 +processes = 4 +threads = 2 +stats = :9191 diff --git a/tools/ws/swagger.yaml b/tools/ws/swagger.yaml index 6fea90e..bbe814a 100644 --- a/tools/ws/swagger.yaml +++ b/tools/ws/swagger.yaml @@ -7,7 +7,7 @@ paths: /greeting/hello: get: tags: [ "greeting" ] - operationId: api.say_hello + operationId: greeting.say_hello summary: Returns a greeting parameters: - name: name