Permalink
Browse files

improve bootstrap.py

  • Loading branch information...
1 parent 5c08797 commit bdf36f4d0b536a2d28af0c834079e4bb52f989d4 @caiosv committed Sep 22, 2013
Showing with 90 additions and 56 deletions.
  1. +85 −47 bootstrap.py
  2. +5 −9 setup.py
View
@@ -8,8 +8,26 @@
env.user = 'ubuntu'
env.git_user_name = 'cSv'
env.git_user_email = 'caiovianna@gmail.com'
-#env.git_repo_dotfiles = 'git://github.com/caiosv/dotfiles.git'
-
+env.git_repo_dotfiles = 'git://github.com/caiosv/dotfiles.git'
+
+# env project
+env.git_repo_project = 'https://github.com/caiosv/atrend_shop.git'
+env.project_base = 'atrend'
+env.project_home = 'atrend_shop'
+env.project_requirements = '%(project_home)s/atrend_requirements.txt' % env
+
+# env database
+env.db_root = ''
+env.db_root_pass = ''
+env.db_user = ''
+env.db_user_pass = ''
+env.db_pass = ''
+env.db_name = ''
+# MySQL database commands
+env.db_create_user = 'CREATE USER "%(db_user)s"@"localhost" IDENTIFIED BY "%(db_user_pass)s"' % env
+env.db_create_database = 'CREATE DATABASE %(db_name)s' % env
+env.db_grant_all_privileges = 'GRANT ALL PRIVILEGES ON %(db_name)s.* TO "%(db_user)s"@"localhost"' % env
+env.db_flush_privileges = 'FLUSH PRIVILEGES'
INSTALL_PACKAGES = [
"vim",
@@ -101,18 +119,65 @@ def clone_dotfiles():
run('git submodule init && git submodule update')
#_____SET UP VIM PLUGIN COMMAND-T_____#
-if env.git_repo_dotfiles is not "git://github.com/caiosv/dotfiles.git":
- pass
-else:
- print magenta('SET UP VIM PLUGIN COMMAND-T..')
- sudo('apt-get install ruby1.8-dev')
- with cd('%(home)s/dotfiles/vim/bundle/command-t/ruby/command-t' % env):
- run('ruby extconf.rb')
- run('make')
+ if env.git_repo_dotfiles is not "git://github.com/caiosv/dotfiles.git":
+ pass
+ else:
+ print magenta('SET UP VIM PLUGIN COMMAND-T..')
+ sudo('apt-get install ruby1.8-dev')
+ with cd('%(home)s/dotfiles/vim/bundle/command-t/ruby/command-t' % env):
+ run('ruby extconf.rb')
+ run('make')
+
+ print magenta('[DONE] VIM PLUGIN COMMAND-T IS READY.')
+
+
+def _set_up_webservers():
+ """
+ """
+ hr()
+ print magenta("Set up Web Servers.")
+ hr()
+ with cd('%(home)s/%(project_base)s/%(project_home)s/conf/' % env):
+ print magenta('Automatic Green Unicorn..')
+ sudo('mv atrend_shop_app.conf /etc/init/') # green unicorn automatic start
- print magenta('[DONE] VIM PLUGIN COMMAND-T IS READY.')
+ #_____set up nginx_____#
+ print magenta("Set Up Nginx..")
+ sudo('mkdir -p /opt/%(project_base)s/logs/nginx/' % env)
+ sudo('ln -s %(home)s/%(project_base)s/%(project_home)s/static /opt/atrend' % env) # sys link static
+ sudo('mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.backup')
+ sudo('mv default /etc/nginx/sites-available/default')
+ print magenta('[DONE] Set up Web Servers.')
+def _set_up_database():
+ """
+ Set up database, create user, create database, set privileges.
+ """
+ print red('Start set up mysql:')
+ _mysql_execute(env.db_create_user, env.db_root, env.db_root_pass)
+ _mysql_execute(env.db_create_database, env.db_root, env.db_root_pass)
+ _mysql_execute(env.db_grant_all_privileges, env.db_root, env.db_root_pass)
+ _mysql_execute(env.db_flush_privileges, env.db_root, env.db_root_pass)
+ print red('[DONE] set up mysql')
+
+
+def _mysql_execute(sql, user=None, password=None):
+ """
+ Executes passed sql command using mysql shell.
+ """
+ user = user or env.conf.DB_USER
+
+ if user == 'root' and password is None:
+ password = _get_root_password()
+ elif password is None:
+ password = env.conf.DB_PASSWORD
+ sql = sql.replace("'", r'\"')
+
+ return run("echo '%s' | mysql --user='%s' --password='%s' " % (sql, user, password))
+
+
+#_____SET PROJECT_____#
def start_project():
"""
CLONE PROJECT FROM REPOSITORY AND THEN
@@ -142,24 +207,22 @@ def start_project():
run('git clone %(git_repo_project)s' % env)
- with prefix('source bin/activate'):
- if env.project_requirements is not '':
- pass
- else:
- env.project_requirements = raw_input(red('Please enter the path to your' + \
+ if env.project_requirements is not '':
+ pass
+ else:
+ env.project_requirements = raw_input(red('Please enter the path to your' + \
red('requirements file', bold=True) + \
': '))
- print magenta('Install Requirements..')
- run('pip install -r %(project_requirements)s' % env)
+ print magenta('Install Requirements..')
+ run('source bin/activate && pip install -r %(project_requirements)s' % env)
_set_up_webservers()
_set_up_database()
with cd('%(home)s/%(project_base)s' % env):
- with prefix('source bin/activate'):
- print magenta('Syncing database..')
- with cd('%(project_home)s' % env):
- run('python manage.py syncdb')
+ print magenta('Syncing database..')
+ with cd('%(project_home)s' % env):
+ run('. bin/activate && python manage.py syncdb')
hr()
print magenta('[DONE] PROJECT IS READY.')
hr()
@@ -180,31 +243,6 @@ def restart_webservers():
print magenta('[DONE] Web Servers is up.')
-def operations():
- hr()
- print (red("TEST OPERATIONS", bold=True))
- hr()
- print (magenta('Local system user: %(local_user)s' % env))
- with cd('/home'):
- run('pwd')
- run('ls -la')
- with cd('/ubuntu'):
- run('pwd')
- run('ls -la')
- with cd('/confs'):
- run('pwd')
- run('ls -la')
- with cd('/light'):
- run('pwd')
- run('ls -la')
- run('virtualenv /home/ubuntu/crappy')
- with cd('/home/ubuntu/crappy'):
- run('pwd')
- with prefix('source bin/activate'):
- run('ls -la')
- print red('%(home)s' % env)
-
-
def main():
from datetime import datetime
startTime = datetime.now()
View
@@ -1,25 +1,21 @@
from distutils.core import setup
-from light.install import _man_pages
+from light.install import _man_pages, _install_commands
VERSION = '0.1.0'
readme = open('README.txt').read()
long_description = """
-To find out what's new in this version of Fabric, please see `the changelog
+To find out what's new in this version of Light, please see `the changelog
<http://docs.light.org/en/%s/changelog.html>`_.
-You can also install the `in-development version
-<https://github.com/caiosv/light/tarball/master#egg=light-dev>`_ using
-pip, with `pip install fabric==dev`.
-
----
%s
----
-For more information, please see the Light website or execute ``light --help`.
+For more information, please see the Light website or execute ``man light`.
""" % (VERSION, readme)
@@ -36,7 +32,6 @@
# Package Info
packages=[
'light',
- 'light.cmds',
'light.api',
'light.colors',
'light.context_managers',
@@ -47,4 +42,5 @@
)
-_man_pages
+_man_pages()
+_install_commands()

0 comments on commit bdf36f4

Please sign in to comment.