Added Flask/Redis
Signed-off-by: ajeetraina <ajeetraina@gmail.com>
This commit is contained in:
parent
99d423e7dd
commit
6d2816541c
5
flask-redis/Dockerfile
Normal file
5
flask-redis/Dockerfile
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
FROM python
|
||||||
|
ADD . /code
|
||||||
|
WORKDIR /code
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
CMD python app.py
|
15
flask-redis/app.py
Normal file
15
flask-redis/app.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# compose_flask/app.py
|
||||||
|
from flask import Flask
|
||||||
|
from redis import Redis
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
redis = Redis(host='redis', port=6379)
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def hello():
|
||||||
|
redis.incr('hits')
|
||||||
|
return 'This webpage has been viewed %s time(s).' % redis.get('hits')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(host="0.0.0.0", debug=True)
|
14
flask-redis/docker-compose.yml
Normal file
14
flask-redis/docker-compose.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
version: '2'
|
||||||
|
services:
|
||||||
|
redis:
|
||||||
|
image: redislabs/redismod
|
||||||
|
ports:
|
||||||
|
- '6379:6379'
|
||||||
|
web:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "5000:5000"
|
||||||
|
volumes:
|
||||||
|
- .:/code
|
||||||
|
depends_on:
|
||||||
|
- redis
|
2
flask-redis/requirements.txt
Normal file
2
flask-redis/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
flask
|
||||||
|
redis
|
@ -1,23 +0,0 @@
|
|||||||
version: '3.6'
|
|
||||||
|
|
||||||
services:
|
|
||||||
redis:
|
|
||||||
image: redislabs/redis
|
|
||||||
ports:
|
|
||||||
- '6379:6379'
|
|
||||||
|
|
||||||
web:
|
|
||||||
build:
|
|
||||||
context: ./web/
|
|
||||||
ports:
|
|
||||||
- "5000:5000"
|
|
||||||
links:
|
|
||||||
- redis
|
|
||||||
|
|
||||||
nginx:
|
|
||||||
restart: always
|
|
||||||
build: ./nginx/
|
|
||||||
ports:
|
|
||||||
- "80:80"
|
|
||||||
links:
|
|
||||||
- web
|
|
@ -1,3 +0,0 @@
|
|||||||
FROM nginx:alpine
|
|
||||||
RUN rm /etc/nginx/conf.d/default.conf
|
|
||||||
ADD sites-enabled/app /etc/nginx/conf.d/default.conf
|
|
@ -1,14 +0,0 @@
|
|||||||
server {
|
|
||||||
|
|
||||||
listen 80;
|
|
||||||
server_name 0.0.0.0;
|
|
||||||
charset utf-8;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://web:8000;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
FROM python
|
|
||||||
|
|
||||||
COPY . /
|
|
||||||
|
|
||||||
RUN pip install -r requirements.txt && pip install gunicorn
|
|
||||||
RUN /usr/local/bin/python -m pip install --upgrade pip
|
|
||||||
ENTRYPOINT ["/start.sh"]
|
|
@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
import os
|
|
||||||
import socket
|
|
||||||
|
|
||||||
from flask import Flask
|
|
||||||
from redis import Redis
|
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
redis = Redis(host=os.environ.get('REDIS_HOST', 'redis'), port=6379)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
|
||||||
def hello():
|
|
||||||
redis.incr('hits')
|
|
||||||
return 'Hi Docker! You have seen %s times and your system is %s.\n' % (redis.get('hits'),socket.gethostname())
|
|
@ -1,16 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import multiprocessing
|
|
||||||
import os
|
|
||||||
|
|
||||||
from distutils.util import strtobool
|
|
||||||
|
|
||||||
|
|
||||||
bind = os.getenv('WEB_BIND', '0.0.0.0:8000')
|
|
||||||
accesslog = '-'
|
|
||||||
access_log_format = "%(h)s %(l)s %(u)s %(t)s '%(r)s' %(s)s %(b)s '%(f)s' '%(a)s' in %(D)sµs" # noqa: E501
|
|
||||||
|
|
||||||
workers = int(os.getenv('WEB_CONCURRENCY', multiprocessing.cpu_count() * 2))
|
|
||||||
threads = int(os.getenv('PYTHON_MAX_THREADS', 1))
|
|
||||||
|
|
||||||
reload = bool(strtobool(os.getenv('WEB_RELOAD', 'false')))
|
|
@ -1,3 +0,0 @@
|
|||||||
Flask==2.0.3
|
|
||||||
redis==4.1.4
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
gunicorn -c app/config.py app.app:app
|
|
Loading…
Reference in New Issue
Block a user