From 905da30a5ca83d1896e1870f269905c2bdca821d Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 12 Mar 2015 17:41:23 +0100 Subject: [PATCH] Add Dockerfile and docker-compose config, update sandbox config --- Dockerfile | 34 +++++++++++ docker-compose.yml | 57 +++++++++++++++++++ .../deploy/apache-app.conf | 6 +- examples/deploy/apt-app.list | 12 ++++ examples/deploy/nginx-app.conf | 30 ++++++++++ examples/deploy/start_app.sh | 23 ++++++++ .../fixtures}/original_format.txt | 0 {example => examples}/sandbox/__init__.py | 0 {example => examples}/sandbox/diag.sh | 0 {example => examples}/sandbox/manage.py | 0 {example => examples}/sandbox/modelviz.py | 0 {example => examples}/sandbox/robots.txt | 0 {example => examples}/sandbox/settings.py | 9 +-- .../sandbox/update_schema.sh | 0 {example => examples}/sandbox/urls.py | 0 {example => examples}/sandbox/wsgi.py | 0 setup.py | 3 +- .../commands/telemeta-create-admin-user.py | 24 ++++++++ 18 files changed, 190 insertions(+), 8 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml rename example/apache2/telemeta.conf => examples/deploy/apache-app.conf (85%) create mode 100644 examples/deploy/apt-app.list create mode 100644 examples/deploy/nginx-app.conf create mode 100644 examples/deploy/start_app.sh rename {example/data/format => examples/fixtures}/original_format.txt (100%) rename {example => examples}/sandbox/__init__.py (100%) rename {example => examples}/sandbox/diag.sh (100%) rename {example => examples}/sandbox/manage.py (100%) rename {example => examples}/sandbox/modelviz.py (100%) rename {example => examples}/sandbox/robots.txt (100%) rename {example => examples}/sandbox/settings.py (97%) rename {example => examples}/sandbox/update_schema.sh (100%) rename {example => examples}/sandbox/urls.py (100%) rename {example => examples}/sandbox/wsgi.py (100%) create mode 100644 telemeta/management/commands/telemeta-create-admin-user.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..02cfce4d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# Copyright 2013 Thatcher Peskens +# Copyright 2014-2015 Guillaume Pellerin +# Copyright 2014-2015 Thomas Fillon +# +# 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 parisson/timeside:latest + +MAINTAINER Guillaume Pellerin , Thomas fillon + +# Clone app +RUN mkdir /opt/Telemeta +ADD . /opt/Telemeta +WORKDIR /opt/Telemeta + +# Install deps +RUN pip install -r requirements.txt + +# Sandbox setup +RUN /opt/Telemeta/examples/sandbox/manage.py syncdb --noinput +RUN /opt/Telemeta/examples/sandbox/manage.py migrate --noinput +RUN /opt/Telemeta/examples/sandbox/manage.py collectstatic --noinput + +EXPOSE 8000 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..b196e490 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,57 @@ +home: + image: debian:wheezy + volumes: + - ./examples/sandbox:/home/telemeta + command: /bin/true + +static: + image: debian:wheezy + volumes: + - /var/www/static + command: true + +log: + image: debian:wheezy + volumes: + - /var/log/nginx + - /var/log/postgres + - /var/log/uwsgi + command: /bin/true + +# datadb: +# image: debian:wheezy +# volumes: +# - /var/lib/postgresql +# command: /bin/true + +# db: +# image: postgres +# volumes_from: +# - datadb + +nginx: + image: nginx + ports: + - "8000:80" + volumes: + - ./examples/deploy/nginx-app.conf:/etc/nginx/conf.d/default.conf + volumes_from: + - static + - home + - log + links: + - app + +app: + build: . + volumes: + - .:/opt/Telemeta + volumes_from: + - static + - home + - log + command: /bin/sh /opt/Telemeta/examples/deploy/start_app.sh + ports: + - "9000:9000" + expose: + - "80" #default runserver wsgi port \ No newline at end of file diff --git a/example/apache2/telemeta.conf b/examples/deploy/apache-app.conf similarity index 85% rename from example/apache2/telemeta.conf rename to examples/deploy/apache-app.conf index d0bffa71..e0eececd 100644 --- a/example/apache2/telemeta.conf +++ b/examples/deploy/apache-app.conf @@ -8,9 +8,9 @@ # alert, emerg. CustomLog ${APACHE_LOG_DIR}/access-telemeta.log combined - Alias /media/ /home/dev/telemeta/example/sandbox/media/ + Alias /media/ /home/dev/telemeta/examples/sandbox/media/ - + Order deny,allow Allow from all @@ -18,7 +18,7 @@ WSGIDaemonProcess telemeta_test user=www-data group=www-data threads=12 processes=4 maximum-requests=1000 deadlock-timeout=300 WSGIProcessGroup telemeta_test WSGIApplicationGroup %{GLOBAL} - WSGIScriptAlias / /home/dev/telemeta/example/sandbox/wsgi.py + WSGIScriptAlias / /home/dev/telemeta/examples/sandbox/wsgi.py # diff --git a/examples/deploy/apt-app.list b/examples/deploy/apt-app.list new file mode 100644 index 00000000..81a807a5 --- /dev/null +++ b/examples/deploy/apt-app.list @@ -0,0 +1,12 @@ +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://www.deb-multimedia.org wheezy main non-free +deb http://www.deb-multimedia.org wheezy-backports main + +deb http://debian.parisson.com/debian/ wheezy main +deb-src http://debian.parisson.com/debian wheezy main + diff --git a/examples/deploy/nginx-app.conf b/examples/deploy/nginx-app.conf new file mode 100644 index 00000000..f1e56dbd --- /dev/null +++ b/examples/deploy/nginx-app.conf @@ -0,0 +1,30 @@ +server_tokens off; + +server { + listen 80; + server_name nginx; + charset utf-8; + + access_log /var/log/nginx/app-access.log; + error_log /var/log/nginx/app-error.log; + + # max upload size + client_max_body_size 75M; # adjust to taste + + # Django media + location /media { + alias /home/telemeta/media; # your Django project's media files - amend as required + autoindex on; + } + # Django static + location /static { + alias /var/www/static; # your Django project's static files - amend as required + autoindex on; + } + + location / { + uwsgi_pass app:8000; + include /etc/nginx/uwsgi_params; + } +} + diff --git a/examples/deploy/start_app.sh b/examples/deploy/start_app.sh new file mode 100644 index 00000000..2b5deb56 --- /dev/null +++ b/examples/deploy/start_app.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# paths +app_dir='/opt/Telemeta/' +sandbox_dir='/home/telemeta/' +manage=$sandbox_dir'manage.py' +wsgi=$sandbox_dir'wsgi.py' +app_static_dir=$app_dir'telemeta/static/' + +# django init +python $manage syncdb --noinput +python $manage migrate --noinput +python $manage collectstatic --noinput +python $manage telemeta-create-admin-user + +# static files auto update +pip install watchdog + +watchmedo shell-command --patterns="*.js;*.css" --recursive \ + --command='python '$manage' collectstatic --noinput' $app_static_dir & + +# app start +uwsgi --socket :8000 --wsgi-file $wsgi --chdir $sandbox_dir --master --processes 4 --threads 2 --py-autoreload 3 diff --git a/example/data/format/original_format.txt b/examples/fixtures/original_format.txt similarity index 100% rename from example/data/format/original_format.txt rename to examples/fixtures/original_format.txt diff --git a/example/sandbox/__init__.py b/examples/sandbox/__init__.py similarity index 100% rename from example/sandbox/__init__.py rename to examples/sandbox/__init__.py diff --git a/example/sandbox/diag.sh b/examples/sandbox/diag.sh similarity index 100% rename from example/sandbox/diag.sh rename to examples/sandbox/diag.sh diff --git a/example/sandbox/manage.py b/examples/sandbox/manage.py similarity index 100% rename from example/sandbox/manage.py rename to examples/sandbox/manage.py diff --git a/example/sandbox/modelviz.py b/examples/sandbox/modelviz.py similarity index 100% rename from example/sandbox/modelviz.py rename to examples/sandbox/modelviz.py diff --git a/example/sandbox/robots.txt b/examples/sandbox/robots.txt similarity index 100% rename from example/sandbox/robots.txt rename to examples/sandbox/robots.txt diff --git a/example/sandbox/settings.py b/examples/sandbox/settings.py similarity index 97% rename from example/sandbox/settings.py rename to examples/sandbox/settings.py index 4f469f5a..9ce029c4 100644 --- a/example/sandbox/settings.py +++ b/examples/sandbox/settings.py @@ -6,8 +6,6 @@ from django.core.urlresolvers import reverse_lazy, reverse sys.dont_write_bytecode = True -BASE_DIR = os.path.dirname(__file__) - DEBUG = True TEMPLATE_DEBUG = DEBUG @@ -19,6 +17,9 @@ ADMINS = ( MANAGERS = ADMINS +# Full filesystem path to the project. +PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. @@ -62,7 +63,7 @@ USE_L10N = True # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" -MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') +MEDIA_ROOT = PROJECT_ROOT + '/media/' if not os.path.exists(MEDIA_ROOT): os.mkdir(MEDIA_ROOT) @@ -76,7 +77,7 @@ MEDIA_URL = '/media/' # 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/example/sandbox/update_schema.sh b/examples/sandbox/update_schema.sh similarity index 100% rename from example/sandbox/update_schema.sh rename to examples/sandbox/update_schema.sh diff --git a/example/sandbox/urls.py b/examples/sandbox/urls.py similarity index 100% rename from example/sandbox/urls.py rename to examples/sandbox/urls.py diff --git a/example/sandbox/wsgi.py b/examples/sandbox/wsgi.py similarity index 100% rename from example/sandbox/wsgi.py rename to examples/sandbox/wsgi.py diff --git a/setup.py b/setup.py index 1c15caa1..80d0be51 100644 --- a/setup.py +++ b/setup.py @@ -61,6 +61,7 @@ setup( 'django-json-rpc', 'django-suit', 'django-google-tools', + 'django-ipauth', 'timeside>=0.7', 'south', 'sorl-thumbnail', @@ -68,7 +69,7 @@ setup( 'psutil', 'pyyaml', 'python-ebml', - 'mysql', + # 'mysql', 'zipstream', ], tests_require=['pytest-django', 'pytest-cov', 'factory-boy'], diff --git a/telemeta/management/commands/telemeta-create-admin-user.py b/telemeta/management/commands/telemeta-create-admin-user.py new file mode 100644 index 00000000..23a274f7 --- /dev/null +++ b/telemeta/management/commands/telemeta-create-admin-user.py @@ -0,0 +1,24 @@ +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User + + +class Command(BaseCommand): + help = """Create a default admin user if it doesn't exist. + you SHOULD change the password and the email afterwards!""" + + username = 'admin' + password = 'admin' + email = 'root@example.com' + + def handle(self, *args, **options): + admin = User.objects.filter(username=self.username) + if not admin: + user = User(username=self.username) + user.set_password(self.password) + user.email = self.email + user.is_superuser = True + user.is_staff = True + user.save() + print 'User "'+ self.username + '" created' -- 2.39.5