Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# syntax=docker/dockerfile:1 | ||
FROM python:3.7-alpine | ||
WORKDIR /code | ||
ENV FLASK_APP=app.py | ||
ENV FLASK_RUN_HOST=0.0.0.0 | ||
RUN apk add --no-cache gcc musl-dev linux-headers | ||
COPY requirements.txt requirements.txt | ||
RUN pip install -r requirements.txt | ||
EXPOSE 5000 | ||
COPY . . | ||
CMD ["flask", "run"] |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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! I have been seen {} times.\n'.format(count) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3.9' | ||
services: | ||
web: | ||
build: . | ||
ports: | ||
- '5000:5000' | ||
volumes: | ||
- '.:/code' | ||
environment: | ||
FLASK_ENV: development | ||
redis: | ||
image: 'redis:alpine' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flask | ||
redis |