File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ FROM python:3.7-alpine
2+ WORKDIR /code
3+ ENV FLASK_APP=app.py
4+ ENV FLASK_RUN_HOST=0.0.0.0
5+ RUN apk add --no-cache gcc musl-dev linux-headers
6+ COPY requirements.txt requirements.txt
7+ RUN pip install -r requirements.txt
8+ EXPOSE 5000
9+ COPY . .
10+ CMD ["flask" , "run" ]
Original file line number Diff line number Diff line change 1+ import time
2+ import redis
3+ from flask import Flask
4+ app = Flask (__name__ )
5+ cache = redis .Redis (host = 'redis' , port = 6379 )
6+ def get_hit_count ():
7+ retries = 5
8+ while True :
9+ try :
10+ return cache .incr ('hits' )
11+ except redis .exceptions .ConnectionError as exc :
12+ if retries == 0 :
13+ raise exc
14+ retries -= 1
15+ time .sleep (0.5 )
16+
17+ @app .route ('/' )
18+ def hello ():
19+ count = get_hit_count ()
20+ return 'Page cloud! I have been seen {} times.\n ' .format (count )
Original file line number Diff line number Diff line change 1+ version : " 3"
2+ services :
3+ web :
4+ build : .
5+ ports :
6+ - " 5000:5000"
7+ redis :
8+ image : redis:alpine
Original file line number Diff line number Diff line change 1+ flask
2+ redis
You can’t perform that action at this time.
0 commit comments