Added folders as well...
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
from pypy:3-6
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Bundle app source
|
||||
COPY app.py /usr/src/app
|
||||
COPY requirements.txt /usr/src/app
|
||||
|
||||
RUN apt-get update
|
||||
|
||||
RUN apt-get install -y vim
|
||||
|
||||
# install requirements
|
||||
RUN pip install --upgrade pip
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
RUN mkdir -p /usr/src/logs
|
||||
|
||||
|
||||
EXPOSE 611
|
||||
|
||||
VOLUME ["/usr/src/app"]
|
||||
|
||||
ENTRYPOINT ["pypy3", "app.py"]
|
||||
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
from flask import Flask
|
||||
from redis.sentinel import Sentinel
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
sentinelHost = os.environ.get("SENTINEL_HOST", None)
|
||||
sentinelPort = int(os.environ.get("SENTINEL_PORT", 26379))
|
||||
redisMasterName = os.environ.get("REDIS_MASTER_NAME", 'mymaster')
|
||||
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
if sentinelHost is not None and sentinelPort is not None:
|
||||
try:
|
||||
sentinel = Sentinel([(sentinelHost, sentinelPort)], socket_timeout=0.1)
|
||||
redis_master = sentinel.master_for(redisMasterName, socket_timeout=0.1)
|
||||
redis_slave = sentinel.slave_for(redisMasterName, socket_timeout=0.1)
|
||||
|
||||
incr_and_return_count = redis_master.incr('hits')
|
||||
count_from_slave = redis_slave.get('hits')
|
||||
return 'Hello World! I have been seen {} times. Yes Yeah\n'.format(count_from_slave)
|
||||
except Exception as e:
|
||||
return sentinelHost+ " "+ str(sentinelPort) + 'Exception handled when started to perform actions: Details error {}\n'.format(e)
|
||||
else:
|
||||
return 'Environment variable sentinelHost or sentinelPort is not found or empty. \n'
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=611, debug=True)
|
||||
@@ -0,0 +1,7 @@
|
||||
version: "3.3"
|
||||
services:
|
||||
agile-python-app:
|
||||
image: 127.0.0.1:5000/agile-python-app
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: ./Dockerfile.yml
|
||||
@@ -0,0 +1,2 @@
|
||||
flask
|
||||
redis
|
||||
Reference in New Issue
Block a user