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-27 11:15:18 +05:30
commit ba5165ebbb
No known key found for this signature in database
GPG Key ID: 735490161CD5C91E
5 changed files with 43 additions and 15 deletions

View File

@ -55,10 +55,15 @@ def setup_production(user, yes=False):
from bench.config.production_setup import setup_production
from bench.utils import run_playbook
# Install prereqs for production
exec_cmd("sudo pip install ansible")
exec_cmd("bench setup role fail2ban")
exec_cmd("bench setup role nginx")
exec_cmd("bench setup role supervisor")
from distutils.spawn import find_executable
if not find_executable('ansible'):
exec_cmd("sudo pip install ansible")
if not find_executable('fail2ban-client'):
exec_cmd("bench setup role fail2ban")
if not find_executable('nginx'):
exec_cmd("bench setup role nginx")
if not find_executable('supervisord'):
exec_cmd("bench setup role supervisor")
setup_production(user=user, yes=yes)
@ -116,10 +121,11 @@ def set_ssh_port(port, force=False):
@click.command('lets-encrypt')
@click.argument('site')
@click.option('--custom-domain')
def setup_letsencrypt(site, custom_domain):
@click.option('-n', '--non-interactive', default=False, is_flag=True, help="Run certbot non-interactively. Shouldn't be used on 1'st attempt")
def setup_letsencrypt(site, custom_domain, non_interactive):
"Setup lets-encrypt for site"
from bench.config.lets_encrypt import setup_letsencrypt
setup_letsencrypt(site, custom_domain, bench_path='.')
setup_letsencrypt(site, custom_domain, bench_path='.', interactive=not non_interactive)
@click.command('procfile')

View File

@ -11,7 +11,7 @@ try:
except ImportError:
from urllib import urlretrieve
def setup_letsencrypt(site, custom_domain, bench_path):
def setup_letsencrypt(site, custom_domain, bench_path, interactive):
site_path = os.path.join(bench_path, "sites", site, "site_config.json")
if not os.path.exists(os.path.dirname(site_path)):
@ -38,7 +38,7 @@ def setup_letsencrypt(site, custom_domain, bench_path):
return
create_config(site, custom_domain)
run_certbot_and_setup_ssl(site, custom_domain, bench_path)
run_certbot_and_setup_ssl(site, custom_domain, bench_path, interactive)
setup_crontab()
@ -51,12 +51,13 @@ def create_config(site, custom_domain):
f.write(config)
def run_certbot_and_setup_ssl(site, custom_domain, bench_path):
def run_certbot_and_setup_ssl(site, custom_domain, bench_path, interactive=True):
service('nginx', 'stop')
get_certbot()
try:
exec_cmd("{path} -n --config /etc/letsencrypt/configs/{site}.cfg certonly".format(path=get_certbot_path(), site=custom_domain or site))
interactive = '' if interactive else '-n'
exec_cmd("{path} {interactive} --config /etc/letsencrypt/configs/{site}.cfg certonly".format(path=get_certbot_path(), interactive=interactive, site=custom_domain or site))
except CommandFailedError:
service('nginx', 'start')
print("There was a problem trying to setup SSL for your site")

View File

@ -103,8 +103,17 @@ def install_bench(args):
if args.production:
extra_vars.update(max_worker_connections=multiprocessing.cpu_count() * 1024)
branch = 'master' if args.production else 'develop'
extra_vars.update(branch=branch)
if args.frappe_branch:
frappe_branch = args.frappe_branch
else:
frappe_branch = 'master' if args.production else 'develop'
extra_vars.update(frappe_branch=frappe_branch)
if args.erpnext_branch:
erpnext_branch = args.erpnext_branch
else:
erpnext_branch = 'master' if args.production else 'develop'
extra_vars.update(erpnext_branch=erpnext_branch)
bench_name = 'frappe-bench' if not args.bench_name else args.bench_name
extra_vars.update(bench_name=bench_name)
@ -359,6 +368,18 @@ def parse_commandline_args():
parser.add_argument('--repo-url', dest='repo_url', help='Clone bench from the given url')
parser.add_argument('--frappe-repo-url', dest='frappe_repo_url', action='store', default='https://github.com/frappe/frappe',
help='Clone frappe from the given url')
parser.add_argument('--frappe-branch', dest='frappe_branch', action='store',
help='Clone a particular branch of frappe')
parser.add_argument('--erpnext-repo-url', dest='erpnext_repo_url', action='store', default='https://github.com/frappe/erpnext',
help='Clone erpnext from the given url')
parser.add_argument('--erpnext-branch', dest='erpnext_branch', action='store',
help='Clone a particular branch of erpnext')
# To enable testing of script using Travis, this should skip the prompt
parser.add_argument('--run-travis', dest='run_travis', action='store_true', default=False,
help=argparse.SUPPRESS)

View File

@ -29,13 +29,13 @@
register: bench_stat
- name: python3 bench init for develop
command: bench init {{ bench_path }} --frappe-branch {{ branch }} --python {{ python }}
command: bench init {{ bench_path }} --frappe-path {{ frappe_repo_url }} --frappe-branch {{ frappe_branch }} --python {{ python }}
args:
creates: "{{ bench_path }}"
when: not bench_stat.stat.exists and not production
- name: python2 bench init for production
command: bench init {{ bench_path }} --frappe-branch {{ branch }}
command: bench init {{ bench_path }} --frappe-path {{ frappe_repo_url }} --frappe-branch {{ frappe_branch }}
args:
creates: "{{ bench_path }}"
when: not bench_stat.stat.exists and production

View File

@ -4,7 +4,7 @@
register: app
- name: Get the ERPNext app
command: bench get-app erpnext https://github.com/frappe/erpnext --branch {{ branch }}
command: bench get-app erpnext {{ erpnext_repo_url }} --branch {{ erpnext_branch }}
args:
creates: "{{ bench_path }}/apps/erpnext"
chdir: "{{ bench_path }}"