2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-23 15:08:24 +00:00

[Fix] Initial commit

This commit is contained in:
shreyas 2016-02-23 18:42:36 +05:30 committed by Anand Doshi
parent e5c8966a00
commit 363fd2d04c
2 changed files with 89 additions and 29 deletions

View File

@ -3,6 +3,7 @@ import getpass
import json import json
import subprocess import subprocess
import shutil import shutil
import socket
from distutils.spawn import find_executable from distutils.spawn import find_executable
from jinja2 import Environment, PackageLoader from jinja2 import Environment, PackageLoader
from .utils import get_sites, get_config, update_config, get_redis_version from .utils import get_sites, get_config, update_config, get_redis_version
@ -87,22 +88,40 @@ def generate_nginx_config(bench='.'):
}) })
write_config_file(bench, 'nginx.conf', config) write_config_file(bench, 'nginx.conf', config)
def generate_redis_cache_config(bench='.'): def generate_redis_celery_broker_config(bench='.'):
template = env.get_template('redis_cache.conf') """Redis that is used for queueing celery tasks"""
conf = { _generate_redis_config(
"maxmemory": get_config().get('cache_maxmemory', '50'), template_name='redis_celery_broker.conf',
"port": get_config().get('redis_cache_port', '11311'), context={
"redis_version": get_redis_version()
}
config = template.render(**conf)
write_config_file(bench, 'redis_cache.conf', config)
},
bench=bench
)
def generate_redis_async_broker_config(bench='.'): def generate_redis_async_broker_config(bench='.'):
template = env.get_template('redis_async_broker.conf') """Redis that is used to do pub/sub"""
conf = { _generate_redis_config(
"port": get_config().get('redis_async_broker_port', '12311'), template_name='redis_async_broker.conf',
"redis_version": get_redis_version() context={
} "port": get_config().get('redis_async_broker_port', '12311'),
config = template.render(**conf) "bench_path": os.path.abspath(bench)
write_config_file(bench, 'redis_async_broker.conf', config) },
bench=bench
)
def generate_redis_cache_config(bench='.'):
"""Redis that is used and optimized for caching"""
_generate_redis_config(
template_name='redis_cache.conf',
context={
"maxmemory": get_config().get('cache_maxmemory', '50'),
"port": get_config().get('redis_cache_port', '11311'),
"redis_version": get_redis_version()
},
bench=bench
)
def _generate_redis_config(template_name, context, bench):
template = env.get_template(template_name)
redis_config = template.render(**context)
write_config_file(bench, template_name, redis_config)

View File

@ -47,7 +47,7 @@ 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, no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None,
verbose=False): verbose=False):
from .app import get_app, install_apps_from_path from .app import get_app, install_apps_from_path
from .config import generate_redis_cache_config, generate_redis_async_broker_config from .config import generate_redis_cache_config, generate_redis_async_broker_config, generate_redis_celery_broker_config
global FRAPPE_VERSION global FRAPPE_VERSION
if os.path.exists(path): if os.path.exists(path):
@ -62,28 +62,69 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
setup_logging() setup_logging()
setup_env(bench=path) setup_env(bench=path)
put_config(default_config, bench=path)
# if wheel_cache_dir: bench_config = make_bench_config()
# update_config({"wheel_cache_dir":wheel_cache_dir}, bench=path) put_config(bench_config, bench=path)
# prime_wheel_cache(bench=path)
if not frappe_path: if not frappe_path:
frappe_path = 'https://github.com/frappe/frappe.git' frappe_path = 'https://github.com/frappe/frappe.git'
get_app('frappe', frappe_path, branch=frappe_branch, bench=path, build_asset_files=False, verbose=verbose) get_app('frappe', frappe_path, branch=frappe_branch, bench=path, build_asset_files=False, verbose=verbose)
if apps_path:
install_apps_from_path(apps_path, bench=path)
FRAPPE_VERSION = get_current_frappe_version(bench=path)
if FRAPPE_VERSION > 5:
setup_socketio(bench=path)
build_assets(bench=path)
generate_redis_celery_broker_config(bench=path)
generate_redis_cache_config(bench=path)
generate_redis_async_broker_config(bench=path)
if not no_procfile: if not no_procfile:
setup_procfile(bench=path) setup_procfile(bench=path)
if not no_backups: if not no_backups:
setup_backups(bench=path) setup_backups(bench=path)
if not no_auto_update: if not no_auto_update:
setup_auto_update(bench=path) setup_auto_update(bench=path)
if apps_path:
install_apps_from_path(apps_path, bench=path) def make_bench_config():
FRAPPE_VERSION = get_current_frappe_version(bench=path) bench_config = {}
if FRAPPE_VERSION > 5: bench_config.update(default_config)
setup_socketio(bench=path) bench_config.update(make_ports())
build_assets(bench=path) return bench_config
generate_redis_cache_config(bench=path)
generate_redis_async_broker_config(bench=path) def make_ports(benches_path="."):
default_ports = {
"webserver_port": 8000,
"socketio_port": 9000,
"redis_celery_broker_port": 11000,
"redis_async_broker_port": 12000,
"redis_cache_port": 13000
}
# collect all existing ports
existing_ports = {}
for folder in os.listdir(benches_path):
bench = os.path.join(benches_path, folder)
if os.path.isdir(bench):
bench_config = get_config(bench)
for key in default_ports.keys():
value = bench_config.get(key)
if value:
existing_ports.setdefault(key, []).append(value)
# new port value = max of existing port value + 1
ports = {}
for key, value in default_ports.items():
existing_value = max(existing_ports.get(key, []))
if existing_value:
value = existing_value + 1
ports[key] = value
return ports
def exec_cmd(cmd, cwd='.'): def exec_cmd(cmd, cwd='.'):
from .cli import from_command_line from .cli import from_command_line