def put(local_file): """Put a DB dump, available locally, in the remote dump location.""" utilities.notify(u'Loading a local db dump to the remote dump location.') execute(rebuild) operations.put(local_file, env.db_dump_file)
def merge(): utilities.notify(u'Now merging from the remote repository.') with prefix(env.workon): run('git merge ' + env.repository_branch + ' origin/' + env.repository_branch) run('git checkout ' + env.repository_branch) run(env.deactivate)
def clone(): utilities.notify(u'Now cloning from the remote repository.') with prefix(env.workon): run('git clone ' + env.repository_location + ' .') run('git checkout ' + env.repository_branch) run(env.deactivate)
def load(): """Load the DB from a valid SQL file.""" utilities.notify(u'Loading data into the database.') execute(rebuild) run('psql ' + env.db_name + ' --username='******' --file=' + env.db_dump_file)
def create(): """Create the DB.""" utilities.notify(u'Creating a new database.') run('createdb --template template0 --encoding UTF-8 ' '--owner {user} {name}'.format(user=env.db_user, name=env.db_name))
def ensure(): """Ensures the app configuration and process management is in place.""" utilities.notify(u'Ensuring the app is configured correctly.') execute(config) execute(management)
def sanity(): """Run a check on all project dependencies.""" utilities.notify(u'Starting the project sanity check. ' 'Here come the notifications:\n') utilities.sanity_check()
def e(e='local'): """Sets properties for the target, based on declared configuration.""" utilities.notify(u'Setting the environment for this task run.') DEFAULT_CONFIG = os.path.join(HERE, 'config.yaml') TARGETS_CONFIG = os.path.join(THERE, 'config.yaml') SENSITIVE_CONFIG = os.path.join(THERE, 'sensitive.yaml') if not os.path.exists(TARGETS_CONFIG): utilities.alert(u'No Quilt configuration file was found. Aborting.') return with open(DEFAULT_CONFIG) as default_file: default = yaml.load(default_file) with open(TARGETS_CONFIG) as targets_file: targets = yaml.load(targets_file) utilities.set_on_env(default, env) utilities.set_on_env(targets[e], env) if os.path.exists(SENSITIVE_CONFIG): with open(SENSITIVE_CONFIG) as sensitive_file: sensitives = yaml.load(sensitive_file) utilities.set_on_env(sensitives[e], env) utilities.notify(u'The target environment is ' + unicode(e))
def collectstatic(): """Run static resource management for the project.""" utilities.notify(u'Now running Django static asset collector.') with prefix(env.workon): run('python manage.py collectstatic') run(env.deactivate)
def validate(): """Run validation checks over the codebase.""" utilities.notify(u'Now running Django validations.') with prefix(env.workon): run('python manage.py validate') run(env.deactivate)
def migrate(): """Run data migrations for the project.""" utilities.notify(u'Now running Django migrations.') with prefix(env.workon): run('python manage.py syncdb --noinput --migrate') run(env.deactivate)
def config(): """Ensures the app configuration is in place.""" utilities.notify(u'Ensuring the app configuration settings.') context = env cuisine.mode_sudo() content = cuisine.text_template(env.app_config_template, context) cuisine.file_write(env.app_config_file, content) execute(restart)
def initial_data(): """Load any initial data into the DB.""" utilities.notify(u'Loading initial data.') with prefix(env.workon): if env.project_initial_data: for f in env.project_initial_data: local('python manage.py loaddata ' + f) run(env.deactivate)
def upgrade(): """A sequence that upgrades the project codebase and dependencies.""" utilities.notify(u'Now starting the project upgrade sequence.') vcs.fetch() vcs.merge() environ.ensure() validate() migrate()
def management(): """Ensures the app process management is in place.""" utilities.notify(u'Ensuring the app management settings.') context = env cuisine.mode_sudo() content = cuisine.text_template(env.app_management_template, context) cuisine.file_write(env.app_management_file, content) execute(update) execute(restart)
def command(cmd, activate='no'): """Execute a command.""" utilities.notify(u'Now executing the command you passed.') if activate == 'yes': with prefix(env.workon): run(cmd) run(env.deactivate) else: run(cmd)
def deploy(): """A sequence that deploys new code to a target.""" utilities.notify(u'Now starting the project deploy sequence.') execute(vcs.fetch) execute(vcs.merge) execute(validate) execute(migrate) execute(collectstatic) execute(app.restart) execute(proxy.restart)
def test(): """Run tests for the project code.""" utilities.notify(u'Running the project test suite.') project_namespace = env.project_name + '.apps.' project_apps = [] for a in env.project_packages: if a.startswith(project_namespace): project_apps.append(a[len(project_namespace):]) run('python manage.py test ' + ' '.join(project_apps))
def upgrade(): """A sequence that upgrades the project codebase and dependencies.""" utilities.notify(u'Now starting the project upgrade sequence.') execute(vcs.fetch) execute(vcs.merge) execute(environ.ensure) execute(validate) execute(migrate) execute(collectstatic) execute(proxy.ensure) execute(app.ensure) execute(queue.ensure)
def build(): """A sequence that makes the initial build of the project environment.""" utilities.notify(u'Now building out the remote environment.') execute(environ.make) execute(vcs.clone) execute(environ.ensure) execute(db.create) execute(validate) execute(migrate) execute(db.initial_data) execute(collectstatic) execute(proxy.ensure) execute(app.ensure) execute(queue.ensure)
def bootstrap(initial='no', environment='no', clear_cache='no'): """A sequence the cleans and rebuilds the project environment.""" utilities.notify(u'Bootstrapping the project. Hold on tight.') if initial == 'yes': db.create() else: db.rebuild() migrate() db.initial_data() if environment == 'yes': env.ensure() if clear_cache == 'yes': cache.flush()
def bootstrap(initial='no', environment='no', clear_cache='no'): """A sequence the cleans and rebuilds the project environment.""" utilities.notify(u'Bootstrapping the project. Hold on tight.') if initial == 'yes': execute(db.create) else: execute(db.rebuild) execute(migrate) execute(db.initial_data) if environment == 'yes': execute(env.ensure) if clear_cache == 'yes': execute(cache.flush) execute(app.restart) execute(proxy.restart)
def ensure(): utilities.notify(u'Ensuring all project dependencies are present.') pip()
def npm(): utilities.notify(u'Ensuring all Node.js dependencies are present.') local('npm install')
def bower(): utilities.notify(u'Ensuring all client-side dependencies are present.') local('bower install')
def pip(): utilities.notify(u'Ensuring all Python dependencies are present.') local('pip install -U -r requirements.txt')
def ensure_settings(): utilities.notify(u'Configuring local settings.') context = env content = cuisine.text_template(env.project_config_template, context) cuisine.file_write(env.project_config_file, content)
def clone(): utilities.notify(u'Now cloning from the remote repository.') local('git clone ' + env.repository_location + ' .') local('git checkout ' + env.repository_branch)
def merge(): utilities.notify(u'Now merging from the remote repository.') local('git merge ' + env.repository_branch + ' origin/' + env.repository_branch) local('git checkout ' + env.repository_branch)
def fetch(): utilities.notify(u'Now fetching from the remote repository.') local('git fetch')
def fetch(): utilities.notify(u'Now fetching from the remote repository.') with prefix(env.workon): run('git fetch') run(env.deactivate)