From b9c7a1474798e9de9296b486a1fb6d72d3c12da8 Mon Sep 17 00:00:00 2001 From: dave Date: Tue, 7 Feb 2017 23:05:09 -0800 Subject: [PATCH] Dockerfile --- README.txt | 5 +++++ docker/Dockerfile | 17 +++++++++++++++++ docker/default | 24 ++++++++++++++++++++++++ docker/supervisor-imghost.conf | 5 +++++ imghost/api.py | 12 ++++++++---- requirements.txt | 9 --------- 6 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 docker/Dockerfile create mode 100644 docker/default create mode 100644 docker/supervisor-imghost.conf diff --git a/README.txt b/README.txt index e5333a4..99d3168 100644 --- a/README.txt +++ b/README.txt @@ -9,3 +9,8 @@ python3 setup.py install imghost Then visit http://127.0.0.1:3000/ + +Dockerfile, based on http://gitlab.davepedu.com/dave/docker-nginx: + +# docker build -t imghost -f docker/Dockerfile . +# docker run -it --rm -v /host/path:/usr/share/imghost/ui/i/ -p 8080:80 --name imghost imghost diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..65339d8 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,17 @@ +FROM dpedu/nginx + +RUN apt-get update ; \ + apt-get install -y supervisor python3-pip python3-setuptools + +ADD . /usr/share/imghost/ + +RUN cd /usr/share/imghost ;\ + pip3 install -r requirements.txt ;\ + python3 setup.py install ;\ + rm -rf scenv README.txt build dist docker imghost imghost.egg-info requirements.txt setup.py ui/i/* .git ; \ + chown www-data /usr/share/imghost/ui/i + +ADD docker/supervisor-imghost.conf /etc/supervisor/conf.d/imghost.conf +ADD docker/default /etc/nginx/sites-enabled/default + +# WORKDIR /usr/share/imghost diff --git a/docker/default b/docker/default new file mode 100644 index 0000000..13848e6 --- /dev/null +++ b/docker/default @@ -0,0 +1,24 @@ +server { + listen 80 default_server; + listen [::]:80 default_server ipv6only=on; + + root /usr/share/imghost/ui/; + index index.html; + + location / { + try_files $uri $uri/ =404; + } + + location /api { + proxy_pass http://127.0.0.1:3000; + } + + #error_page 404 /404.html; + + #error_page 500 502 503 504 /50x.html; + + #location = /50x.html { + # root /usr/share/nginx/html; + #} + +} diff --git a/docker/supervisor-imghost.conf b/docker/supervisor-imghost.conf new file mode 100644 index 0000000..7aa060a --- /dev/null +++ b/docker/supervisor-imghost.conf @@ -0,0 +1,5 @@ +[program:imghost] +command=/usr/local/bin/imghost +autorestart=true +directory=/usr/share/imghost +user=www-data diff --git a/imghost/api.py b/imghost/api.py index 0fba243..9050daf 100644 --- a/imghost/api.py +++ b/imghost/api.py @@ -73,7 +73,8 @@ class ImgHostApiV1(Mountable): sha = sha.decode("UTF-8").split(" ")[0] imgpath = os.path.join("i", "{}.{}".format(sha[0:8], ext)) os.link(theFile.file.name, os.path.join("ui", imgpath)) - raise cherrypy.HTTPRedirect("/" + imgpath) + cherrypy.response.headers['Location'] = "/" + imgpath + cherrypy.response.status = 302 class ImgHostApi(object): @@ -83,9 +84,11 @@ class ImgHostApi(object): self.ui = Mountable(conf={'/': { 'tools.staticdir.on': True, 'tools.staticdir.dir': ui_path, - 'tools.staticdir.index': 'index.html'}}).mount('/') + 'tools.staticdir.index': 'index.html' + }}).mount('/') - self.app_v1 = ImgHostApiV1().mount('/api/v1') + self.app_v1 = ImgHostApiV1(conf={'/': {'tools.proxy.on': True, + }}).mount('/api/v1') cherrypy.config.update({ 'sessionFilter.on': False, @@ -98,7 +101,8 @@ class ImgHostApi(object): 'server.socket_host': '0.0.0.0', 'server.socket_timeout': 5, 'log.screen': False, - 'engine.autoreload.on': False + 'engine.autoreload.on': False, + }) def run(self): diff --git a/requirements.txt b/requirements.txt index 359c964..2505291 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,2 @@ appdirs==1.4.0 -cheroot==5.1.0 CherryPy==10.0.0 -imghost==0.0.0 -packaging==16.8 -pkg-resources==0.0.0 -portend==1.8 -pyparsing==2.1.10 -pytz==2016.10 -six==1.10.0 -tempora==1.6.1