From ed719f5d9a25c2be1c2c5ef4c806635844e487bc Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 1 Oct 2014 04:11:10 +0200 Subject: [PATCH] Add Dockerfile and deploy conf files --- Dockerfile | 49 +++++++++++++++++++++++++++++ README.rst | 5 +-- deploy/apt-app.list | 10 ++++++ deploy/nginx-app.conf | 37 ++++++++++++++++++++++ deploy/supervisor-app.conf | 5 +++ timeside/server/sandbox/settings.py | 4 +-- timeside/server/sandbox/uwsgi.ini | 31 ++++++++++++++++++ timeside/server/sandbox/wsgi.py | 2 +- 8 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 Dockerfile create mode 100644 deploy/apt-app.list create mode 100644 deploy/nginx-app.conf create mode 100644 deploy/supervisor-app.conf create mode 100644 timeside/server/sandbox/uwsgi.ini diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..afd3beb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +# Copyright 2013 Thatcher Peskens +# Copyright 2014 Guillaume Pellerin +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from debian:stable + +maintainer Guillaume Pellerin + +add ./deploy/apt-app.list /etc/apt/sources.list.d/ +run apt-get update +run apt-get install -y build-essential vim +run apt-get install -y python python-dev python-pip +run apt-get -y -t wheezy-backports dist-upgrade +run apt-get install -y --force-yes -t wheezy-backports nginx supervisor python-timeside git python-tables python-django python-traits python-networkx +run apt-get clean + +# install uwsgi now because it takes a little while +run pip install uwsgi + +# clone app +add . /opt/TimeSide + +# setup all the configfiles +run echo "daemon off;" >> /etc/nginx/nginx.conf +run rm /etc/nginx/sites-enabled/default +run ln -s /opt/TimeSide/deploy/nginx-app.conf /etc/nginx/sites-enabled/ +run ln -s /opt/TimeSide/deploy/supervisor-app.conf /etc/supervisor/conf.d/ + +# run pip install +run pip install -e /opt/TimeSide + +# sandbox setup +run /opt/TimeSide/timeside/server/sandbox/manage.py syncdb --noinput +run /opt/TimeSide/timeside/server/sandbox/manage.py migrate --noinput +run /opt/TimeSide/timeside/server/sandbox/manage.py collectstatic --noinput + +expose 80 +cmd ["supervisord", "-n"] diff --git a/README.rst b/README.rst index 4c195bd..f1dd895 100644 --- a/README.rst +++ b/README.rst @@ -450,10 +450,11 @@ To start the web server through the container:: Then browse http://localhost:9000/api/ -To start a development process, it is advised to checkout the dev branch:: +To start a new development, it is advised to checkout the dev branch and build your own container:: - cd /root/apps/TimeSide + cd TimeSide git checkout dev + sudo docker build . Sponsors and Partners diff --git a/deploy/apt-app.list b/deploy/apt-app.list new file mode 100644 index 0000000..647b260 --- /dev/null +++ b/deploy/apt-app.list @@ -0,0 +1,10 @@ +deb http://ftp.debian.org/debian/ wheezy-backports main contrib non-free +deb-src http://ftp.debian.org/debian/ wheezy-backports main contrib non-free + +deb http://security.debian.org/ wheezy/updates main +deb-src http://security.debian.org/ wheezy/updates main + +deb http://debian.parisson.com/debian/ wheezy main +deb-src http://debian.parisson.com/debian wheezy main + +deb ftp://ftp.igh.cnrs.fr/pub/debian-multimedia stable main \ No newline at end of file diff --git a/deploy/nginx-app.conf b/deploy/nginx-app.conf new file mode 100644 index 0000000..fe04fac --- /dev/null +++ b/deploy/nginx-app.conf @@ -0,0 +1,37 @@ +# mysite_nginx.conf + +# the upstream component nginx needs to connect to +upstream django { + server unix:/opt/TimeSide/timeside/server/sandbox/app.sock; # for a file socket + # server 127.0.0.1:8001; # for a web port socket (we'll use this first) + } + +# configuration of the server +server { + # the port your site will be served on, default_server indicates that this server block + # is the block to use if no blocks match the server_name + listen 80 default_server; + + # the domain name it will serve for + server_name .example.com; # substitute your machine's IP address or FQDN + charset utf-8; + + # max upload size + client_max_body_size 75M; # adjust to taste + + # Django media + location /media { + alias /opt/TimeSide/timeside/server/sandbox/media; # your Django project's media files - amend as required + } + + # Uncomment in production! + location /static { + alias /var/www/static; # your Django project's static files - amend as required + } + + # Finally, send all non-media requests to the Django server. + location / { + uwsgi_pass django; + include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed + } + } diff --git a/deploy/supervisor-app.conf b/deploy/supervisor-app.conf new file mode 100644 index 0000000..6138d61 --- /dev/null +++ b/deploy/supervisor-app.conf @@ -0,0 +1,5 @@ +[program:app-uwsgi] +command = /usr/local/bin/uwsgi --ini /opt/TimeSide/timeside/server/sandbox/uwsgi.ini + +[program:nginx-app] +command = /usr/sbin/nginx diff --git a/timeside/server/sandbox/settings.py b/timeside/server/sandbox/settings.py index 1cd5c10..2890b1f 100644 --- a/timeside/server/sandbox/settings.py +++ b/timeside/server/sandbox/settings.py @@ -60,13 +60,13 @@ MEDIA_ROOT = PROJECT_ROOT + '/media/' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" -MEDIA_URL = '' +MEDIA_URL = '/media/' # Absolute path to the directory static files should be collected to. # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. # Example: "/home/media/media.lawrence.com/static/" -STATIC_ROOT = '' +STATIC_ROOT = '/var/www/static' # URL prefix for static files. # Example: "http://media.lawrence.com/static/" diff --git a/timeside/server/sandbox/uwsgi.ini b/timeside/server/sandbox/uwsgi.ini new file mode 100644 index 0000000..94bd251 --- /dev/null +++ b/timeside/server/sandbox/uwsgi.ini @@ -0,0 +1,31 @@ +[uwsgi] +# this config will be loaded if nothing specific is specified +# load base config from below +ini = :base + +# %d is the dir this configuration file is in +socket = %dapp.sock +master = true +processes = 4 + +[dev] +ini = :base +# socket (uwsgi) is not the same as http, nor http-socket +socket = :8001 + + +[local] +ini = :base +http = :8000 +# set the virtual env to use +home=/home/me/.virtualenv + + +[base] +# chdir to the folder of this config file, plus app/website +chdir = %d +# load the module from wsgi.py, it is a python path from +# the directory above. +module=wsgi +# allow anyone to connect to the socket. This is very permissive +chmod-socket=666 diff --git a/timeside/server/sandbox/wsgi.py b/timeside/server/sandbox/wsgi.py index c4d2c74..cf8e7eb 100644 --- a/timeside/server/sandbox/wsgi.py +++ b/timeside/server/sandbox/wsgi.py @@ -15,7 +15,7 @@ framework. """ import os -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sandbox.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION -- 2.39.5