Initial commit
This commit is contained in:
commit
d740a015bd
|
@ -0,0 +1,26 @@
|
||||||
|
FROM ubuntu:trusty
|
||||||
|
MAINTAINER Dave P
|
||||||
|
|
||||||
|
# Create user
|
||||||
|
RUN useradd --create-home --uid 1000 python ; \
|
||||||
|
locale-gen en ; \
|
||||||
|
echo "python:python" | chpasswd ; \
|
||||||
|
apt-get update ; apt-get install -y nginx-full uwsgi uwsgi-plugin-python3 python-virtualenv python3-pip supervisor ; \
|
||||||
|
echo "daemon off;" >> /etc/nginx/nginx.conf ; \
|
||||||
|
su -c "mkdir /home/python/app/" python ; \
|
||||||
|
mkdir /start.d
|
||||||
|
|
||||||
|
# install configs & scripts
|
||||||
|
COPY default /etc/nginx/sites-available/default
|
||||||
|
COPY pythonapp.ini /etc/uwsgi/apps-enabled/pythonapp.ini
|
||||||
|
COPY nginx.conf /etc/supervisor/conf.d/nginx.conf
|
||||||
|
COPY pythonapp.conf /etc/supervisor/conf.d/pythonapp.conf
|
||||||
|
COPY supervisor.conf /etc/supervisor/conf.d/supervisor.conf
|
||||||
|
COPY init-virtualenv /start.d/init-virtualenv
|
||||||
|
COPY start /start
|
||||||
|
|
||||||
|
RUN chmod +x /start ; chmod +x /start.d/init-virtualenv
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
CMD /start
|
|
@ -0,0 +1,17 @@
|
||||||
|
Docker Pythonapp
|
||||||
|
================
|
||||||
|
|
||||||
|
For running uWSGI python3 app
|
||||||
|
|
||||||
|
**Usage:**
|
||||||
|
|
||||||
|
* build image: `docker build -t pyapp .`
|
||||||
|
* build a python3 app. for example, in a folder called testapp
|
||||||
|
* `testapp/app.py` is the main wsgi file. var `application` must be the wsgi app instance.
|
||||||
|
* testapp/requirements.txt is used by pip to install required modules
|
||||||
|
* app/static will be mapped to http://server.address/static/
|
||||||
|
* run container: docker run -p 80:80 -v /localpath/to/appdir/:/home/python/app/ pythonapp
|
||||||
|
|
||||||
|
**Example app:**
|
||||||
|
|
||||||
|
http://gitlab.xmopx.net/dave/example-uwsgi-app/tree/master
|
|
@ -0,0 +1,16 @@
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
#listen [::]:80 ipv6only=on;
|
||||||
|
root /usr/share/nginx/html/;
|
||||||
|
include uwsgi_params;
|
||||||
|
|
||||||
|
access_log /var/log/nginx/pythonapp.log;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
uwsgi_pass 127.0.0.1:3330;
|
||||||
|
}
|
||||||
|
location /static/ {
|
||||||
|
autoindex on;
|
||||||
|
alias /home/python/app/static/;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
su python <<'EOF'
|
||||||
|
if [ -d /home/python/appenv ] ; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
cd /home/python/
|
||||||
|
virtualenv --python=python3.4 appenv
|
||||||
|
source appenv/bin/activate
|
||||||
|
pip install -r app/requirements.txt
|
||||||
|
deactivate
|
||||||
|
EOF
|
|
@ -0,0 +1,3 @@
|
||||||
|
[program:nginx]
|
||||||
|
command=/usr/sbin/nginx
|
||||||
|
autorestart=true
|
|
@ -0,0 +1,4 @@
|
||||||
|
[program:pythonapp]
|
||||||
|
command=/usr/bin/uwsgi --ini /etc/uwsgi/apps-enabled/pythonapp.ini --uid python --gid python
|
||||||
|
autorestart=true
|
||||||
|
stopsignal=INT
|
|
@ -0,0 +1,17 @@
|
||||||
|
[uwsgi]
|
||||||
|
no-orphans = true
|
||||||
|
log-date = true
|
||||||
|
uid = pythonapp
|
||||||
|
pid = pythonapp
|
||||||
|
plugins = python3
|
||||||
|
touch-reload = /home/python/app/app.py
|
||||||
|
chdir = /home/python/app/
|
||||||
|
wsgi-file = /home/python/app/app.py
|
||||||
|
callable = application
|
||||||
|
master = true
|
||||||
|
processes = 1
|
||||||
|
socket = 127.0.0.1:3330
|
||||||
|
enable-threads = true
|
||||||
|
no-threads-wait = true
|
||||||
|
die-on-term = true
|
||||||
|
virtualenv = /home/python/appenv
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# run everything in start.d
|
||||||
|
find /start.d -type f -executable -exec {} \;
|
||||||
|
|
||||||
|
# Cleanly kill supervisor when container is stopped
|
||||||
|
trap 'kill $(jobs -p)' EXIT
|
||||||
|
|
||||||
|
# start services
|
||||||
|
supervisord
|
|
@ -0,0 +1,2 @@
|
||||||
|
[supervisord]
|
||||||
|
nodaemon=true
|
Loading…
Reference in New Issue