mirror of
https://github.com/frappe/bench.git
synced 2024-11-12 00:06:36 +00:00
Merge branch 'develop' into playbooks-fix
This commit is contained in:
commit
f7c6c5a882
@ -1,11 +1,8 @@
|
||||
from jinja2 import Environment, PackageLoader
|
||||
|
||||
__version__ = "5.0.0"
|
||||
|
||||
env = Environment(loader=PackageLoader('bench.config'))
|
||||
|
||||
VERSION = "5.0.0"
|
||||
PROJECT_NAME = "frappe-bench"
|
||||
FRAPPE_VERSION = None
|
||||
|
||||
|
||||
def set_frappe_version(bench_path='.'):
|
||||
from .app import get_current_frappe_version
|
||||
global FRAPPE_VERSION
|
||||
|
12
bench/app.py
12
bench/app.py
@ -111,6 +111,9 @@ def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=Fal
|
||||
if git_url == data['name']:
|
||||
git_url = 'https://github.com/{org}/{app}'.format(org=org, app=git_url)
|
||||
break
|
||||
else:
|
||||
bench.utils.log("App {app} not found".format(app=git_url), level=2)
|
||||
sys.exit(1)
|
||||
|
||||
# Gets repo name from URL
|
||||
repo_name = git_url.rsplit('/', 1)[1].rsplit('.', 1)[0]
|
||||
@ -177,8 +180,11 @@ def install_app(app, bench_path=".", verbose=False, no_cache=False, postprocess=
|
||||
app_path = os.path.join(bench_path, "apps", app)
|
||||
cache_flag = "--no-cache-dir" if no_cache else ""
|
||||
|
||||
exec_cmd("{pip} install {quiet} -U -e {app} {no_cache}".format(pip=pip_path,
|
||||
quiet=quiet_flag, app=app_path, no_cache=cache_flag))
|
||||
exec_cmd("{pip} install {quiet} -U -e {app} {no_cache}".format(pip=pip_path, quiet=quiet_flag, app=app_path, no_cache=cache_flag))
|
||||
|
||||
if os.path.exists(os.path.join(app_path, 'package.json')):
|
||||
exec_cmd("yarn install", cwd=app_path)
|
||||
|
||||
add_to_appstxt(app, bench_path=bench_path)
|
||||
|
||||
if postprocess:
|
||||
@ -407,7 +413,7 @@ def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrad
|
||||
if version_upgrade[0] and upgrade:
|
||||
update_requirements()
|
||||
update_node_packages()
|
||||
reload_module(utils)
|
||||
reload_module(bench.utils)
|
||||
backup_all_sites()
|
||||
patch_sites()
|
||||
build_assets()
|
||||
|
@ -10,13 +10,13 @@ import sys
|
||||
import click
|
||||
|
||||
# imports - module imports
|
||||
import bench
|
||||
from bench.app import get_apps
|
||||
from bench.commands import bench_command
|
||||
from bench.config.common_site_config import get_config
|
||||
from bench.utils import PatchError, bench_cache_file, check_latest_version, drop_privileges, find_parent_bench, generate_command_cache, get_cmd_output, get_env_cmd, get_frappe, is_bench_directory, is_dist_editable, is_root, log
|
||||
|
||||
|
||||
logger = logging.getLogger('bench')
|
||||
logger = logging.getLogger(bench.PROJECT_NAME)
|
||||
from_command_line = False
|
||||
change_uid_msg = "You should not run this command as root"
|
||||
|
||||
@ -30,7 +30,7 @@ def cli():
|
||||
change_dir()
|
||||
change_uid()
|
||||
|
||||
if is_dist_editable("bench") and len(sys.argv) > 1 and sys.argv[1] != "src":
|
||||
if is_dist_editable(bench.PROJECT_NAME) and len(sys.argv) > 1 and sys.argv[1] != "src":
|
||||
log("bench is installed in editable mode!\n\nThis is not the recommended mode of installation for production. Instead, install the package from PyPI with: `pip install frappe-bench`\n", level=3)
|
||||
|
||||
if not is_bench_directory() and not cmd_requires_root() and len(sys.argv) > 1 and sys.argv[1] not in ("init", "find", "src"):
|
||||
|
@ -7,13 +7,12 @@ def print_bench_version(ctx, param, value):
|
||||
return
|
||||
|
||||
import bench
|
||||
click.echo(bench.__version__)
|
||||
click.echo(bench.VERSION)
|
||||
ctx.exit()
|
||||
|
||||
@click.group()
|
||||
@click.option('--version', is_flag=True, is_eager=True, callback=print_bench_version, expose_value=False)
|
||||
def bench_command(bench_path='.'):
|
||||
"""Bench manager for Frappe"""
|
||||
import bench
|
||||
from bench.utils import setup_logging
|
||||
|
||||
|
@ -14,7 +14,6 @@ import bench.config.production_setup
|
||||
import bench.config.redis
|
||||
import bench.config.site_config
|
||||
import bench.config.supervisor
|
||||
|
||||
import bench.utils
|
||||
from bench.utils import exec_cmd, run_playbook
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
"""Module for setting up system and respective bench configurations"""
|
||||
|
||||
# imports - third party imports
|
||||
from jinja2 import Environment, PackageLoader
|
||||
|
||||
env = Environment(loader=PackageLoader('bench.config'))
|
@ -1,15 +1,19 @@
|
||||
import bench, os, click, errno
|
||||
from bench.utils import exec_cmd, CommandFailedError, update_common_site_config
|
||||
from bench.config.site_config import update_site_config, remove_domain, get_domains
|
||||
# imports - standard imports
|
||||
import os
|
||||
|
||||
# imports - third party imports
|
||||
import click
|
||||
from crontab import CronTab
|
||||
from six.moves.urllib.request import urlretrieve
|
||||
|
||||
# imports - module imports
|
||||
import bench
|
||||
from bench.config.common_site_config import get_config
|
||||
from bench.config.nginx import make_nginx_conf
|
||||
from bench.config.production_setup import service
|
||||
from bench.config.common_site_config import get_config
|
||||
from crontab import CronTab
|
||||
from bench.config.site_config import get_domains, remove_domain, update_site_config
|
||||
from bench.utils import CommandFailedError, exec_cmd, update_common_site_config
|
||||
|
||||
try:
|
||||
from urllib.request import urlretrieve
|
||||
except ImportError:
|
||||
from urllib import urlretrieve
|
||||
|
||||
def setup_letsencrypt(site, custom_domain, bench_path, interactive):
|
||||
|
||||
@ -44,7 +48,7 @@ def setup_letsencrypt(site, custom_domain, bench_path, interactive):
|
||||
|
||||
|
||||
def create_config(site, custom_domain):
|
||||
config = bench.env.get_template('letsencrypt.cfg').render(domain=custom_domain or site)
|
||||
config = bench.config.env.get_template('letsencrypt.cfg').render(domain=custom_domain or site)
|
||||
config_path = '/etc/letsencrypt/configs/{site}.cfg'.format(site=custom_domain or site)
|
||||
create_dir_if_missing(config_path)
|
||||
|
||||
@ -171,4 +175,3 @@ def setup_wildcard_ssl(domain, email, bench_path, exclude_base_domain):
|
||||
make_nginx_conf(bench_path)
|
||||
print("Restrting Nginx service")
|
||||
service('nginx', 'restart')
|
||||
|
||||
|
@ -9,6 +9,7 @@ import click
|
||||
from six import string_types
|
||||
|
||||
# imports - module imports
|
||||
import bench
|
||||
from bench.utils import get_bench_name, get_sites
|
||||
|
||||
|
||||
@ -19,14 +20,11 @@ def make_nginx_conf(bench_path, yes=False):
|
||||
if not click.confirm('nginx.conf already exists and this will overwrite it. Do you want to continue?'):
|
||||
return
|
||||
|
||||
from bench import env
|
||||
from bench.config.common_site_config import get_config
|
||||
|
||||
template = env.get_template('nginx.conf')
|
||||
template = bench.config.env.get_template('nginx.conf')
|
||||
bench_path = os.path.abspath(bench_path)
|
||||
sites_path = os.path.join(bench_path, "sites")
|
||||
|
||||
config = get_config(bench_path)
|
||||
config = bench.config.common_site_config.get_config(bench_path)
|
||||
sites = prepare_sites(config, bench_path)
|
||||
bench_name = get_bench_name(bench_path)
|
||||
|
||||
@ -58,17 +56,15 @@ def make_nginx_conf(bench_path, yes=False):
|
||||
f.write(nginx_conf)
|
||||
|
||||
def make_bench_manager_nginx_conf(bench_path, yes=False, port=23624, domain=None):
|
||||
from bench import env
|
||||
from bench.config.site_config import get_site_config
|
||||
from bench.config.common_site_config import get_config
|
||||
|
||||
template = env.get_template('bench_manager_nginx.conf')
|
||||
template = bench.config.env.get_template('bench_manager_nginx.conf')
|
||||
bench_path = os.path.abspath(bench_path)
|
||||
sites_path = os.path.join(bench_path, "sites")
|
||||
|
||||
config = get_config(bench_path)
|
||||
site_config = get_site_config(domain, bench_path=bench_path)
|
||||
sites = prepare_sites(config, bench_path)
|
||||
bench_name = get_bench_name(bench_path)
|
||||
|
||||
template_vars = {
|
||||
@ -153,9 +149,6 @@ def prepare_sites(config, bench_path):
|
||||
while site["port"] in ports_in_use:
|
||||
site["port"] += 1
|
||||
|
||||
# if site["port"] in ports_in_use:
|
||||
# raise Exception("Port {0} is being used by another site {1}".format(site["port"], ports_in_use[site["port"]]))
|
||||
|
||||
if site["port"] in ports_in_use and not site["name"] in ports_in_use[site["port"]]:
|
||||
shared_port_exception_found = True
|
||||
ports_in_use[site["port"]].append(site["name"])
|
||||
|
@ -1,7 +1,15 @@
|
||||
import bench, os, click
|
||||
from bench.utils import find_executable
|
||||
# imports - standard imports
|
||||
import os
|
||||
|
||||
# imports - third party imports
|
||||
import click
|
||||
|
||||
# imports - module imports
|
||||
import bench
|
||||
from bench.app import use_rq
|
||||
from bench.config.common_site_config import get_config
|
||||
from bench.utils import find_executable
|
||||
|
||||
|
||||
def setup_procfile(bench_path, yes=False, skip_redis=False):
|
||||
config = get_config(bench_path=bench_path)
|
||||
@ -10,7 +18,7 @@ def setup_procfile(bench_path, yes=False, skip_redis=False):
|
||||
click.confirm('A Procfile already exists and this will overwrite it. Do you want to continue?',
|
||||
abort=True)
|
||||
|
||||
procfile = bench.env.get_template('Procfile').render(
|
||||
procfile = bench.config.env.get_template('Procfile').render(
|
||||
node=find_executable("node") or find_executable("nodejs"),
|
||||
use_rq=use_rq(bench_path),
|
||||
webserver_port=config.get('webserver_port'),
|
||||
|
@ -1,14 +1,13 @@
|
||||
# imports - standard imports
|
||||
import os
|
||||
import sys
|
||||
from distutils.spawn import find_executable
|
||||
|
||||
# imports - module imports
|
||||
from bench.config.common_site_config import get_config
|
||||
from bench.config.nginx import make_nginx_conf
|
||||
from bench.config.supervisor import generate_supervisor_config
|
||||
from bench.config.systemd import generate_systemd_config
|
||||
from bench.utils import CommandFailedError, exec_cmd, fix_prod_setup_perms, get_bench_name, get_cmd_output
|
||||
from bench.utils import CommandFailedError, exec_cmd, find_executable, fix_prod_setup_perms, get_bench_name, get_cmd_output
|
||||
|
||||
|
||||
def setup_production_prerequisites():
|
||||
|
@ -52,7 +52,7 @@ def generate_config(bench_path):
|
||||
os.makedirs(pid_path)
|
||||
|
||||
def write_redis_config(template_name, context, bench_path):
|
||||
template = bench.env.get_template(template_name)
|
||||
template = bench.config.env.get_template(template_name)
|
||||
|
||||
if "pid_path" not in context:
|
||||
context["pid_path"] = os.path.abspath(os.path.join(bench_path, "config", "pids"))
|
||||
|
@ -1,8 +1,13 @@
|
||||
import os, json
|
||||
from bench.utils import get_sites
|
||||
from bench.config.nginx import make_nginx_conf
|
||||
# imports - standard imports
|
||||
import json
|
||||
import os
|
||||
from collections import defaultdict
|
||||
|
||||
# imports - module imports
|
||||
from bench.config.nginx import make_nginx_conf
|
||||
from bench.utils import get_sites
|
||||
|
||||
|
||||
def get_site_config(site, bench_path='.'):
|
||||
config_path = os.path.join(bench_path, 'sites', site, 'site_config.json')
|
||||
if not os.path.exists(config_path):
|
||||
|
@ -20,7 +20,7 @@ def generate_supervisor_config(bench_path, user=None, yes=False):
|
||||
|
||||
update_supervisord_conf(user=user)
|
||||
|
||||
template = bench.env.get_template('supervisor.conf')
|
||||
template = bench.config.env.get_template('supervisor.conf')
|
||||
config = get_config(bench_path=bench_path)
|
||||
bench_dir = os.path.abspath(bench_path)
|
||||
|
||||
|
@ -1,9 +1,16 @@
|
||||
import os, getpass, click
|
||||
# imports - standard imports
|
||||
import getpass
|
||||
import os
|
||||
|
||||
# imports - third partyimports
|
||||
import click
|
||||
|
||||
# imports - module imports
|
||||
import bench
|
||||
from bench.utils import exec_cmd
|
||||
from bench.app import get_current_frappe_version, use_rq
|
||||
from bench.utils import get_bench_name, find_executable
|
||||
from bench.config.common_site_config import get_config, update_config, get_gunicorn_workers
|
||||
from bench.config.common_site_config import get_config, get_gunicorn_workers, update_config
|
||||
from bench.utils import exec_cmd, find_executable, get_bench_name
|
||||
|
||||
|
||||
def generate_systemd_config(bench_path, user=None, yes=False,
|
||||
stop=False, create_symlinks=False,
|
||||
@ -78,7 +85,7 @@ def setup_systemd_directory(bench_path):
|
||||
|
||||
def setup_main_config(bench_info, bench_path):
|
||||
# Main config
|
||||
bench_template = bench.env.get_template('systemd/frappe-bench.target')
|
||||
bench_template = bench.config.env.get_template('systemd/frappe-bench.target')
|
||||
bench_config = bench_template.render(**bench_info)
|
||||
bench_config_path = os.path.join(bench_path, 'config', 'systemd' , bench_info.get("bench_name") + '.target')
|
||||
|
||||
@ -87,11 +94,11 @@ def setup_main_config(bench_info, bench_path):
|
||||
|
||||
def setup_workers_config(bench_info, bench_path):
|
||||
# Worker Group
|
||||
bench_workers_target_template = bench.env.get_template('systemd/frappe-bench-workers.target')
|
||||
bench_default_worker_template = bench.env.get_template('systemd/frappe-bench-frappe-default-worker.service')
|
||||
bench_short_worker_template = bench.env.get_template('systemd/frappe-bench-frappe-short-worker.service')
|
||||
bench_long_worker_template = bench.env.get_template('systemd/frappe-bench-frappe-long-worker.service')
|
||||
bench_schedule_worker_template = bench.env.get_template('systemd/frappe-bench-frappe-schedule.service')
|
||||
bench_workers_target_template = bench.config.env.get_template('systemd/frappe-bench-workers.target')
|
||||
bench_default_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-default-worker.service')
|
||||
bench_short_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-short-worker.service')
|
||||
bench_long_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-long-worker.service')
|
||||
bench_schedule_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-schedule.service')
|
||||
|
||||
bench_workers_target_config = bench_workers_target_template.render(**bench_info)
|
||||
bench_default_worker_config = bench_default_worker_template.render(**bench_info)
|
||||
@ -122,9 +129,9 @@ def setup_workers_config(bench_info, bench_path):
|
||||
|
||||
def setup_web_config(bench_info, bench_path):
|
||||
# Web Group
|
||||
bench_web_target_template = bench.env.get_template('systemd/frappe-bench-web.target')
|
||||
bench_web_service_template = bench.env.get_template('systemd/frappe-bench-frappe-web.service')
|
||||
bench_node_socketio_template = bench.env.get_template('systemd/frappe-bench-node-socketio.service')
|
||||
bench_web_target_template = bench.config.env.get_template('systemd/frappe-bench-web.target')
|
||||
bench_web_service_template = bench.config.env.get_template('systemd/frappe-bench-frappe-web.service')
|
||||
bench_node_socketio_template = bench.config.env.get_template('systemd/frappe-bench-node-socketio.service')
|
||||
|
||||
bench_web_target_config = bench_web_target_template.render(**bench_info)
|
||||
bench_web_service_config = bench_web_service_template.render(**bench_info)
|
||||
@ -145,10 +152,10 @@ def setup_web_config(bench_info, bench_path):
|
||||
|
||||
def setup_redis_config(bench_info, bench_path):
|
||||
# Redis Group
|
||||
bench_redis_target_template = bench.env.get_template('systemd/frappe-bench-redis.target')
|
||||
bench_redis_cache_template = bench.env.get_template('systemd/frappe-bench-redis-cache.service')
|
||||
bench_redis_queue_template = bench.env.get_template('systemd/frappe-bench-redis-queue.service')
|
||||
bench_redis_socketio_template = bench.env.get_template('systemd/frappe-bench-redis-socketio.service')
|
||||
bench_redis_target_template = bench.config.env.get_template('systemd/frappe-bench-redis.target')
|
||||
bench_redis_cache_template = bench.config.env.get_template('systemd/frappe-bench-redis-cache.service')
|
||||
bench_redis_queue_template = bench.config.env.get_template('systemd/frappe-bench-redis-queue.service')
|
||||
bench_redis_socketio_template = bench.config.env.get_template('systemd/frappe-bench-redis-socketio.service')
|
||||
|
||||
bench_redis_target_config = bench_redis_target_template.render(**bench_info)
|
||||
bench_redis_cache_config = bench_redis_cache_template.render(**bench_info)
|
||||
|
@ -96,7 +96,7 @@ def check_latest_version():
|
||||
if pypi_request.status_code == 200:
|
||||
pypi_version_str = pypi_request.json().get('info').get('version')
|
||||
pypi_version = Version(pypi_version_str)
|
||||
local_version = Version(bench.__version__)
|
||||
local_version = Version(bench.VERSION)
|
||||
|
||||
if pypi_version > local_version:
|
||||
log("A newer version of bench is available: {0} → {1}".format(local_version, pypi_version))
|
||||
@ -394,8 +394,6 @@ def setup_backups(bench_path='.'):
|
||||
|
||||
|
||||
def setup_sudoers(user):
|
||||
from bench import env
|
||||
|
||||
if not os.path.exists('/etc/sudoers.d'):
|
||||
os.makedirs('/etc/sudoers.d')
|
||||
|
||||
@ -409,7 +407,7 @@ def setup_sudoers(user):
|
||||
if set_permissions:
|
||||
os.chmod('/etc/sudoers', 0o440)
|
||||
|
||||
template = env.get_template('frappe_sudoers')
|
||||
template = bench.config.env.get_template('frappe_sudoers')
|
||||
frappe_sudoers = template.render(**{
|
||||
'user': user,
|
||||
'service': find_executable('service'),
|
||||
@ -427,7 +425,7 @@ def setup_sudoers(user):
|
||||
|
||||
def setup_logging(bench_path='.'):
|
||||
if os.path.exists(os.path.join(bench_path, 'logs')):
|
||||
logger = logging.getLogger('bench')
|
||||
logger = logging.getLogger(bench.PROJECT_NAME)
|
||||
log_file = os.path.join(bench_path, 'logs', 'bench.log')
|
||||
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
|
||||
hdlr = logging.FileHandler(log_file)
|
||||
|
11
setup.py
11
setup.py
@ -2,22 +2,17 @@ import ast
|
||||
import re
|
||||
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
from bench import PROJECT_NAME, VERSION
|
||||
|
||||
with open('requirements.txt') as f:
|
||||
install_requires = f.read().strip().split('\n')
|
||||
|
||||
with open('bench/__init__.py', 'rb') as f:
|
||||
_version_re = re.compile(r'__version__\s+=\s+(.*)')
|
||||
version = str(ast.literal_eval(_version_re.search(
|
||||
f.read().decode('utf-8')).group(1)))
|
||||
|
||||
setup(
|
||||
name='bench',
|
||||
name=PROJECT_NAME,
|
||||
description='Metadata driven, full-stack web framework',
|
||||
author='Frappe Technologies',
|
||||
author_email='info@frappe.io',
|
||||
version=version,
|
||||
version=VERSION,
|
||||
packages=find_packages(),
|
||||
zip_safe=False,
|
||||
include_package_data=True,
|
||||
|
Loading…
Reference in New Issue
Block a user