Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
env.user = APP_USER
env.use_shell = False

PROJECT_PATH = os.path.join(os.path.dirname(__file__))
PROJECT_PATH = os.path.dirname(__file__)
REPO_PATH = '/home/{}/{}'.format(APP_USER, APP_NAME)
SOURCE_VENV = 'source /usr/local/bin/virtualenvwrapper.sh'
WORKON_ENV = '{} && workon {}'.format(SOURCE_VENV, VENV_NAME)
Expand Down Expand Up @@ -80,7 +80,9 @@ def mkvirtualenv():


def manage(command):
default_settings = '{{ project_name }}.settings.{0}'.format(env.environment)
default_settings = '{{ project_name }}.settings.{0}'.format(
env.environment
)
django_settings = env.get('django_settings', default_settings)

with shell_env(DJANGO_SETTINGS_MODULE=django_settings):
Expand Down Expand Up @@ -140,8 +142,8 @@ def bootstrap():
))
sudo('chown -fR {0}:{0} {1}'.format(APP_USER, ssh_dir))

sudoers_file = os.path.join('/etc/sudoers.d/', APP_USER)
tmp_file = os.path.join('/tmp', APP_USER)
sudoers_file = '/etc/sudoers.d/{}'.format(APP_USER)
tmp_file = '/tmp/{}'.format(APP_USER)
if not exists(sudoers_file):
sudo('echo "{} ALL=NOPASSWD: ALL" > {}'.format(APP_USER, tmp_file))
sudo('chown root:root {}'.format(tmp_file))
Expand All @@ -150,15 +152,24 @@ def bootstrap():

sudo('apt-get update --fix-missing')

with settings(user=env.user):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fabric has some kind of helper function for that (I believe it's called line). Take a look ;)

bashrc = run('cat ~/.bashrc')
if 'DJANGO_SETTINGS_MODULE' not in bashrc:
default_settings = '{{ project_name }}.settings.{0}'.format(
env.environment
)
run('echo "export DJANGO_SETTINGS_MODULE={0}" >> ~/.bashrc'.format(
default_settings))


@task
def provision(branch='master'):
"""Run puppet"""

update_code(branch)

puppet_path = os.path.join(REPO_PATH, 'puppet/')
modules_path = os.path.join(puppet_path, 'modules')
puppet_path = '{}/puppet/'.format(REPO_PATH)
modules_path = '{}/modules'.format(puppet_path)
puppet_modules = '{}:/etc/puppet/modules'.format(modules_path)

if not exists('/usr/bin/puppet'):
Expand All @@ -169,7 +180,7 @@ def provision(branch='master'):
run('sudo python bootstrap.py')

if env.is_vagrant:
cmd = os.path.join(puppet_path, 'manifests', 'site.pp')
cmd = '{}/manifests/site.pp'.format(puppet_path)
else:
cmd = '-e "include {}"'.format(APP_NAME)

Expand Down