-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
big bang, seems to be working in docker with nginx + uwsgi + flask
- Loading branch information
1 parent
6f6da11
commit ee56949
Showing
16 changed files
with
352 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
FROM python:3.7-stretch | ||
|
||
# Copy python requirements file | ||
COPY requirements.txt /tmp/requirements.txt | ||
|
||
# install dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
python-numpy \ | ||
python-scipy \ | ||
libffi-dev \ | ||
libjpeg-turbo-progs \ | ||
python-setuptools \ | ||
python-dev \ | ||
python3-dev \ | ||
cmake \ | ||
libtiff5-dev \ | ||
libjpeg62-turbo-dev \ | ||
zlib1g-dev \ | ||
libfreetype6-dev \ | ||
liblcms2-dev \ | ||
libwebp-dev \ | ||
tcl8.6-dev \ | ||
tk8.6-dev \ | ||
python-tk \ | ||
python3-tk \ | ||
libharfbuzz-dev \ | ||
libfribidi-dev \ | ||
nginx \ | ||
uwsgi \ | ||
uwsgi-plugin-python3 \ | ||
supervisor \ | ||
&& pip3 install --upgrade pip setuptools \ | ||
&& pip3 install -r /tmp/requirements.txt \ | ||
&& apt-get clean | ||
|
||
|
||
RUN groupadd -g 999 nginx && \ | ||
useradd -r -u 999 -g nginx nginx | ||
|
||
# Copy the Nginx global conf | ||
COPY nginx.conf /etc/nginx/ | ||
# Copy the Flask Nginx site conf | ||
COPY flask-site-nginx.conf /etc/nginx/conf.d/ | ||
# Copy the base uWSGI ini file to enable default dynamic uwsgi process number | ||
COPY uwsgi.ini /etc/uwsgi/ | ||
# Custom Supervisord config | ||
COPY supervisord.conf /etc/supervisord.conf | ||
|
||
# Add app | ||
COPY ./src /src | ||
WORKDIR /src | ||
|
||
CMD ["/usr/bin/supervisord"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: '3' | ||
services: | ||
web: | ||
build: . | ||
expose: | ||
- "5000" | ||
ports: | ||
- "5000:5000" | ||
volumes: | ||
- ./:/code:cached |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
server { | ||
location / { | ||
try_files $uri @yourapplication; | ||
} | ||
location @yourapplication { | ||
include uwsgi_params; | ||
uwsgi_pass unix:///tmp/uwsgi.sock; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# based on default config of nginx 1.12.1 | ||
# Define the user that will own and run the Nginx server | ||
user nginx; | ||
# Define the number of worker processes; recommended value is the number of | ||
# cores that are being used by your server | ||
# auto will default to number of vcpus/cores | ||
worker_processes auto; | ||
|
||
# altering default pid file location | ||
pid /tmp/nginx.pid; | ||
|
||
# turn off daemon mode to be watched by supervisord | ||
daemon off; | ||
|
||
# Enables the use of JIT for regular expressions to speed-up their processing. | ||
pcre_jit on; | ||
|
||
# Define the location on the file system of the error log, plus the minimum | ||
# severity to log messages for | ||
error_log /var/log/nginx/error.log warn; | ||
|
||
# events block defines the parameters that affect connection processing. | ||
events { | ||
# Define the maximum number of simultaneous connections that can be opened by a worker process | ||
worker_connections 1024; | ||
} | ||
|
||
|
||
# http block defines the parameters for how NGINX should handle HTTP web traffic | ||
http { | ||
# Include the file defining the list of file types that are supported by NGINX | ||
include /etc/nginx/mime.types; | ||
# Define the default file type that is returned to the user | ||
default_type text/html; | ||
|
||
# Don't tell nginx version to clients. | ||
server_tokens off; | ||
|
||
# Specifies the maximum accepted body size of a client request, as | ||
# indicated by the request header Content-Length. If the stated content | ||
# length is greater than this size, then the client receives the HTTP | ||
# error code 413. Set to 0 to disable. | ||
client_max_body_size 0; | ||
|
||
# Define the format of log messages. | ||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for"'; | ||
|
||
# Define the location of the log of access attempts to NGINX | ||
access_log /var/log/nginx/access.log main; | ||
|
||
# Define the parameters to optimize the delivery of static content | ||
sendfile on; | ||
tcp_nopush on; | ||
tcp_nodelay on; | ||
|
||
# Define the timeout value for keep-alive connections with the client | ||
keepalive_timeout 65; | ||
|
||
# Define the usage of the gzip compression algorithm to reduce the amount of data to transmit | ||
#gzip on; | ||
|
||
# Include additional parameters for virtual host(s)/server(s) | ||
include /etc/nginx/conf.d/*.conf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
numpy==1.11.3 | ||
Pillow==4.0.0 | ||
attrs==18.1.0 | ||
click==6.7 | ||
Flask==1.0.2 | ||
itsdangerous==0.24 | ||
Jinja2==2.10 | ||
MarkupSafe==1.0 | ||
numpy==1.14.5 | ||
Pillow==5.2.0 | ||
Werkzeug==0.14.1 | ||
uwsgi |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import io | ||
|
||
from flask import Flask, request, redirect, flash, send_file, render_template_string | ||
|
||
from transform import transform | ||
|
||
UPLOAD_FOLDER = "/path/to/the/uploads" | ||
ALLOWED_EXTENSIONS = set(["png", "jpg", "jpeg", "gif"]) | ||
|
||
app = Flask(__name__) | ||
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER | ||
|
||
|
||
def allowed_file(filename): | ||
return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS | ||
|
||
|
||
@app.route("/", methods=["GET", "POST"]) | ||
def upload_file(): | ||
if request.method == "POST": | ||
# check if the post request has the file part | ||
if "file" not in request.files: | ||
flash("No file part") | ||
return redirect(request.url) | ||
file = request.files["file"] | ||
# if user does not select file, browser also | ||
# submit a empty part without filename | ||
if file.filename == "": | ||
flash("No selected file") | ||
return redirect(request.url) | ||
if file and allowed_file(file.filename): | ||
fout = transform(file_in=file, file_out=io.BytesIO()) | ||
return send_file(fout, as_attachment=True, attachment_filename="output.png") | ||
|
||
return render_template_string( | ||
r""" | ||
<!doctype html> | ||
<head> | ||
<title>Convert An Image</title> | ||
</head> | ||
<body> | ||
<h1>Convert An Image to Text!</h1> | ||
{% with messages = get_flashed_messages() %} | ||
{% if messages %} | ||
<ul class=flashes> | ||
{% for message in messages %} | ||
<li>{{ message }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
{% endwith %} | ||
<p>Note that this may take a minute to process.</p> | ||
<form method=post enctype=multipart/form-data> | ||
<p> | ||
<input type=file name=file> | ||
<input type=submit value=Upload> | ||
</p> | ||
</form> | ||
</body> | ||
""" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host="0.0.0.0") |
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
Oops, something went wrong.