From 6449df6af42791484b2117911302305fbf8afa4f Mon Sep 17 00:00:00 2001 From: Bryan Date: Tue, 3 Dec 2013 22:08:03 -0500 Subject: [PATCH] separating env, code, and project directories while also making it easier to mix them for #182 --- fabfile.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/fabfile.py b/fabfile.py index 01385ad..5eea3ea 100644 --- a/fabfile.py +++ b/fabfile.py @@ -15,7 +15,8 @@ env.proj_repo = 'git@github.com:FinalsClub/karmaworld.git' env.repo_root = '~/karmaworld' env.proj_root = '/var/www/karmaworld' env.branch = 'prod' -env.code_root = '{0}/{1}-code'.format(env.proj_root, env.branch) +env.code_root = proj_root +env.env_root = proj_root env.supervisor_conf = '{0}/confs/{1}/supervisord.conf'.format(env.code_root, env.branch) ######## Define host(s) @@ -66,12 +67,19 @@ def beta(): env.branch = 'beta' ######## Run Commands in Virutal Environment +def virtenv_path(): + """ + Builds the virtualenv path. + """ + # not much here now, but maybe useful later. + return env.env_root + def virtenv_exec(command): """ Execute command in Virtualenv """ - path = os.path.sep.join( (env.proj_root, env.branch) ) + path = virtenv_path() with prefix('source {0}/bin/activate'.format(path)): run(command) @@ -91,7 +99,7 @@ def collect_static(): Collect static files (if AWS config. present, push to S3) """ - virtenv_exec('%s/manage.py collectstatic --noinput' % env.proj_root ) + virtenv_exec('%s/manage.py collectstatic --noinput' % env.code_root ) ####### Run Dev Server @task @@ -100,20 +108,24 @@ def dev_server(): Runs the built-in django webserver """ - virtenv_exec('%s/manage.py runserver' % env.proj_root) + virtenv_exec('%s/manage.py runserver' % env.code_root) ####### Create Virtual Environment + @task -def make_virtualenv(): - """ - Create our Virtualenv in env.proj_root - """ +def link_code(): + """ + Link the karmaworld repo into the appropriate production location + """ + if not files.exists(env.code_root): + run('ln -s {0} {1}'.format(env.repo_root, env.code_root)) - path = os.path.sep.join( (env.proj_root, env.branch) ) - if not files.exists(path): - run('virtualenv {0}'.format(path)) - if not files.exists(env.code_root): - run('ln -s {0} {1}'.format(env.repo_root, env.code_root)) +@task +def make_virtualenv(): + """ + Create our Virtualenv + """ + run('virtualenv {0}'.format(virtenv_path()) @task def start_supervisord(): @@ -255,6 +267,7 @@ def first_deploy(): """ Sets up and deploys the project for the first time. """ + link_code() make_virtualenv() file_setup() check_secrets() -- 2.25.1