2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-11 15:51:03 +00:00

Merge branch 'master' into systemd

This commit is contained in:
Ameya Shenoy 2018-04-14 15:56:26 +05:30 committed by GitHub
commit 3b8f9441cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 82 additions and 36 deletions

View File

@ -64,6 +64,33 @@ def check_url(url, raise_err = True):
return True
def get_excluded_apps(bench_path='.'):
try:
with open(os.path.join(bench_path, 'sites', 'excluded_apps.txt')) as f:
return f.read().strip().split('\n')
except IOError:
return []
def add_to_excluded_apps_txt(app, bench_path='.'):
if app == 'frappe':
raise ValueError('Frappe app cannot be excludeed from update')
if app not in os.listdir('apps'):
raise ValueError('The app {} does not exist'.format(app))
apps = get_excluded_apps(bench_path=bench_path)
if app not in apps:
apps.append(app)
return write_excluded_apps_txt(apps, bench_path=bench_path)
def write_excluded_apps_txt(apps, bench_path='.'):
with open(os.path.join(bench_path, 'sites', 'excluded_apps.txt'), 'w') as f:
return f.write('\n'.join(apps))
def remove_from_excluded_apps_txt(app, bench_path='.'):
apps = get_excluded_apps(bench_path=bench_path)
if app in apps:
apps.remove(app)
return write_excluded_apps_txt(apps, bench_path=bench_path)
def get_app(git_url, branch=None, bench_path='.', build_asset_files=True, verbose=False):
# from bench.utils import check_url
try:
@ -173,6 +200,10 @@ def pull_all_apps(bench_path='.', reset=False):
# chech for local changes
if not reset:
for app in get_apps(bench_path=bench_path):
excluded_apps = get_excluded_apps()
if app in excluded_apps:
print("Skipping reset for app {}".format(app))
continue
app_dir = get_repo_dir(app, bench_path=bench_path)
if os.path.exists(os.path.join(app_dir, '.git')):
out = subprocess.check_output(["git", "status"], cwd=app_dir)
@ -192,6 +223,10 @@ Here are your choices:
sys.exit(1)
for app in get_apps(bench_path=bench_path):
excluded_apps = get_excluded_apps()
if app in excluded_apps:
print("Skipping pull for app {}".format(app))
continue
app_dir = get_repo_dir(app, bench_path=bench_path)
if os.path.exists(os.path.join(app_dir, '.git')):
remote = get_remote(app)
@ -219,7 +254,7 @@ def is_version_upgrade(app='frappe', bench_path='.', branch=None):
local_version = get_major_version(get_current_version(app, bench_path=bench_path))
upstream_version = get_major_version(upstream_version)
if upstream_version - local_version > 0:
return (True, local_version, upstream_version)

View File

@ -47,7 +47,7 @@ bench_command.add_command(switch_to_develop)
from bench.commands.utils import (start, restart, set_nginx_port, set_ssl_certificate, set_ssl_certificate_key, set_url_root,
set_mariadb_host, set_default_site, download_translations, shell, backup_site, backup_all_sites, release, renew_lets_encrypt,
disable_production, bench_src, prepare_staging)
disable_production, bench_src)
bench_command.add_command(start)
bench_command.add_command(restart)
bench_command.add_command(set_nginx_port)
@ -61,7 +61,6 @@ bench_command.add_command(shell)
bench_command.add_command(backup_site)
bench_command.add_command(backup_all_sites)
bench_command.add_command(release)
bench_command.add_command(prepare_staging)
bench_command.add_command(renew_lets_encrypt)
bench_command.add_command(disable_production)
bench_command.add_command(bench_src)
@ -180,4 +179,8 @@ def migrate_env(python, no_backup = False):
log.debug('Migration Error')
raise
bench_command.add_command(migrate_env)
bench_command.add_command(migrate_env)
from bench.commands.make import exclude_app_for_update, include_app_for_update
bench_command.add_command(exclude_app_for_update)
bench_command.add_command(include_app_for_update)

View File

@ -8,13 +8,14 @@ import click
@click.option('--frappe-path', default=None, help="path to frappe repo")
@click.option('--frappe-branch', default=None, help="path to frappe repo")
@click.option('--clone-from', default=None, help="copy repos from path")
@click.option('--clone-without-update', is_flag=True, help="copy repos from path without update")
@click.option('--no-procfile', is_flag=True, help="Pull changes in all the apps in bench")
@click.option('--no-backups',is_flag=True, help="Run migrations for all sites in the bench")
@click.option('--no-auto-update',is_flag=True, help="Build JS and CSS artifacts for the bench")
@click.option('--skip-redis-config-generation', is_flag=True, help="Skip redis config generation if already specifying the common-site-config file")
@click.option('--verbose',is_flag=True, help="Verbose output during install")
def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups,
no_auto_update, clone_from, verbose, skip_redis_config_generation,
no_auto_update, clone_from, verbose, skip_redis_config_generation, clone_without_update,
ignore_exist = False,
python = 'python'): # Let's change we're ready. - <achilles@frappe.io>
'''
@ -24,6 +25,7 @@ def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups,
init(path, apps_path=apps_path, no_procfile=no_procfile, no_backups=no_backups,
no_auto_update=no_auto_update, frappe_path=frappe_path, frappe_branch=frappe_branch,
verbose=verbose, clone_from=clone_from, skip_redis_config_generation=skip_redis_config_generation,
clone_without_update=clone_without_update,
ignore_exist = ignore_exist,
python = python)
click.echo('Bench {} initialized'.format(path))
@ -52,3 +54,19 @@ def remove_app(app_name):
"completely remove app from bench"
from bench.app import remove_app
remove_app(app_name)
@click.command('exclude-app')
@click.argument('app_name')
def exclude_app_for_update(app_name):
"Exclude app from updating"
from bench.app import add_to_excluded_apps_txt
add_to_excluded_apps_txt(app_name)
@click.command('include-app')
@click.argument('app_name')
def include_app_for_update(app_name):
"Include app from updating"
from bench.app import remove_from_excluded_apps_txt
remove_from_excluded_apps_txt(app_name)

View File

@ -7,18 +7,18 @@ from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgra
restart_supervisor_processes, restart_systemd_processes)
from bench import patches
#TODO: Not DRY
@click.command('update')
@click.option('--pull', is_flag=True, help="Pull changes in all the apps in bench")
@click.option('--patch',is_flag=True, help="Run migrations for all sites in the bench")
@click.option('--build',is_flag=True, help="Build JS and CSS artifacts for the bench")
@click.option('--bench',is_flag=True, help="Update bench")
@click.option('--requirements',is_flag=True, help="Update requirements")
@click.option('--restart-supervisor',is_flag=True, help="restart supervisor processes after update")
@click.option('--restart-systemd',is_flag=True, help="restart systemd units after update")
@click.option('--auto',is_flag=True)
@click.option('--no-backup',is_flag=True)
@click.option('--force',is_flag=True)
@click.option('--patch', is_flag=True, help="Run migrations for all sites in the bench")
@click.option('--build', is_flag=True, help="Build JS and CSS artifacts for the bench")
@click.option('--bench', is_flag=True, help="Update bench")
@click.option('--requirements', is_flag=True, help="Update requirements")
@click.option('--restart-supervisor', is_flag=True, help="restart supervisor processes after update")
@click.option('--restart-systemd', is_flag=True, help="restart systemd units after update")
@click.option('--auto', is_flag=True)
@click.option('--no-backup', is_flag=True)
@click.option('--force', is_flag=True)
@click.option('--reset', is_flag=True, help="Hard resets git branch's to their new states overriding any changes and overriding rebase on pull")
def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, restart_systemd=False, requirements=False, no_backup=False, force=False, reset=False):
"Update bench"
@ -41,7 +41,7 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar
'requirements': requirements,
'no-backup': no_backup,
'restart-supervisor': restart_supervisor,
'reset':reset
'reset': reset
})
if conf.get('release_bench'):

View File

@ -135,14 +135,6 @@ def release(app, bump_type, from_branch, to_branch, owner, repo_name, remote):
release(bench_path='.', app=app, bump_type=bump_type, from_branch=from_branch, to_branch=to_branch,
remote=remote, owner=owner, repo_name=repo_name)
@click.command('prepare-staging')
@click.argument('app')
def prepare_staging(app):
"""Prepare staging branch from develop branch"""
from bench.prepare_staging import prepare_staging
prepare_staging(bench_path='.', app=app)
@click.command('disable-production')
def disable_production():
"""Disables production environment for the bench."""

View File

@ -56,7 +56,7 @@ def run_certbot_and_setup_ssl(site, custom_domain, bench_path):
get_certbot()
try:
exec_cmd("{path} --config /etc/letsencrypt/configs/{site}.cfg certonly".format(path=get_certbot_path(), site=custom_domain or site))
exec_cmd("{path} -n --config /etc/letsencrypt/configs/{site}.cfg certonly".format(path=get_certbot_path(), site=custom_domain or site))
except CommandFailedError:
service('nginx', 'start')
print("There was a problem trying to setup SSL for your site")

View File

@ -31,9 +31,6 @@ def release(bench_path, app, bump_type, from_branch='develop', to_branch='master
print('bench not configured to release')
sys.exit(1)
if config.get('branches_to_update'):
branches_to_update.update(config.get('branches_to_update'))
validate(bench_path, config)
bump(bench_path, app, bump_type, from_branch=from_branch, to_branch=to_branch, owner=owner,

View File

@ -36,6 +36,7 @@ def get_env_cmd(cmd, bench_path='.'):
def init(path, apps_path=None, no_procfile=False, no_backups=False,
no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None,
verbose=False, clone_from=None, skip_redis_config_generation=False,
clone_without_update=False,
ignore_exist = False,
python = 'python'): # Let's change when we're ready. - <achilles@frappe.io>
from .app import get_app, install_apps_from_path
@ -56,7 +57,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
try:
os.makedirs(os.path.join(path, dirname))
except OSError as e:
if e.errno != os.errno.EEXIST:
if e.errno == os.errno.EEXIST:
pass
setup_logging()
@ -66,7 +67,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
make_config(path)
if clone_from:
clone_apps_from(bench_path=path, clone_from=clone_from)
clone_apps_from(bench_path=path, clone_from=clone_from, update_app=not clone_without_update)
else:
if not frappe_path:
frappe_path = 'https://github.com/frappe/frappe.git'
@ -94,7 +95,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
if not no_auto_update:
setup_auto_update(bench_path=path)
def clone_apps_from(bench_path, clone_from):
def clone_apps_from(bench_path, clone_from, update_app=True):
from .app import install_app
print('Copying apps from {0}...'.format(clone_from))
subprocess.check_output(['cp', '-R', os.path.join(clone_from, 'apps'), bench_path])
@ -107,22 +108,22 @@ def clone_apps_from(bench_path, clone_from):
def setup_app(app):
# run git reset --hard in each branch, pull latest updates and install_app
app_path = os.path.join(bench_path, 'apps', app)
if os.path.exists(os.path.join(app_path, '.git')):
print('Cleaning up {0}'.format(app))
# remove .egg-ino
subprocess.check_output(['rm', '-rf', app + '.egg-info'], cwd=app_path)
# remove .egg-ino
subprocess.check_output(['rm', '-rf', app + '.egg-info'], cwd=app_path)
if update_app and os.path.exists(os.path.join(app_path, '.git')):
remotes = subprocess.check_output(['git', 'remote'], cwd=app_path).strip().split()
if 'upstream' in remotes:
remote = 'upstream'
else:
remote = remotes[0]
print('Cleaning up {0}'.format(app))
branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], cwd=app_path).strip()
subprocess.check_output(['git', 'reset', '--hard'], cwd=app_path)
subprocess.check_output(['git', 'pull', '--rebase', remote, branch], cwd=app_path)
install_app(app, bench_path)
install_app(app, bench_path)
with open(os.path.join(clone_from, 'sites', 'apps.txt'), 'r') as f:
apps = f.read().splitlines()