Skip to content

Commit

Permalink
Add python-helloworld app
Browse files Browse the repository at this point in the history
  • Loading branch information
SudKul committed Jan 21, 2022
1 parent 4766a96 commit 4f1e504
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Lesson-3-Containerization/python-helloworld/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
39 changes: 39 additions & 0 deletions Lesson-3-Containerization/python-helloworld/app.py
Original file line number Diff line number Diff line change
@@ -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')
2 changes: 2 additions & 0 deletions Lesson-3-Containerization/python-helloworld/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==1.1.1
werkzeug==0.16.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Define a test that will always pass successfully
def test_always_passes():
assert True

0 comments on commit 4f1e504

Please sign in to comment.