Created
April 18, 2021 21:45
-
-
Save rhamedy/78b6d4c1720bc8c272d713b75ee85c8c to your computer and use it in GitHub Desktop.
Sample Flask App - Ping Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
app = Flask(__name__) | |
import requests | |
@app.route('/') | |
def ping_service(): | |
return 'Hello, I am ping service!' | |
@app.route('/ping') | |
def do_ping(): | |
ping = 'Ping ...' | |
response = '' | |
try: | |
response = requests.get('http://pong-service-container:5001/pong') | |
except requests.exceptions.RequestException as e: | |
print('\n Cannot reach the pong service.') | |
return 'Ping ...\n' | |
return 'Ping ... ' + response.text + ' \n' | |
if __name__ == "__main__": | |
app.run(host ='0.0.0.0', port = 5000, debug = True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.8-slim-buster | |
COPY . /app | |
WORKDIR /app | |
RUN pip install -r requirements.txt | |
ENTRYPOINT [ "python" ] | |
CMD [ "app.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Flask==0.12 | |
requests==2.25.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not work