Rename services to remove "app"
This commit is contained in:
18
vote/Dockerfile
Normal file
18
vote/Dockerfile
Normal file
@ -0,0 +1,18 @@
|
||||
# Using official python runtime base image
|
||||
FROM python:2.7-alpine
|
||||
|
||||
# Set the application directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install our requirements.txt
|
||||
ADD requirements.txt /app/requirements.txt
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
# Copy our code from the current folder to /app inside the container
|
||||
ADD . /app
|
||||
|
||||
# Make port 80 available for links and/or publish
|
||||
EXPOSE 80
|
||||
|
||||
# Define our command to be run when launching the container
|
||||
CMD gunicorn app:app -b 0.0.0.0:80 --log-file - --access-logfile - --workers 4 --keep-alive 0
|
45
vote/app.py
Normal file
45
vote/app.py
Normal file
@ -0,0 +1,45 @@
|
||||
from flask import Flask, render_template, request, make_response, g
|
||||
from redis import Redis
|
||||
import os
|
||||
import socket
|
||||
import random
|
||||
import json
|
||||
|
||||
option_a = os.getenv('OPTION_A', "Cats")
|
||||
option_b = os.getenv('OPTION_B', "Dogs")
|
||||
hostname = socket.gethostname()
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def get_redis():
|
||||
if not hasattr(g, 'redis'):
|
||||
g.redis = Redis(host="redis", db=0, socket_timeout=5)
|
||||
return g.redis
|
||||
|
||||
@app.route("/", methods=['POST','GET'])
|
||||
def hello():
|
||||
voter_id = request.cookies.get('voter_id')
|
||||
if not voter_id:
|
||||
voter_id = hex(random.getrandbits(64))[2:-1]
|
||||
|
||||
vote = None
|
||||
|
||||
if request.method == 'POST':
|
||||
redis = get_redis()
|
||||
vote = request.form['vote']
|
||||
data = json.dumps({'voter_id': voter_id, 'vote': vote})
|
||||
redis.rpush('votes', data)
|
||||
|
||||
resp = make_response(render_template(
|
||||
'index.html',
|
||||
option_a=option_a,
|
||||
option_b=option_b,
|
||||
hostname=hostname,
|
||||
vote=vote,
|
||||
))
|
||||
resp.set_cookie('voter_id', voter_id)
|
||||
return resp
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host='0.0.0.0', port=80, debug=True, threaded=True)
|
3
vote/requirements.txt
Normal file
3
vote/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Flask
|
||||
Redis
|
||||
gunicorn
|
129
vote/static/stylesheets/style.css
Normal file
129
vote/static/stylesheets/style.css
Normal file
@ -0,0 +1,129 @@
|
||||
@import url(//fonts.googleapis.com/css?family=Open+Sans:400,700,600);
|
||||
|
||||
*{
|
||||
box-sizing:border-box;
|
||||
}
|
||||
html,body{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #F7F8F9;
|
||||
height: 100vh;
|
||||
font-family: 'Open Sans';
|
||||
}
|
||||
|
||||
button{
|
||||
border-radius: 0;
|
||||
width: 100%;
|
||||
height: 50%;
|
||||
}
|
||||
|
||||
button[type="submit"] {
|
||||
-webkit-appearance:none; -webkit-border-radius:0;
|
||||
}
|
||||
|
||||
button i{
|
||||
float: right;
|
||||
padding-right: 30px;
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
button.a{
|
||||
background-color: #1aaaf8;
|
||||
}
|
||||
|
||||
button.b{
|
||||
background-color: #00cbca;
|
||||
}
|
||||
|
||||
#tip{
|
||||
text-align: left;
|
||||
color: #c0c9ce;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#hostname{
|
||||
position: absolute;
|
||||
bottom: 100px;
|
||||
right: 0;
|
||||
left: 0;
|
||||
color: #8f9ea8;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
#content-container{
|
||||
z-index: 2;
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
display: table;
|
||||
padding: 10px;
|
||||
max-width: 940px;
|
||||
height: 100%;
|
||||
}
|
||||
#content-container-center{
|
||||
display: table-cell;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#content-container-center h3{
|
||||
color: #254356;
|
||||
}
|
||||
|
||||
#choice{
|
||||
transition: all 300ms linear;
|
||||
line-height: 1.3em;
|
||||
display: inline;
|
||||
vertical-align: middle;
|
||||
font-size: 3em;
|
||||
}
|
||||
#choice a{
|
||||
text-decoration:none;
|
||||
}
|
||||
#choice a:hover, #choice a:focus{
|
||||
outline:0;
|
||||
text-decoration:underline;
|
||||
}
|
||||
|
||||
#choice button{
|
||||
display: block;
|
||||
height: 80px;
|
||||
width: 330px;
|
||||
border: none;
|
||||
color: white;
|
||||
text-transform: uppercase;
|
||||
font-size:18px;
|
||||
font-weight: 700;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
text-align: left;
|
||||
padding-left: 50px;
|
||||
}
|
||||
|
||||
#choice button.a:hover{
|
||||
background-color: #1488c6;
|
||||
}
|
||||
|
||||
#choice button.b:hover{
|
||||
background-color: #00a2a1;
|
||||
}
|
||||
|
||||
#choice button.a:focus{
|
||||
background-color: #1488c6;
|
||||
}
|
||||
|
||||
#choice button.b:focus{
|
||||
background-color: #00a2a1;
|
||||
}
|
||||
|
||||
#background-stats{
|
||||
z-index:1;
|
||||
height:100%;
|
||||
width:100%;
|
||||
position:absolute;
|
||||
}
|
||||
#background-stats div{
|
||||
transition: width 400ms ease-in-out;
|
||||
display:inline-block;
|
||||
margin-bottom:-4px;
|
||||
width:50%;
|
||||
height:100%;
|
||||
}
|
49
vote/templates/index.html
Normal file
49
vote/templates/index.html
Normal file
@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{option_a}} vs {{option_b}}!</title>
|
||||
<base href="/index.html">
|
||||
<meta name = "viewport" content = "width=device-width, initial-scale = 1.0">
|
||||
<meta name="keywords" content="docker-compose, docker, stack">
|
||||
<meta name="author" content="Tutum dev team">
|
||||
<link rel='stylesheet' href="{{ url_for('static',filename='stylesheets/style.css') }}" />
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="content-container">
|
||||
<div id="content-container-center">
|
||||
<h3>{{option_a}} vs {{option_b}}!</h3>
|
||||
<form id="choice" name='form' method="POST" action="/">
|
||||
<button id="a" type="submit" name="vote" class="a" value="a">{{option_a}}</button>
|
||||
<button id="b" type="submit" name="vote" class="b" value="b">{{option_b}}</button>
|
||||
</form>
|
||||
<div id="tip">
|
||||
(Tip: you can change your vote)
|
||||
</div>
|
||||
<div id="hostname">
|
||||
Processed by container ID {{hostname}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
|
||||
|
||||
{% if vote %}
|
||||
<script>
|
||||
var vote = "{{vote}}";
|
||||
|
||||
if(vote == "a"){
|
||||
$(".a").prop('disabled', true);
|
||||
$(".a").html('{{option_a}} <i class="fa fa-check-circle"></i>');
|
||||
$(".b").css('opacity','0.5');
|
||||
}
|
||||
if(vote == "b"){
|
||||
$(".b").prop('disabled', true);
|
||||
$(".b").html('{{option_b}} <i class="fa fa-check-circle"></i>');
|
||||
$(".a").css('opacity','0.5');
|
||||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user