add Dockerfile
This commit is contained in:
33
tools/ws/Dockerfile
Normal file
33
tools/ws/Dockerfile
Normal 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" ]
|
||||
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
from dbpool import getConnection
|
||||
from heroes_mock import HEROES
|
||||
|
||||
def get_heroes():
|
||||
try:
|
||||
|
@ -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
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user