diff --git a/Lesson-3-Containerization/python-helloworld/Dockerfile b/Lesson-3-Containerization/python-helloworld/Dockerfile new file mode 100644 index 0000000000..1d99462494 --- /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 0000000000..7bb61145fd --- /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 0000000000..891b7d305e --- /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 0000000000..78dca99869 --- /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