mirror of
https://github.com/frappe/bench.git
synced 2024-11-13 16:56:33 +00:00
Merge pull request #692 from codingCoffee/bm_port
bench manager runs on a separate port
This commit is contained in:
commit
6f7f46fd2f
@ -172,7 +172,10 @@ def setup_node_requirements():
|
|||||||
|
|
||||||
|
|
||||||
@click.command('manager')
|
@click.command('manager')
|
||||||
def setup_manager():
|
@click.option('--yes', help='Yes to regeneration of nginx config file', default=False, is_flag=True)
|
||||||
|
@click.option('--port', help='Port on which you want to run bench manager', default=23624)
|
||||||
|
@click.option('--domain', help='Domain on which you want to run bench manager')
|
||||||
|
def setup_manager(yes=False, port=23624, domain=None):
|
||||||
"Setup bench-manager.local site with the bench_manager app installed on it"
|
"Setup bench-manager.local site with the bench_manager app installed on it"
|
||||||
from six.moves import input
|
from six.moves import input
|
||||||
create_new_site = True
|
create_new_site = True
|
||||||
@ -190,6 +193,24 @@ def setup_manager():
|
|||||||
|
|
||||||
exec_cmd("bench --site bench-manager.local install-app bench_manager")
|
exec_cmd("bench --site bench-manager.local install-app bench_manager")
|
||||||
|
|
||||||
|
from bench.config.common_site_config import get_config
|
||||||
|
bench_path = '.'
|
||||||
|
conf = get_config(bench_path)
|
||||||
|
if conf.get('restart_supervisor_on_update') or conf.get('restart_systemd_on_update'):
|
||||||
|
# implicates a production setup or so I presume
|
||||||
|
if not domain:
|
||||||
|
print("Please specify the site name on which you want to host bench-manager using the 'domain' flag")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
from bench.utils import get_sites, get_bench_name
|
||||||
|
bench_name = get_bench_name(bench_path)
|
||||||
|
|
||||||
|
if domain not in get_sites(bench_path):
|
||||||
|
raise Exception("No such site")
|
||||||
|
|
||||||
|
from bench.config.nginx import make_bench_manager_nginx_conf
|
||||||
|
make_bench_manager_nginx_conf(bench_path, yes=yes, port=port, domain=domain)
|
||||||
|
|
||||||
|
|
||||||
@click.command('config')
|
@click.command('config')
|
||||||
def setup_config():
|
def setup_config():
|
||||||
|
@ -44,6 +44,45 @@ def make_nginx_conf(bench_path, yes=False):
|
|||||||
with open(conf_path, "w") as f:
|
with open(conf_path, "w") as f:
|
||||||
f.write(nginx_conf)
|
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')
|
||||||
|
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 = {
|
||||||
|
"port": port,
|
||||||
|
"domain": domain,
|
||||||
|
"bench_manager_site_name": "bench-manager.local",
|
||||||
|
"sites_path": sites_path,
|
||||||
|
"http_timeout": config.get("http_timeout"),
|
||||||
|
"webserver_port": config.get('webserver_port'),
|
||||||
|
"socketio_port": config.get('socketio_port'),
|
||||||
|
"bench_name": bench_name,
|
||||||
|
"error_pages": get_error_pages(),
|
||||||
|
"ssl_certificate": site_config.get('ssl_certificate'),
|
||||||
|
"ssl_certificate_key": site_config.get('ssl_certificate_key')
|
||||||
|
}
|
||||||
|
|
||||||
|
bench_manager_nginx_conf = template.render(**template_vars)
|
||||||
|
|
||||||
|
conf_path = os.path.join(bench_path, "config", "nginx.conf")
|
||||||
|
|
||||||
|
if not yes and os.path.exists(conf_path):
|
||||||
|
click.confirm('nginx.conf already exists and bench-manager configuration will be appended to it. Do you want to continue?',
|
||||||
|
abort=True)
|
||||||
|
|
||||||
|
with open(conf_path, "a") as myfile:
|
||||||
|
myfile.write(bench_manager_nginx_conf)
|
||||||
|
|
||||||
def prepare_sites(config, bench_path):
|
def prepare_sites(config, bench_path):
|
||||||
sites = {
|
sites = {
|
||||||
"that_use_port": [],
|
"that_use_port": [],
|
||||||
|
100
bench/config/templates/bench_manager_nginx.conf
Normal file
100
bench/config/templates/bench_manager_nginx.conf
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
server {
|
||||||
|
listen {{ port }};
|
||||||
|
server_name {{ domain }};
|
||||||
|
root {{ sites_path }};
|
||||||
|
|
||||||
|
|
||||||
|
{% if ssl_certificate and ssl_certificate_key %}
|
||||||
|
ssl on;
|
||||||
|
ssl_certificate {{ ssl_certificate }};
|
||||||
|
ssl_certificate_key {{ ssl_certificate_key }};
|
||||||
|
ssl_session_timeout 5m;
|
||||||
|
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
||||||
|
ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS";
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
location /assets {
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ ^/protected/(.*) {
|
||||||
|
internal;
|
||||||
|
try_files /{{ bench_manager_site_name }}/$1 =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /socket.io {
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_set_header X-Frappe-Site-Name {{ bench_manager_site_name }};
|
||||||
|
proxy_set_header Origin $scheme://$http_host;
|
||||||
|
proxy_set_header Host {{ bench_manager_site_name }};
|
||||||
|
|
||||||
|
proxy_pass http://{{ bench_name }}-socketio-server;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files /{{ bench_manager_site_name }}/public/$uri @webserver;
|
||||||
|
}
|
||||||
|
|
||||||
|
location @webserver {
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-Frappe-Site-Name {{ bench_manager_site_name }};
|
||||||
|
proxy_set_header Host {{ bench_manager_site_name }};
|
||||||
|
proxy_set_header X-Use-X-Accel-Redirect True;
|
||||||
|
proxy_read_timeout {{ http_timeout or 120 }};
|
||||||
|
proxy_redirect off;
|
||||||
|
|
||||||
|
proxy_pass http://{{ bench_name }}-frappe;
|
||||||
|
}
|
||||||
|
|
||||||
|
# error pages
|
||||||
|
{% for error_code, error_page in error_pages.items() -%}
|
||||||
|
|
||||||
|
error_page {{ error_code }} /{{ error_page.split('/')[-1] }};
|
||||||
|
location /{{ error_code }}.html {
|
||||||
|
root {{ '/'.join(error_page.split('/')[:-1]) }};
|
||||||
|
internal;
|
||||||
|
}
|
||||||
|
|
||||||
|
{% endfor -%}
|
||||||
|
|
||||||
|
# optimizations
|
||||||
|
sendfile on;
|
||||||
|
keepalive_timeout 15;
|
||||||
|
client_max_body_size 50m;
|
||||||
|
client_body_buffer_size 16K;
|
||||||
|
client_header_buffer_size 1k;
|
||||||
|
|
||||||
|
# enable gzip compresion
|
||||||
|
# based on https://mattstauffer.co/blog/enabling-gzip-on-nginx-servers-including-laravel-forge
|
||||||
|
gzip on;
|
||||||
|
gzip_http_version 1.1;
|
||||||
|
gzip_comp_level 5;
|
||||||
|
gzip_min_length 256;
|
||||||
|
gzip_proxied any;
|
||||||
|
gzip_vary on;
|
||||||
|
gzip_types
|
||||||
|
application/atom+xml
|
||||||
|
application/javascript
|
||||||
|
application/json
|
||||||
|
application/rss+xml
|
||||||
|
application/vnd.ms-fontobject
|
||||||
|
application/x-font-ttf
|
||||||
|
application/font-woff
|
||||||
|
application/x-web-app-manifest+json
|
||||||
|
application/xhtml+xml
|
||||||
|
application/xml
|
||||||
|
font/opentype
|
||||||
|
image/svg+xml
|
||||||
|
image/x-icon
|
||||||
|
text/css
|
||||||
|
text/plain
|
||||||
|
text/x-component
|
||||||
|
;
|
||||||
|
# text/html is always compressed by HttpGzipModule
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -121,14 +121,14 @@ server {
|
|||||||
{% if ssl_certificate and ssl_certificate_key -%}
|
{% if ssl_certificate and ssl_certificate_key -%}
|
||||||
# http to https redirect
|
# http to https redirect
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name
|
server_name
|
||||||
{% for name in server_names -%}
|
{% for name in server_names -%}
|
||||||
{{ name }}
|
{{ name }}
|
||||||
{% endfor -%}
|
{% endfor -%}
|
||||||
;
|
;
|
||||||
|
|
||||||
return 301 https://$host$request_uri;
|
return 301 https://$host$request_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -136,11 +136,11 @@ server {
|
|||||||
{%- endmacro -%}
|
{%- endmacro -%}
|
||||||
|
|
||||||
upstream {{ bench_name }}-frappe {
|
upstream {{ bench_name }}-frappe {
|
||||||
server 127.0.0.1:{{ webserver_port or 8000 }} fail_timeout=0;
|
server 127.0.0.1:{{ webserver_port or 8000 }} fail_timeout=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
upstream {{ bench_name}}-socketio-server {
|
upstream {{ bench_name}}-socketio-server {
|
||||||
server 127.0.0.1:{{ socketio_port or 3000 }} fail_timeout=0;
|
server 127.0.0.1:{{ socketio_port or 3000 }} fail_timeout=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
{% if allow_rate_limiting %}
|
{% if allow_rate_limiting %}
|
||||||
|
Loading…
Reference in New Issue
Block a user