Skip to content

Commit ae21442

Browse files
author
pagecloud
committed
Initial commit
0 parents  commit ae21442

5 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎Dockerfile‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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"]

‎README.md‎

Whitespace-only changes.

‎app.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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)

‎docker-compose.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "3"
2+
services:
3+
web:
4+
build: .
5+
ports:
6+
- "5000:5000"
7+
redis:
8+
image: redis:alpine

‎requirements.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flask
2+
redis

0 commit comments

Comments
 (0)