From 4f1e50422012863102d588991b52319a94e1a53f Mon Sep 17 00:00:00 2001 From: sudkul Date: Fri, 21 Jan 2022 17:36:25 +0530 Subject: [PATCH] Add python-helloworld app --- .../python-helloworld/Dockerfile | 9 +++++ .../python-helloworld/app.py | 39 +++++++++++++++++++ .../python-helloworld/requirements.txt | 2 + .../python-helloworld/test_with_pytest.py | 3 ++ 4 files changed, 53 insertions(+) create mode 100644 Lesson-3-Containerization/python-helloworld/Dockerfile create mode 100644 Lesson-3-Containerization/python-helloworld/app.py create mode 100644 Lesson-3-Containerization/python-helloworld/requirements.txt create mode 100644 Lesson-3-Containerization/python-helloworld/test_with_pytest.py diff --git a/Lesson-3-Containerization/python-helloworld/Dockerfile b/Lesson-3-Containerization/python-helloworld/Dockerfile new file mode 100644 index 000000000..1d9946249 --- /dev/null +++ b/Lesson-3-Containerization/python-helloworld/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.8 +LABEL maintainer="Udacity" + +COPY . /app +WORKDIR /app +RUN pip install -r requirements.txt + +# command to run on container start +CMD [ "python", "app.py" ] diff --git a/Lesson-3-Containerization/python-helloworld/app.py b/Lesson-3-Containerization/python-helloworld/app.py new file mode 100644 index 000000000..7bb61145f --- /dev/null +++ b/Lesson-3-Containerization/python-helloworld/app.py @@ -0,0 +1,39 @@ +from flask import Flask +from flask import json +import logging + +app = Flask(__name__) + +@app.route('/status') +def healthcheck(): + response = app.response_class( + response=json.dumps({"result":"OK - healthy"}), + status=200, + mimetype='application/json' + ) + + app.logger.info('Status request successfull') + return response + +@app.route('/metrics') +def metrics(): + response = app.response_class( + response=json.dumps({"status":"success","code":0,"data":{"UserCount":140,"UserCountActive":23}}), + status=200, + mimetype='application/json' + ) + + app.logger.info('Metrics request successfull') + return response + +@app.route("/") +def hello(): + app.logger.info('Main request successfull') + + return "Hello World!" + +if __name__ == "__main__": + ## stream logs to a file + logging.basicConfig(filename='app.log',level=logging.DEBUG) + + app.run(host='0.0.0.0') diff --git a/Lesson-3-Containerization/python-helloworld/requirements.txt b/Lesson-3-Containerization/python-helloworld/requirements.txt new file mode 100644 index 000000000..891b7d305 --- /dev/null +++ b/Lesson-3-Containerization/python-helloworld/requirements.txt @@ -0,0 +1,2 @@ +Flask==1.1.1 +werkzeug==0.16.1 diff --git a/Lesson-3-Containerization/python-helloworld/test_with_pytest.py b/Lesson-3-Containerization/python-helloworld/test_with_pytest.py new file mode 100644 index 000000000..78dca9986 --- /dev/null +++ b/Lesson-3-Containerization/python-helloworld/test_with_pytest.py @@ -0,0 +1,3 @@ +## Define a test that will always pass successfully +def test_always_passes(): + assert True