mirror of
https://github.com/frappe/bench.git
synced 2025-01-24 15:38:25 +00:00
[Fix] Bypassed get_passwords for development env, and extra_vars.json to be created in tmp directory
This commit is contained in:
parent
489663de0a
commit
3a0405bb54
@ -20,3 +20,4 @@
|
|||||||
|
|
||||||
- name: Set /tmp/.bench folder perms
|
- name: Set /tmp/.bench folder perms
|
||||||
command: 'chown -R {{ frappe_user }}:{{ frappe_user }} /tmp/.bench'
|
command: 'chown -R {{ frappe_user }}:{{ frappe_user }} /tmp/.bench'
|
||||||
|
when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'CentOS'
|
||||||
|
@ -41,10 +41,15 @@ def install_bench(args):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# In some cases setup_tools are not updated, We will force update it.
|
# In some cases setup_tools are not updated, We will force update it.
|
||||||
run_os_command({
|
success = run_os_command({
|
||||||
'pip': 'sudo pip install --upgrade setuptools'
|
'python': 'wget https://bootstrap.pypa.io/ez_setup.py'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if success:
|
||||||
|
run_os_command({
|
||||||
|
'python': 'sudo python ez_setup.py --user python'
|
||||||
|
})
|
||||||
|
|
||||||
# Restricting ansible version due to following bug in ansible 2.1
|
# Restricting ansible version due to following bug in ansible 2.1
|
||||||
# https://github.com/ansible/ansible-modules-core/issues/3752
|
# https://github.com/ansible/ansible-modules-core/issues/3752
|
||||||
success = run_os_command({
|
success = run_os_command({
|
||||||
@ -65,9 +70,9 @@ def install_bench(args):
|
|||||||
if args.production and not args.user:
|
if args.production and not args.user:
|
||||||
args.user = 'frappe'
|
args.user = 'frappe'
|
||||||
|
|
||||||
extra_vars = get_extra_vars(vars(args))
|
|
||||||
|
|
||||||
# create user if not exists
|
# create user if not exists
|
||||||
|
extra_vars = vars(args)
|
||||||
|
|
||||||
run_playbook('develop/create_user.yml', extra_vars=extra_vars)
|
run_playbook('develop/create_user.yml', extra_vars=extra_vars)
|
||||||
|
|
||||||
if args.develop:
|
if args.develop:
|
||||||
@ -105,7 +110,7 @@ def clone_bench_repo(args):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
branch = args.bench_branch or 'develop'
|
branch = args.bench_branch or 'develop'
|
||||||
repo_url = args.bench_repo_url or 'https://github.com/frappe/bench'
|
repo_url = args.repo_url or 'https://github.com/frappe/bench'
|
||||||
|
|
||||||
success = run_os_command(
|
success = run_os_command(
|
||||||
{'git': 'git clone {repo_url} {bench_repo} --depth 1 --branch {branch}'.format(
|
{'git': 'git clone {repo_url} {bench_repo} --depth 1 --branch {branch}'.format(
|
||||||
@ -168,45 +173,42 @@ def get_passwords(run_travis=False):
|
|||||||
'admin_password': admin_password
|
'admin_password': admin_password
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_vars_json_path(extra_vars):
|
def get_extra_vars_json(extra_args, run_travis=False):
|
||||||
json_path = os.path.join(os.path.abspath(os.path.expanduser('~')), 'extra_vars.json')
|
# We need to pass production as extra_vars to the playbook to execute conditionals in the
|
||||||
|
# playbook. Extra variables can passed as json or key=value pair. Here, we will use JSON.
|
||||||
|
json_path = os.path.join('/tmp', 'extra_vars.json')
|
||||||
|
extra_vars = dict(extra_args.items())
|
||||||
|
|
||||||
|
if extra_args.get('production'):
|
||||||
|
run_travis = extra_args.get('run_travis')
|
||||||
|
extra_vars.update(get_passwords(run_travis))
|
||||||
|
extra_vars.update(max_worker_connections=multiprocessing.cpu_count() * 1024)
|
||||||
|
|
||||||
|
branch = 'master' if extra_args.get('setup_production') else 'develop'
|
||||||
|
extra_vars.update(branch=branch)
|
||||||
|
|
||||||
|
user = args.user or getpass.getuser()
|
||||||
|
if user == 'root':
|
||||||
|
raise Exception('--user cannot be root')
|
||||||
|
|
||||||
|
extra_vars['frappe_user'] = user
|
||||||
|
|
||||||
with open(json_path, mode='w') as j:
|
with open(json_path, mode='w') as j:
|
||||||
json.dump(extra_vars, j, indent=1, sort_keys=True)
|
json.dump(extra_vars, j, indent=1, sort_keys=True)
|
||||||
|
|
||||||
return ('@' + json_path)
|
return ('@' + json_path)
|
||||||
|
|
||||||
def get_extra_vars(extra_args):
|
|
||||||
extra_vars = dict(extra_args.items())
|
|
||||||
|
|
||||||
run_travis = extra_args.get('run_travis')
|
|
||||||
extra_vars.update(get_passwords(run_travis))
|
|
||||||
|
|
||||||
branch = 'master' if extra_args.get('setup_production') else 'develop'
|
|
||||||
extra_vars.update(branch=branch)
|
|
||||||
|
|
||||||
extra_vars.update(max_worker_connections=multiprocessing.cpu_count() * 1024)
|
|
||||||
|
|
||||||
user = args.user or getpass.getuser()
|
|
||||||
|
|
||||||
if user == 'root':
|
|
||||||
raise Exception('--user cannot be root')
|
|
||||||
|
|
||||||
extra_vars['frappe_user'] = user
|
|
||||||
|
|
||||||
return extra_vars
|
|
||||||
|
|
||||||
def run_playbook(playbook_name, sudo=False, extra_vars=None):
|
def run_playbook(playbook_name, sudo=False, extra_vars=None):
|
||||||
args = ['ansible-playbook', '-c', 'local', playbook_name]
|
args = ['ansible-playbook', '-c', 'local', playbook_name]
|
||||||
|
|
||||||
if extra_vars:
|
if extra_vars:
|
||||||
args.extend(['-e', get_vars_json_path(extra_vars=extra_vars)])
|
args.extend(['-e', get_extra_vars_json(extra_vars)])
|
||||||
|
|
||||||
if extra_vars.get('verbosity'):
|
if extra_vars.get('verbosity'):
|
||||||
args.append('-vvvv')
|
args.append('-vvvv')
|
||||||
|
|
||||||
if sudo:
|
if sudo:
|
||||||
user = extra_vars.get('user')
|
user = extra_vars.get('user') or getpass.getuser()
|
||||||
args.extend(['--become', '--become-user={0}'.format(user)])
|
args.extend(['--become', '--become-user={0}'.format(user)])
|
||||||
|
|
||||||
success = subprocess.check_call(args, cwd=os.path.join(tmp_bench_repo, 'playbooks'))
|
success = subprocess.check_call(args, cwd=os.path.join(tmp_bench_repo, 'playbooks'))
|
||||||
@ -237,7 +239,7 @@ def parse_commandline_args():
|
|||||||
|
|
||||||
parser.add_argument('--bench-branch', dest='bench_branch', help='Clone a particular branch of bench repository')
|
parser.add_argument('--bench-branch', dest='bench_branch', help='Clone a particular branch of bench repository')
|
||||||
|
|
||||||
parser.add_argument('--bench-repo-url', dest='bench_repo_url', help='Clones bench repository from the given url')
|
parser.add_argument('--repo-url', dest='repo_url', help='Clone bench from the given url')
|
||||||
|
|
||||||
# To enable testing of script using Travis, this should skip the prompt
|
# 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,
|
parser.add_argument('--run-travis', dest='run_travis', action='store_true', default=False,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user