diff --git a/.gitignore b/.gitignore index 87fb20d6..50321a5d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ umap/settings/local.py umap/settings/local/* docs/_build +umap/remote_static \ No newline at end of file diff --git a/fabfile.py b/fabfile.py index f786dd7d..55a513e3 100644 --- a/fabfile.py +++ b/fabfile.py @@ -11,31 +11,40 @@ env.requirements_file = 'requirements.pip' env.restart_sudo = False +def run_as_umap(*args, **kwargs): + if env.restart_sudo: + kwargs['user'] = "umap" + return sudo(*args, **kwargs) + else: + return run(*args, **kwargs) + + #============================================================================== # Tasks which set up deployment environments #============================================================================== @task -def live(): +def osmfr(): """ - Use the live deployment environment. + OSM-fr servers. """ - server = 'umap.org' + server = 'osm102.openstreetmap.fr' env.roledefs = { 'web': [server], 'db': [server], } env.system_users = {server: 'www-data'} - env.virtualenv_dir = '/home/ybon/.virtualenvs/{project_name}'.format(**env) - env.project_dir = '{virtualenv_dir}/src/{project_name}'.format(**env) + env.virtualenv_dir = '/data/project/umap/.virtualenvs/{project_name}'.format(**env) + env.project_dir = '/data/project/umap/src/{project_name}'.format(**env) env.project_conf = '{project_name}.settings.local'.format(**env) - env.restart_command = 'circusctl restart {project_name}'.format(**env) + env.restart_command = 'touch {project_dir}/umap/wsgi.py'.format(**env) + env.restart_sudo = True @task def dev(): """ - Use the development deployment environment. + Kimsufi dev server. """ server = 'ks3267459.kimsufi.com' env.roledefs = { @@ -133,7 +142,7 @@ def update(action='check'): """ with cd(env.project_dir): remote, dest_branch = env.remote_ref.split('/', 1) - run('git fetch {remote}'.format(remote=remote, + run_as_umap('git fetch {remote}'.format(remote=remote, dest_branch=dest_branch, **env)) with hide('running', 'stdout'): changed_files = run('git diff-index --cached --name-only ' @@ -145,10 +154,10 @@ def update(action='check'): reqs_changed = env.requirements_file in changed_files else: reqs_changed = False - run('git merge {remote_ref}'.format(**env)) - run('find -name "*.pyc" -delete') + run_as_umap('git merge {remote_ref}'.format(**env)) + run_as_umap('find -name "*.pyc" -delete') if action == "clean": - run('git clean -df') + run_as_umap('git clean -df') if action == 'force' or reqs_changed: # Not using execute() because we don't want to run multiple times for # each role (since this task gets run per role). @@ -164,8 +173,6 @@ def collectstatic(): collect_remote_statics() dj('collectstatic --link --noinput') dj('compress') - # with cd('{virtualenv_dir}/var/static'.format(**env)): - # fix_permissions() @task @@ -183,11 +190,7 @@ def restart(): """ Restart the web service. """ - if env.restart_sudo: - cmd = sudo - else: - cmd = run - cmd(env.restart_command) + run_as_umap(env.restart_command) @task @@ -205,10 +208,10 @@ def requirements(name=None, upgrade=False): "project_dir": env.project_dir, "requirements_file": env.requirements_file, } - run('{base_command} -r {project_dir}/{requirements_file}'\ + run_as_umap('{base_command} -r {project_dir}/{requirements_file}'\ .format(**kwargs)) else: - run('{base_command} {name}'.format( + run_as_umap('{base_command} {name}'.format( base_command=base_command, name=name )) @@ -222,37 +225,19 @@ def dj(command): """ Run a Django manage.py command on the server. """ - run('{virtualenv_dir}/bin/python {project_dir}/manage.py {dj_command} ' + run_as_umap('{virtualenv_dir}/bin/python {project_dir}/manage.py {dj_command} ' '--settings {project_conf}'.format(dj_command=command, **env)) -def fix_permissions(path='.'): - """ - Fix the file permissions. - """ - if ' ' in path: - full_path = '{path} (in {cwd})'.format(path=path, cwd=env.cwd) - else: - full_path = posixpath.normpath(posixpath.join(env.cwd, path)) - puts('Fixing {0} permissions'.format(full_path)) - with hide('running'): - system_user = env.system_users.get(env.host) - if system_user: - run('chmod -R g=rX,o= -- {0}'.format(path)) - run('chgrp -R {0} -- {1}'.format(system_user, path)) - else: - run('chmod -R go= -- {0}'.format(path)) - - def collect_remote_statics(): """ Add leaflet and leaflet.draw in a repository watched by collectstatic. """ remote_static_dir = '{project_dir}/{project_name}/remote_static'.format(**env) - run('mkdir -p {0}'.format(remote_static_dir)) + run_as_umap('mkdir -p {0}'.format(remote_static_dir)) remote_repositories = { - 'leaflet': "git://github.com/Leaflet/Leaflet.git@master", - 'draw': "git://github.com/Leaflet/Leaflet.draw.git@master", + 'leaflet': "git://github.com/Leaflet/Leaflet.git@master#v0.6.2", + 'draw': "git://github.com/Leaflet/Leaflet.draw.git@master#v0.2.1", 'hash': "git://github.com/mlevans/leaflet-hash.git@master", 'storage': 'git://github.com/yohanboniface/Leaflet.Storage.git@master', 'edit_in_osm': 'git://github.com/yohanboniface/Leaflet.EditInOSM.git@master', @@ -268,11 +253,11 @@ def collect_remote_statics(): else: ref = branch with hide("running", "stdout"): - exists = run('if [ -d "{0}" ]; then echo 1; fi'.format(subdir)) + exists = run_as_umap('if [ -d "{0}" ]; then echo 1; fi'.format(subdir)) if exists: with cd(subdir): - run('git pull origin {0}'.format(branch)) + run_as_umap('git pull origin {0}'.format(branch)) else: - run('git clone {0} {1}'.format(repository, subdir)) + run_as_umap('git clone {0} {1}'.format(repository, subdir)) with cd(subdir): - run('git checkout {0}'.format(ref)) + run_as_umap('git checkout {0}'.format(ref))