Commit 90669b98 authored by kaiyou's avatar kaiyou

Docker packaging

parent d66f3447
FROM python:3
RUN apt-get update \
&& apt-get install --no-install-recommends -y nginx supervisor \
&& apt-get clean
ADD requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
ADD tedimg /tedimg
ADD docker /config
CMD /usr/bin/supervisord -c /config/supervisor.conf
Image upload with Flask
=======================
No database, no additional features. Plain and simple image upload.
Use the Docker image
--------------------
Simply allocate a data directory and create the thumbnails
sub-directory:
mkdir -p /path/to/data/thumbnails
Then run the image server:
docker run --name=tedimg -d -v /path/to/data:/data kaiyou/tedimg
Build from source
-----------------
NodeJS and NPM are required to build from source :
git clone git@github.com:kaiyou/tedimg.git
cd tedimg
npm install
gulp
docker build
user www-data;
worker_processes 4;
pid /run/nginx.pid;
daemon off;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /dev/stdout;
error_log /dev/stderr;
gzip on;
gzip_disable "msie6";
server {
listen 80;
location /images {
alias /data;
}
location /static {
root /tedimg;
}
location / {
uwsgi_pass unix:///app.sock;
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
}
}
}
[supervisord]
pidfile=/var/run/supervisord.pid
nodaemon=true
loglevel=DEBUG
[program:nginx]
command=nginx -c /config/nginx.conf
redirect_stderr=true
[program:flask]
command = /usr/local/bin/uwsgi --ini /config/uwsgi.conf
redirect_stderr=true
[uwsgi]
ini = :base
socket = /app.sock
master = true
processes = 4
[base]
chdir = /
module=tedimg:app
chmod-socket=666
......@@ -2,11 +2,11 @@
"name": "tedimg",
"dependencies": {
"gulp-concat": "^2.6.0",
"gulp-replace": "^0.5.4",
"gulp-replace": "^0.5.4"
},
"devDependencies": {
"gulp": "^3.9.0",
"gulp-bower": "0.0.11",
"gulp-notify": "^2.2.0",
"gulp-notify": "^2.2.0"
}
}
Flask==0.10.1
Jinja2==2.8
Pillow==3.0.0
requests==2.8.1
uWSGI==2.0.11.2
from tedimg import app
from flask import send_from_directory
import os
app.config.update(
SITE_NAME="TeDomum Images",
FULL_STORAGE="./tedimg/static/images",
......
from flask import Flask
import os
app = Flask(__name__)
app.debug = "FLASK_DEBUG" in os.environ
app.config.update(
SITE_NAME="TedImg",
SITE_NAME=os.environ.get("SITE_NAME", "TedImg"),
SOURCE_URL="https://git.tedomum.net/kaiyou/tedimg",
HELP_URL="https://git.tedomum.net/kaiyou/tedimg",
FULL_STORAGE="/tmp/images",
THUMB_STORAGE="/tmp/images/thumb",
FULL_WEB="image",
THUMB_WEB="images/thumb",
FULL_STORAGE=os.environ.get("FULL_STORAGE", "/tmp/images"),
THUMB_STORAGE=os.environ.get("THUMB_STORAGE", "/tmp/images/thumb"),
FULL_WEB=os.environ.get("FULL_WEB", "images"),
THUMB_WEB=os.environ.get("THUMB_WEB", "images/thumb"),
THUMB_SIZE=100
)
if (app.debug):
from werkzeug import debug
app.wsgi_app = debug.DebuggedApplication(app.wsgi_app, True)
import tedimg.views
......@@ -33,13 +33,16 @@ def image_from_url(url):
def save_with_thumbnail(image, filename):
dest = "."
print(filename)
while os.path.exists(os.path.join(app.config["FULL_STORAGE"], dest)):
filename, ext = os.path.splitext(filename)
random = binascii.hexlify(os.urandom(3)).decode('utf8')
dest = "%s-%s%s" % (filename, random, ext)
image.save(os.path.join(app.config["FULL_STORAGE"], dest))
# Grab some configuration
full_file = os.path.join(app.config["FULL_STORAGE"], dest)
thumb_file = os.path.join(app.config["THUMB_STORAGE"], dest)
thumb_size = app.config["THUMB_SIZE"]
# Save the image and thumbnail
image.save(full_file, format=image.format)
image.thumbnail((thumb_size, thumb_size))
image.save(os.path.join(app.config["THUMB_STORAGE"], dest))
image.save(thumb_file, format=image.format)
return dest
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment