Public Repository

Last pushed: 10 months ago
Short Description
Short description is empty for this repo.
Full Description

FROM python:3.4

RUN groupadd -r uwsgi && useradd -r -g uwsgi uwsgi
RUN pip install Flask==0.10.1 uWSGI==2.0.8 requests==2.5.1 redis==2.10.3
WORKDIR /app
COPY app /app
COPY cmd.sh /

EXPOSE 9090 9191
USER uwsgi

CMD ["/cmd.sh"]

#!/bin/bash
set -e

if [ "$ENV" = 'DEV' ]; then
echo "Running Development Server"
exec python "identidock.py"
else
echo "Running Production Server"
exec uwsgi --http 0.0.0.0:9090 --wsgi-file /app/identidock.py \
--callable app --stats 0.0.0.0:9191
fi

from flask import Flask, Response, request
import requests
import hashlib
import redis

app = Flask(name)
cache = redis.StrictRedis(host='redis', port=6379, db=0)
salt = "UNIQUE_SALT"
default_name = 'Joe Bloggs'

@app.route('/', methods=['GET', 'POST'])
def mainpage():

name = default_name
if request.method == 'POST':
    name = request.form['name']

salted_name = salt + name
name_hash = hashlib.sha256(salted_name.encode()).hexdigest()
header = '<html><head><title>Identidock</title></head><body>'
body = '''<form method="POST">
          Hello <input type="text" name="name" value="{0}">
          <input type="submit" value="submit">
          </form>
          <p>You look like a:
          <img src="/monster/{1}"/>
          '''.format(name, name_hash)
footer = '</body></html>'

return header + body + footer

@app.route('/monster/<name>')
def get_identicon(name):

image = cache.get(name)
if image is None:
    print ("Cache miss", flush=True)
    r = requests.get('http://dnmonster:8080/monster/' + name + '?size=80')
    image = r.content
    cache.set(name, image)

return Response(image, mimetype='image/png')

if name == 'main':
app.run(debug=True, host='0.0.0.0')

Docker Pull Command
Owner
nanquanyuhao