mirror of
https://github.com/docker/awesome-compose.git
synced 2025-04-26 10:43:35 +02:00
adding nginx-wsgi-flask docker-compose sample
Signed-off-by: grantbirki <grant.birkinbine@gmail.com> Signed-off-by: Grant Birkinbine <grant.birkinbine@gmail.com>
This commit is contained in:
parent
017fd26b54
commit
55225b5e5c
11 changed files with 335 additions and 0 deletions
32
nginx-wsgi-flask/flask/Dockerfile
Normal file
32
nginx-wsgi-flask/flask/Dockerfile
Normal file
|
@ -0,0 +1,32 @@
|
|||
FROM python:3.9.2-alpine
|
||||
|
||||
# upgrade pip
|
||||
RUN pip install --upgrade pip
|
||||
|
||||
# get curl for healthchecks
|
||||
RUN apk add curl
|
||||
|
||||
# permissions and nonroot user for tightened security
|
||||
RUN adduser -D nonroot
|
||||
RUN mkdir /home/app/ && chown -R nonroot:nonroot /home/app
|
||||
RUN mkdir -p /var/log/flask-app && touch /var/log/flask-app/flask-app.err.log && touch /var/log/flask-app/flask-app.out.log
|
||||
RUN chown -R nonroot:nonroot /var/log/flask-app
|
||||
WORKDIR /home/app
|
||||
USER nonroot
|
||||
|
||||
# copy all the files to the container
|
||||
COPY --chown=nonroot:nonroot . .
|
||||
|
||||
# venv
|
||||
ENV VIRTUAL_ENV=/home/app/venv
|
||||
|
||||
# python setup
|
||||
RUN python -m venv $VIRTUAL_ENV
|
||||
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
||||
RUN export FLASK_APP=app.py
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
# define the port number the container should expose
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["python", "app.py"]
|
27
nginx-wsgi-flask/flask/app.py
Normal file
27
nginx-wsgi-flask/flask/app.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from flask import Flask, request, jsonify
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
return "Hello World!"
|
||||
|
||||
@app.route('/cache-me')
|
||||
def cache():
|
||||
return "nginx will cache this response"
|
||||
|
||||
@app.route('/info')
|
||||
def info():
|
||||
|
||||
resp = {
|
||||
'connecting_ip': request.headers['X-Real-IP'],
|
||||
'proxy_ip': request.headers['X-Forwarded-For'],
|
||||
'host': request.headers['Host'],
|
||||
'user-agent': request.headers['User-Agent']
|
||||
}
|
||||
|
||||
return jsonify(resp)
|
||||
|
||||
@app.route('/flask-health-check')
|
||||
def flask_health_check():
|
||||
return "success"
|
2
nginx-wsgi-flask/flask/requirements.txt
Normal file
2
nginx-wsgi-flask/flask/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
Flask==1.1.1
|
||||
gunicorn==20.0.4
|
5
nginx-wsgi-flask/flask/wsgi.py
Normal file
5
nginx-wsgi-flask/flask/wsgi.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from app import app
|
||||
import os
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host='0.0.0.0', port=os.environ.get("FLASK_SERVER_PORT"), debug=True)
|
Loading…
Add table
Add a link
Reference in a new issue