From 9c046b63d9333d41717b4a8a3f1f12d92c4f6577 Mon Sep 17 00:00:00 2001 From: marcsello Date: Sun, 29 Mar 2020 17:08:53 +0200 Subject: [PATCH] Created app skeleton --- Dockerfile | 14 +++++++++----- app.py | 16 ---------------- consumer_api/app.py | 28 ++++++++++++++++++++++++++++ consumer_api/db.py | 3 +++ consumer_api/views/__init__.py | 3 +++ consumer_api/views/consumers_view.py | 7 +++++++ consumer_api/views/log_view.py | 7 +++++++ consumer_api/views/sync_view.py | 7 +++++++ requirements.txt | 4 +++- 9 files changed, 67 insertions(+), 22 deletions(-) delete mode 100644 app.py create mode 100644 consumer_api/app.py create mode 100644 consumer_api/db.py create mode 100644 consumer_api/views/__init__.py create mode 100644 consumer_api/views/consumers_view.py create mode 100644 consumer_api/views/log_view.py create mode 100644 consumer_api/views/sync_view.py diff --git a/Dockerfile b/Dockerfile index 0ca2e4e..03d458c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,13 @@ -FROM python:3 +FROM python:3.8-slim -WORKDIR /app +ADD consumer_api requirements.txt /consumer_api/ +WORKDIR /consumer_api/ -COPY . ./ +ENV PIP_NO_CACHE_DIR=true +ENV TZ Europe/Budapest +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -RUN pip3 install --no-cache-dir -r requirements.txt +RUN pip3 install -r requirements.txt -CMD ["python3", "app.py"] +EXPOSE 8000 +CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"] diff --git a/app.py b/app.py deleted file mode 100644 index 4aaddda..0000000 --- a/app.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python -import sentry_sdk - -""" -Main Flask RESTful API -""" - -__author__ = "@tormakris" -__copyright__ = "Copyright 2020, GoldenPogácsa Team" -__module_name__ = "app" -__version__text__ = "1" - -sentry_sdk.init("https://0a106e104e114bc9a3fa47f9cb0db2f4@sentry.kmlabz.com/10") - -if __name__ == "__main__": - print("Producer") diff --git a/consumer_api/app.py b/consumer_api/app.py new file mode 100644 index 0000000..a1ceecf --- /dev/null +++ b/consumer_api/app.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +import sentry_sdk +from flask import Flask +import os +from db import redis_client +from views import ConsumersView, LogView, SyncView + +""" +Main Flask RESTful API +""" + +__author__ = "@tormakris" +__copyright__ = "Copyright 2020, GoldenPogácsa Team" +__module_name__ = "app" +__version__text__ = "1" + +sentry_sdk.init("https://0a106e104e114bc9a3fa47f9cb0db2f4@sentry.kmlabz.com/10") + +app = Flask(__name__) +app.config['REDIS_URL'] = os.environ['REDIS_URL'] + +redis_client.init_app(app) + +for view in [ConsumersView, LogView, SyncView]: + view.register(app, trailing_slash=False) + +if __name__ == "__main__": + app.run(debug=True) diff --git a/consumer_api/db.py b/consumer_api/db.py new file mode 100644 index 0000000..90e8358 --- /dev/null +++ b/consumer_api/db.py @@ -0,0 +1,3 @@ +from flask_redis import FlaskRedis + +redis_client = FlaskRedis() diff --git a/consumer_api/views/__init__.py b/consumer_api/views/__init__.py new file mode 100644 index 0000000..61fd946 --- /dev/null +++ b/consumer_api/views/__init__.py @@ -0,0 +1,3 @@ +from .consumers_view import ConsumersView +from .log_view import LogView +from .sync_view import SyncView \ No newline at end of file diff --git a/consumer_api/views/consumers_view.py b/consumer_api/views/consumers_view.py new file mode 100644 index 0000000..feb59ef --- /dev/null +++ b/consumer_api/views/consumers_view.py @@ -0,0 +1,7 @@ +from flask_classful import FlaskView + + +class ConsumersView(FlaskView): + + def get(self): + return "ConsumersView" diff --git a/consumer_api/views/log_view.py b/consumer_api/views/log_view.py new file mode 100644 index 0000000..fc589f4 --- /dev/null +++ b/consumer_api/views/log_view.py @@ -0,0 +1,7 @@ +from flask_classful import FlaskView + + +class LogView(FlaskView): + + def get(self): + return "LogView" \ No newline at end of file diff --git a/consumer_api/views/sync_view.py b/consumer_api/views/sync_view.py new file mode 100644 index 0000000..6f17796 --- /dev/null +++ b/consumer_api/views/sync_view.py @@ -0,0 +1,7 @@ +from flask_classful import FlaskView + + +class SyncView(FlaskView): + + def get(self): + return "SyncView" diff --git a/requirements.txt b/requirements.txt index 2be6044..b44d269 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ sentry_sdk flask -flask-redis \ No newline at end of file +flask-redis +flask-classful +gunicorn \ No newline at end of file