# HG changeset patch # User Yves-Marie Haussonne # Date 1371719409 -7200 # Node ID ad3dd662b64f4d27fb26b87b0ce5859a579effb3 # Parent a92b8dc8de4da2d41d0fc3345a11ea764938d21a Add sync files diff -r a92b8dc8de4d -r ad3dd662b64f sbin/sync/config.py.tmpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sbin/sync/config.py.tmpl Thu Jun 20 11:10:09 2013 +0200 @@ -0,0 +1,57 @@ +from fabric.api import env +from random import choice + +env.hosts = ['iri@ns227785.ovh.net'] + +env.web_group = 'www-data' +env.folders = ['static/media'] + +env.repos = { + 'web' : {'repo':"/iridata/users/ymh/projects/festivalaix", 'src_root': 'src', 'module':''}, + 'metadatacomposer': {'repo':"/iridata/users/ymh/projects/metadatacomposer", 'src_root': 'src', 'module':''}, + 'ldt': {'repo':"/iridata/users/ymh/projects/platform", 'src_root': 'src/ldt', 'module':''}, +} +env.base_export_path = "~/tmp" +env.export_prefix = "festivalaix" + +env.remote_path = { + 'web':"/home/web/festivalaix/", + 'src':"/home/ldt/festivalaix/src", + 'virtualenv':"/home/ldt/virtualenv/festivalaix", + 'build_export':"/home/iri/tmp/build", + 'venv_export':"/home/iri/tmp/venv", +} + +env.platform_web_module = "aixweb" +env.remote_baseline_venv = "/home/ldt/virtualenv/baseline" + +env.rsync_filters = { + 'src' : [ + "P .htpasswd", + "P .htaccess", + "P aixweb/config.py", + ], + 'venv': [ + "+ core", + ] +} +env.web_relaunch_cmd = "supervisorctl restart aixweb" + + +env.config = { + 'web': { + 'base_url': "/ldt/", + 'web_url': 'http://176.31.235.78', + 'db_engine':'postgresql_psycopg2', + 'db_name':'aixweb', + 'db_user': 'iri', + 'db_password': '', + 'db_host': '127.0.0.1', + 'db_port': 5432, + 'haystack_url' : 'http://localhost:9200', + 'haystack_index' : 'aixweb', + 'log_file' : '/var/log/ldt/aixweb.log', + 'secret_key' : ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]), + }, +} + diff -r a92b8dc8de4d -r ad3dd662b64f sbin/sync/fabfile.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sbin/sync/fabfile.py Thu Jun 20 11:10:09 2013 +0200 @@ -0,0 +1,84 @@ +from fablib import (export_version, do_sync_web, create_config, + clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv, + clean_rsync_folder, rsync_export, get_comp_versions_dict, SyncComp, + do_relaunch_server) +from fabric.api import task, env +from fabric.colors import green +import config #@UnusedImport +import imp +import os.path + +@task +def relaunch_server(do_collectstatic=True, do_syncdb=True): + print("Relaunch server") + do_relaunch_server(do_collectstatic, do_syncdb) + +@task +def sync_web(version): + print(green("sync web with version %s" % version)) + export_path = export_version(web=version) + export_path_full = os.path.join(export_path,'web') + do_sync_web(version, export_path_full) + create_config(export_path_full) + clean_export_folder(export_path) + relaunch_server() + +@task +def update_lib(version, package): + print(green("update %s with version %s" % (package,version))) + export_path = export_version(web=version) + export_path_full = os.path.join(export_path,'web') + lib_path = os.path.join(export_path_full, "virtualenv", "res", "lib") + + f, pathname, description = imp.find_module("patch", [lib_path]) + imp.load_module("patch", f, pathname, description) + f, pathname, description = imp.find_module("lib_create_env", [lib_path]) + lib_create_env = imp.load_module("lib_create_env", f, pathname, description) + + package_path_full = os.path.join(export_path_full, "virtualenv", "res", "src", lib_create_env.URLS[package]['local']) + + sync_install_build(package_path_full) + clean_export_folder(export_path) + relaunch_server() + + +@task +def create_virtualenv(version): + print(green("create virtualenv with version %s" % version)) + export_path = export_version(web=version) + export_path_web = os.path.join(export_path,'web') + venv_remote_export_path = "" + try: + virtualenv_path = os.path.join(export_path_web, "virtualenv") + + venv_remote_export_path = os.path.join(env.remote_path['venv_export'], env.export_prefix, version,"virtualenv") + rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv']) + do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv']) + finally: + clean_export_folder(export_path) + if venv_remote_export_path: + clean_rsync_folder(venv_remote_export_path) + +if len(env.repos) > 1: + @task + def sync_platform(version): + print(green("sync platform with version web %s" % (version))) + export_path = export_version(web=version) + + export_path_web = os.path.join(export_path,'web') + do_sync_web(version, export_path_web) + + comp_versions = get_comp_versions_dict(export_path_web) + + for key in [k for k in env.repos if k != 'web']: + export_path_key = export_version(**{key: comp_versions[key]}) + export_path_comp = os.path.join(export_path_key, key) + do_sync_comp(key, export_path_comp) + clean_export_folder(export_path_key) + + create_config(export_path_web) + clean_export_folder(export_path) + relaunch_server() + +for sync_name in [key for key in env.repos if key != 'web']: + globals()[sync_name] = SyncComp(sync_name)