-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathapp.py
41 lines (31 loc) · 1014 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import socket
import uuid
from flask import Flask, render_template
from redis import Redis
from secrets import secret, SecretNotFoundError
# Create the flask application
app = Flask(__name__)
# Connect to redis and set num_requests to 0 if it doesn't exist
redis = Redis(host='redis')
redis.setnx('num_requests', 0)
# Get the id of the docker container we're running in (it's our hostname)
container_id = socket.gethostname()
# Read our example secret
try:
db_password = secret('db_password')
except SecretNotFoundError:
db_password = 'NOT SET'
@app.route('/')
def home():
# Increment the number of requests
redis.incr('num_requests')
# Display process information to the user
return render_template(
'home.html',
container_id=container_id,
num_requests=int(redis.get('num_requests')),
db_password=db_password,
)
if __name__ == '__main__':
# This will only run when using docker-compose.override.yml
app.run(debug=True, host='0.0.0.0')