Last active
March 22, 2019 03:26
-
-
Save samsulmaarif/bdb7c49bebd342195e1641ea0183b290 to your computer and use it in GitHub Desktop.
LAB 3 docker compose
This file contains hidden or 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
import time | |
import redis | |
from flask import Flask | |
app = Flask(__name__) | |
cache = redis.Redis(host='redis', port=6379) | |
def get_hit_count(): | |
retries = 5 | |
while True: | |
try: | |
return cache.incr('hits') | |
except redis.exceptions.ConnectionError as exc: | |
if retries == 0: | |
raise exc | |
retries -= 1 | |
time.sleep(0.5) | |
@app.route('/') | |
def hello(): | |
count = get_hit_count() | |
return 'Hello World! Saya sudah terlihat {} kali.\n'.format(count) | |
if __name__ == "__main__": | |
app.run(host="0.0.0.0", debug=True) |
This file contains hidden or 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
version: '3' | |
services: | |
web: | |
build: . | |
ports: | |
- "5000:5000" | |
redis: | |
image: "redis:alpine" |
This file contains hidden or 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.4-alpine | |
ADD . /code | |
WORKDIR /code | |
RUN pip install -r requirements.txt | |
CMD ["python", "app.py"] |
This file contains hidden or 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 | |
redis |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment