Add nginx + uwsgi stack for Sahana, closes #223
This commit is contained in:
parent
0671e7378e
commit
f260971661
@ -27,7 +27,7 @@ export SAHANADEMO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|||||||
envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv
|
envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv
|
||||||
|
|
||||||
# Populate database
|
# Populate database
|
||||||
docker run --rm -h sahana-demo --link postgres -v /srv/sahana-demo/conf:/srv/web2py/applications/eden/models -v /srv/sahana-demo/data/databases:/srv/web2py/applications/eden/databases -v /tmp/masterUsers.csv:/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv sahana ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
|
docker run --rm -h sahana-demo --link postgres -v /srv/sahana-demo/conf:/srv/web2py/applications/eden/models -v /srv/sahana-demo/data/databases:/srv/web2py/applications/eden/databases -v /tmp/masterUsers.csv:/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py"
|
||||||
rm /tmp/masterUsers.csv
|
rm /tmp/masterUsers.csv
|
||||||
|
|
||||||
# Create Sahana service
|
# Create Sahana service
|
||||||
|
@ -32,7 +32,7 @@ export SAHANA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|||||||
envsubst <${SOURCE_DIR}/srv/sahana/data/Spotter/masterUsers.csv >/srv/sahana/data/Spotter/masterUsers.csv
|
envsubst <${SOURCE_DIR}/srv/sahana/data/Spotter/masterUsers.csv >/srv/sahana/data/Spotter/masterUsers.csv
|
||||||
|
|
||||||
# Populate database
|
# Populate database
|
||||||
docker run --rm -h sahana --link postgres -v /srv/sahana/conf:/srv/web2py/applications/eden/models -v /srv/sahana/data/Spotter:/srv/web2py/applications/eden/modules/templates/Spotter -v /srv/sahana/data/databases:/srv/web2py/applications/eden/databases sahana ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
|
docker run --rm -h sahana --link postgres -v /srv/sahana/conf:/srv/web2py/applications/eden/models -v /srv/sahana/data/Spotter:/srv/web2py/applications/eden/modules/templates/Spotter -v /srv/sahana/data/databases:/srv/web2py/applications/eden/databases sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py"
|
||||||
|
|
||||||
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
|
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
|
||||||
if [ ${DEBUG:-0} -eq 0 ]; then
|
if [ ${DEBUG:-0} -eq 0 ]; then
|
||||||
|
@ -13,7 +13,7 @@ RUN \
|
|||||||
# Add edge/testing repository
|
# Add edge/testing repository
|
||||||
echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/testing' >>/etc/apk/repositories \
|
echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/testing' >>/etc/apk/repositories \
|
||||||
# Install runtime dependencies
|
# Install runtime dependencies
|
||||||
&& apk --no-cache add geos@edge py-gdal@edge py2-dateutil py2-lxml py2-numpy py2-pillow py2-psycopg2 py2-requests
|
&& apk --no-cache add geos@edge nginx py-gdal@edge py2-dateutil py2-lxml py2-numpy py2-pillow py2-psycopg2 py2-requests s6 uwsgi-python
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
# Install build dependencies
|
# Install build dependencies
|
||||||
@ -26,6 +26,8 @@ RUN \
|
|||||||
&& git -C /srv/web2py submodule update \
|
&& git -C /srv/web2py submodule update \
|
||||||
# Fix Web2py urllib import (https://github.com/web2py/pydal/commit/9d2290c)
|
# Fix Web2py urllib import (https://github.com/web2py/pydal/commit/9d2290c)
|
||||||
&& sed -i 's/import traceback/import traceback\nimport urllib/' /srv/web2py/gluon/packages/dal/pydal/base.py \
|
&& sed -i 's/import traceback/import traceback\nimport urllib/' /srv/web2py/gluon/packages/dal/pydal/base.py \
|
||||||
|
# Symlink WSGI handler
|
||||||
|
&& ln -s /srv/web2py/handlers/wsgihandler.py /srv/web2py/wsgihandler.py \
|
||||||
# Install Sahana
|
# Install Sahana
|
||||||
&& git clone --depth 1 https://github.com/sahana/eden.git /srv/web2py/applications/eden \
|
&& git clone --depth 1 https://github.com/sahana/eden.git /srv/web2py/applications/eden \
|
||||||
# Install python dependencies, exclude old or unnecessary ones
|
# Install python dependencies, exclude old or unnecessary ones
|
||||||
@ -40,7 +42,7 @@ RUN \
|
|||||||
&& cp /usr/share/fonts/ttf-dejavu/DejaVuSerif.ttf /srv/web2py/applications/eden/static/fonts/DejaVuSerif.ttf \
|
&& cp /usr/share/fonts/ttf-dejavu/DejaVuSerif.ttf /srv/web2py/applications/eden/static/fonts/DejaVuSerif.ttf \
|
||||||
# Create OS user
|
# Create OS user
|
||||||
&& addgroup -S -g 8001 sahana \
|
&& addgroup -S -g 8001 sahana \
|
||||||
&& adduser -S -u 8001 -h /srv/web2py -s /bin/false -g sahana -G sahana sahana \
|
&& adduser -S -u 8001 -h /srv/web2py -s /bin/sh -g sahana -G sahana sahana \
|
||||||
&& chown -R sahana:sahana /srv/web2py \
|
&& chown -R sahana:sahana /srv/web2py \
|
||||||
# Cleanup
|
# Cleanup
|
||||||
&& apk --no-cache del .deps \
|
&& apk --no-cache del .deps \
|
||||||
@ -48,11 +50,11 @@ RUN \
|
|||||||
&& rm -r /srv/web2py/applications/admin /srv/web2py/applications/examples /srv/web2py/applications/welcome \
|
&& rm -r /srv/web2py/applications/admin /srv/web2py/applications/examples /srv/web2py/applications/welcome \
|
||||||
&& rm -r /root/.cache
|
&& rm -r /root/.cache
|
||||||
|
|
||||||
|
COPY docker/etc/ /etc/
|
||||||
|
|
||||||
COPY --chown=8001:8001 docker/srv/ /srv/
|
COPY --chown=8001:8001 docker/srv/ /srv/
|
||||||
|
|
||||||
VOLUME ["/srv/web2py/applications/eden/models", "/srv/web2py/applications/eden/databases", "/srv/web2py/applications/eden/uploads"]
|
VOLUME ["/srv/web2py/applications/eden/models", "/srv/web2py/applications/eden/databases", "/srv/web2py/applications/eden/uploads"]
|
||||||
EXPOSE 8001
|
EXPOSE 8001
|
||||||
|
|
||||||
USER sahana
|
CMD ["s6-svscan", "/etc/services.d"]
|
||||||
WORKDIR /srv/web2py
|
|
||||||
CMD ["./web2py.py", "-a", "eden", "-K", "eden", "-X", "-i", "0.0.0.0", "-p", "8001", "--nogui"]
|
|
||||||
|
41
sahana/docker/etc/nginx/nginx.conf
Normal file
41
sahana/docker/etc/nginx/nginx.conf
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
user nginx;
|
||||||
|
pid /run/nginx.pid;
|
||||||
|
worker_processes 1;
|
||||||
|
error_log /dev/stderr warn;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
include mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
access_log off;
|
||||||
|
server_tokens off;
|
||||||
|
client_max_body_size 100m;
|
||||||
|
sendfile on;
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 8001;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
location = / {
|
||||||
|
return 301 $http_x_forwarded_proto://$http_x_forwarded_host/eden;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /eden {
|
||||||
|
uwsgi_pass unix:///run/uwsgi;
|
||||||
|
uwsgi_read_timeout 300s;
|
||||||
|
uwsgi_send_timeout 300s;
|
||||||
|
include uwsgi_params;
|
||||||
|
uwsgi_param UWSGI_SCHEME $scheme;
|
||||||
|
uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~* /eden/static {
|
||||||
|
root /srv/web2py/applications;
|
||||||
|
expires max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
sahana/docker/etc/services.d/.s6-svscan/finish
Executable file
3
sahana/docker/etc/services.d/.s6-svscan/finish
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
/bin/true
|
3
sahana/docker/etc/services.d/nginx/run
Executable file
3
sahana/docker/etc/services.d/nginx/run
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/execlineb -P
|
||||||
|
|
||||||
|
/usr/sbin/nginx -g "daemon off;"
|
3
sahana/docker/etc/services.d/uwsgi/run
Executable file
3
sahana/docker/etc/services.d/uwsgi/run
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/execlineb -P
|
||||||
|
|
||||||
|
/usr/sbin/uwsgi --ini /etc/uwsgi/uwsgi.conf
|
22
sahana/docker/etc/uwsgi/uwsgi.conf
Normal file
22
sahana/docker/etc/uwsgi/uwsgi.conf
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
[uwsgi]
|
||||||
|
uid = sahana
|
||||||
|
gid = sahana
|
||||||
|
chdir = /srv/web2py
|
||||||
|
|
||||||
|
plugin = python
|
||||||
|
enable-threads = 1
|
||||||
|
module = wsgihandler
|
||||||
|
|
||||||
|
socket = /run/uwsgi
|
||||||
|
chown-socket = nginx:nginx
|
||||||
|
|
||||||
|
cheaper = 1
|
||||||
|
cheaper-algo = spare
|
||||||
|
cheaper-initial = 1
|
||||||
|
cheaper-step = 1
|
||||||
|
workers = 8
|
||||||
|
idle = 600
|
||||||
|
harakiri = 300
|
||||||
|
|
||||||
|
mule = run_scheduler.py
|
||||||
|
cron = 10 -1 -1 -1 -1 python web2py.py -Q -S eden -M -R scripts/sessions2trash.py -A -o
|
6
sahana/docker/srv/web2py/run_scheduler.py
Normal file
6
sahana/docker/srv/web2py/run_scheduler.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from gluon.shell import run
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run('eden', True, True, None, False, 'from gluon import current; current._scheduler.loop()')
|
@ -28,7 +28,7 @@ export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|||||||
envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv
|
envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv
|
||||||
|
|
||||||
# Populate database
|
# Populate database
|
||||||
docker run --rm -h sambro --link postgres -v /srv/sambro/conf:/srv/web2py/applications/eden/models -v /srv/sambro/data/SAMBRO:/srv/web2py/applications/eden/modules/templates/SAMBRO -v /tmp/masterUsers.csv:/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv -v /srv/sambro/data/databases:/srv/web2py/applications/eden/databases sahana ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
|
docker run --rm -h sambro --link postgres -v /srv/sambro/conf:/srv/web2py/applications/eden/models -v /srv/sambro/data/SAMBRO:/srv/web2py/applications/eden/modules/templates/SAMBRO -v /tmp/masterUsers.csv:/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv -v /srv/sambro/data/databases:/srv/web2py/applications/eden/databases sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py"
|
||||||
rm /tmp/masterUsers.csv
|
rm /tmp/masterUsers.csv
|
||||||
|
|
||||||
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
|
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
|
||||||
|
Loading…
Reference in New Issue
Block a user