def update_project(skip_test="true", target_dir='tolong'): """ Updates the source directory with most recent code, create migration and then restarts the webserver """ setup_env(target_dir) if skip_test != "true": run_test() check_django_shell() # update temporary source code first, so we can know whether migration has addition # or deletion update_source_code(path=env.TEMP_SRC_PATH) symlink_settings_local() install_project_requirements(os.path.join(env.TEMP_SRC_PATH, 'requirements.txt')) migration_type = check_migration_type() if migration_type == "update_source_then_migrate": update_source_code() collect_static() # compress_static() restart_webserver() migrate() return elif migration_type == "migrate_then_update_source": # Migrate from temporary first migrate(env.TEMP_SRC_PATH) # then normal stuff without migration again update_source_code() elif migration_type is None: update_source_code() collect_static() # compress_static() restart_webserver()
def deploy_project(target_dir='tolong'): """ Deploys a project for the first time """ setup_env(target_dir) if exists("%s" % env.PROJECT_PATH): abort( 'Project already deployed. Run "fab update_project -H <host>" instead' ) setup_os() require.files.directory(env.PROJECT_PATH, use_sudo=True, owner='www-data', group='www-data') update_source_code(deploy=True) setup_virtualenv() log_dir = os.path.join(env.PROJECT_PATH, 'logs') require.files.directory(log_dir, use_sudo=True, owner='www-data', group='www-data') setup_webserver() create_db() context = { 'db_name': env.db_name, 'db_user': env.db_user, 'db_pass': env.db_pass, } upload_template('fabfiles/conf_templates/settings_local.py.tpl', env.HOME_PATH, context=context) sudo('mv %ssettings_local.py.tpl %s/%s/settings_local.py' % (env.HOME_PATH, env.SRC_PATH, env.PROJECT_NAME)) install_project_requirements() collect_static() # compress_static() sudo('chown -R www-data:www-data %s' % env.PROJECT_PATH) sudo('{0} syncdb'.format(env.MANAGE_BIN)) migrate() ''' print("""Finished deployment. Now you need to:\n 1. Edit your %s/settings_local.py file\n 2. Run "fab create_initial_migration -H <host>"\n 3. Connect to server and run "%s manage.py syncdb" from %ssrc\n 4. Run "fab migrate -H <host>"\n 5. Run "fab collect_static -H <host>" """ % (env.SRC_PATH, env.PYTHON_BIN, env.PROJECT_PATH)) ''' restart_webserver()
def deploy_project(target_dir='tolong'): """ Deploys a project for the first time """ setup_env(target_dir) if exists("%s" % env.PROJECT_PATH): abort('Project already deployed. Run "fab update_project -H <host>" instead') setup_os() require.files.directory(env.PROJECT_PATH, use_sudo=True, owner='www-data', group='www-data') update_source_code(deploy=True) setup_virtualenv() log_dir = os.path.join(env.PROJECT_PATH, 'logs') require.files.directory(log_dir, use_sudo=True, owner='www-data', group='www-data') setup_webserver() create_db() context = { 'db_name': env.db_name, 'db_user': env.db_user, 'db_pass': env.db_pass, } upload_template('fabfiles/conf_templates/settings_local.py.tpl', env.HOME_PATH, context=context) sudo('mv %ssettings_local.py.tpl %s/%s/settings_local.py' % (env.HOME_PATH, env.SRC_PATH, env.PROJECT_NAME)) install_project_requirements() collect_static() # compress_static() sudo('chown -R www-data:www-data %s' % env.PROJECT_PATH) sudo('{0} syncdb'.format(env.MANAGE_BIN)) migrate() ''' print("""Finished deployment. Now you need to:\n 1. Edit your %s/settings_local.py file\n 2. Run "fab create_initial_migration -H <host>"\n 3. Connect to server and run "%s manage.py syncdb" from %ssrc\n 4. Run "fab migrate -H <host>"\n 5. Run "fab collect_static -H <host>" """ % (env.SRC_PATH, env.PYTHON_BIN, env.PROJECT_PATH)) ''' restart_webserver()