Initial commit of the fabric file for automatic installation

This commit is contained in:
Roberto Rosario
2012-05-31 20:38:25 -04:00
parent c7ea5271e4
commit ac500e48a4
12 changed files with 216 additions and 0 deletions

32
fabfile.py vendored Normal file
View File

@@ -0,0 +1,32 @@
import os
from fabric.api import run, sudo, cd, env, task
from fabfiles.databases import mysql
from fabfiles.webservers import apache
from fabfiles.platforms import ubuntu
from fabfiles.conf import setup_paths
@task(default=True)
def install(**kwargs):
setup_paths(**kwargs)
ubuntu.install_dependencies()
ubuntu.install_mayan()
mysql.install_database_manager()
mysql.create_database()
ubuntu.fix_permissions()
apache.install()
apache.install_site()
apache.restart()
@task
def uninstall(**kwargs):
setup_paths(**kwargs)
ubuntu.uninstall()
apache.remove_site()

0
fabfiles/__init__.py Normal file
View File

14
fabfiles/conf.py Normal file
View File

@@ -0,0 +1,14 @@
import os
from fabric.api import run, sudo, cd, env, task
from literals import DEFAULT_INSTALL_PATH, DEFAULT_VIRTUALENV_NAME, DEFAULT_REPOSITORY_NAME, DEFAULT_OS
def setup_paths(**kwargs):
env['os'] = kwargs.pop('os', DEFAULT_OS)
env['install_path'] = kwargs.pop('path', DEFAULT_INSTALL_PATH[env.os])
env['virtualenv_name'] = kwargs.pop('virtualenv_name', DEFAULT_VIRTUALENV_NAME[env.os])
env['repository_name'] = kwargs.pop('repository_name', DEFAULT_REPOSITORY_NAME[env.os])
env['virtualenv_path'] = os.path.join(env.install_path, env.virtualenv_name)
env['repository_path'] = os.path.join(env.virtualenv_path, env.repository_name)

View File

View File

@@ -0,0 +1,20 @@
from fabric.api import run, sudo, cd, env, task
@task
def install_database_manager():
print('Installing MySQL')
sudo('apt-get install -y mysql-server libmysqlclient-dev')
with cd(env.virtualenv_path):
sudo('source bin/activate; pip install MySQL-python')
@task
def create_database(*args, **kwargs):
print('Setting up Mayan EDMS\'s MySQL database')
#TODO: create DB and mayan user
#TODO: custom settings_local

15
fabfiles/literals.py Normal file
View File

@@ -0,0 +1,15 @@
OS_UBUNTU = 'ubuntu'
DEFAULT_INSTALL_PATH = {
OS_UBUNTU: '/usr/share'
}
DEFAULT_VIRTUALENV_NAME = {
OS_UBUNTU: 'mayan'
}
DEFAULT_REPOSITORY_NAME = {
OS_UBUNTU: 'mayan'
}
DEFAULT_OS = OS_UBUNTU

View File

View File

@@ -0,0 +1,50 @@
from fabric.api import run, sudo, cd, env, task
from ..conf import setup_paths
@task
def install_dependencies():
print('Installing dependencies')
sudo('apt-get install -y git-core gcc tesseract-ocr unpaper python-virtualenv ghostscript libjpeg-dev libpng-dev poppler-utils')
@task
def uninstall(**kwargs):
drop_database=kwargs.pop('drop_database', False)
setup_paths(**kwargs)
print('Uninstalling Mayan EDMS from: %s' % env.virtualenv_path)
sudo('rm %s -Rf' % env.virtualenv_path)
if drop_database:
#TODO: drop database
pass
@task
def fix_permissions(**kwargs):
setup_paths(**kwargs)
sudo('chmod 777 %s -R' % env.virtualenv_path)
sudo('chgrp www-data %s -R' % env.virtualenv_path)
@task
def install_mayan():
print('Installing Mayan EDMS from git repository')
with cd(env.install_path):
sudo('virtualenv --no-site-packages %s' % env.virtualenv_name)
with cd(env.virtualenv_path):
sudo('git clone http://www.github.com/rosarior/mayan %s' % env.repository_name)
sudo('source bin/activate; pip install -r %s/requirements/production.txt' % env.repository_name)
@task
def syncdb(**kwargs):
setup_paths(**kwargs)
with cd(env.virtualenv_path):
sudo('source bin/activate; %(repository_name)s/manage.py syncdb --noinput; %(repository_name)s/manage.py migrate' % (env))

20
fabfiles/templates.py Normal file
View File

@@ -0,0 +1,20 @@
import os
TEMPLATE_DIR = 'fabfiles/templates'
class Template(object):
def open(self, filename):
self.descriptor = open(os.path.join(TEMPLATE_DIR, filename), 'r')
def load(self, filename, context=None):
self.open()
self.content = self.descriptor.read() % (context if context else {})
def save_as(self, filename):
output_descriptor = open(filename, 'w')
output_descriptor.write(self.content)
output_descriptor.close()
def close(self):
self.descriptor.close()

View File

@@ -0,0 +1,20 @@
<VirtualHost *:80>
# Uncomment if libapache2-mod-xsendfile is installed
# XSendFile On
# XSendFileAllowAbove On
WSGIScriptAlias / %(repository_path)/wsgi/dispatch.wsgi
<Directory %(repository_path)>
Order deny,allow
Allow from all
</Directory>
ErrorLog /var/log/apache2/mayan_error.log
LogLevel warn
CustomLog /var/log/apache2/mayan_access.log combined
Alias /mayan-static "%(repository_path)/static/"
<Location "/static">
SetHandler None
</Location>
</VirtualHost>

View File

View File

@@ -0,0 +1,45 @@
import os
from fabric.api import run, sudo, cd, env, task
from ..templates import Template
from ..conf import setup_paths
@task
def install():
print('Installing apache and mod-wsgi')
sudo('apt-get install -y apache2 libapache2-mod-wsgi')
# Get rid of Apache's default site
sudo('a2dissite default')
reload_webserver()
@task
def install_site(**kwargs):
print('Adding Mayan EDMS\'s virtualhost file to apache')
setup_paths(**kwargs)
#TODO: mod site with paths
sudo('cp %s /etc/apache2/sites-available/' % os.path.join(env.repository_path, 'contrib/apache/mayan'))
sudo('a2ensite mayan')
@task
def remove_site():
sudo('a2dissite mayan')
@task
def restart():
print('Restarting the web server')
sudo('/etc/init.d/apache2 restart')
@task
def reload():
print('Reloading the web server')
sudo('/etc/init.d/apache2 reload')