diff --git a/bench/commands/install.py b/bench/commands/install.py index e86e9429..31ad59b6 100644 --- a/bench/commands/install.py +++ b/bench/commands/install.py @@ -25,9 +25,10 @@ def install_prerequisites(): @click.command( "mariadb", help="Install and setup MariaDB of specified version and root password" ) -@click.option("--mysql_root_password", "--mysql-root-password", default="") +@click.option("--mysql_root_password", "--mysql-root-password", + "--mariadb_root_password", "--mariadb-root-password", default="") @click.option("--version", default="10.3") -def install_maridb(mysql_root_password, version): +def install_mariadb(mysql_root_password, version): if mysql_root_password: extra_vars.update( { @@ -111,7 +112,7 @@ def install_failtoban(**kwargs): install.add_command(install_prerequisites) -install.add_command(install_maridb) +install.add_command(install_mariadb) install.add_command(install_wkhtmltopdf) install.add_command(install_nodejs) install.add_command(install_psutil) diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 999f8dbd..9b13c269 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -358,7 +358,7 @@ def sync_domains(domain=None, site=None): @click.command("role", help="Install dependencies via ansible roles") @click.argument("role") @click.option("--admin_emails", default="") -@click.option("--mysql_root_password") +@click.option("--mysql_root_password", "--mariadb_root_password") @click.option("--container", is_flag=True, default=False) def setup_roles(role, **kwargs): extra_vars = {"production": True} diff --git a/bench/config/common_site_config.py b/bench/config/common_site_config.py index 0514c24e..2d4ef2c3 100644 --- a/bench/config/common_site_config.py +++ b/bench/config/common_site_config.py @@ -83,7 +83,7 @@ def update_config_for_frappe(config, bench_path): for key in ("redis_cache", "redis_queue", "redis_socketio"): if key not in config: - config[key] = f"redis://localhost:{ports[key]}" + config[key] = f"redis://127.0.0.1:{ports[key]}" for key in ("webserver_port", "socketio_port", "file_watcher_port"): if key not in config: diff --git a/bench/config/templates/bench_manager_nginx.conf b/bench/config/templates/bench_manager_nginx.conf index 4f8426c9..bab26e88 100644 --- a/bench/config/templates/bench_manager_nginx.conf +++ b/bench/config/templates/bench_manager_nginx.conf @@ -39,7 +39,7 @@ server { } location @webserver { - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-For $remote_addr; 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 }}; diff --git a/bench/playbooks/roles/mariadb/README.md b/bench/playbooks/roles/mariadb/README.md index 72e42382..ad869194 100644 --- a/bench/playbooks/roles/mariadb/README.md +++ b/bench/playbooks/roles/mariadb/README.md @@ -13,7 +13,7 @@ Debain 9 ## Post install -Run `mysql_secure_installation` +Run `mariadb-secure-installation` ## Requirements @@ -39,7 +39,7 @@ Configuration filename: mysql_conf_file: settings.cnf ``` -### Experimental unattended mysql_secure_installation +### Experimental unattended mariadb-secure-installation ``` ansible-playbook release.yml --extra-vars "mysql_secure_installation=true mysql_root_password=your_very_secret_password" diff --git a/bench/playbooks/roles/mariadb/handlers/main.yml b/bench/playbooks/roles/mariadb/handlers/main.yml index 3755d8ce..6f737d91 100644 --- a/bench/playbooks/roles/mariadb/handlers/main.yml +++ b/bench/playbooks/roles/mariadb/handlers/main.yml @@ -1,3 +1,3 @@ --- -- name: restart mysql - service: name=mysql state=restarted +- name: restart mariadb + service: name=mariadb state=restarted diff --git a/bench/playbooks/roles/mariadb/tasks/main.yml b/bench/playbooks/roles/mariadb/tasks/main.yml index 8079583d..b4e145ad 100644 --- a/bench/playbooks/roles/mariadb/tasks/main.yml +++ b/bench/playbooks/roles/mariadb/tasks/main.yml @@ -16,7 +16,7 @@ group: root mode: 0644 when: mysql_conf_tpl != 'change_me' and ansible_distribution != 'Debian' - notify: restart mysql + notify: restart mariadb - include_tasks: debian.yml when: ansible_distribution == 'Debian' @@ -29,7 +29,7 @@ group: root mode: 0644 when: mysql_conf_tpl != 'change_me' and ansible_distribution == 'Debian' - notify: restart mysql + notify: restart mariadb - name: Add additional conf for MariaDB 10.2 in mariadb.conf.d blockinfile: @@ -59,7 +59,7 @@ - name: Start and enable service service: - name: mysql + name: mariadb state: started enabled: yes diff --git a/bench/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml b/bench/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml index 4265375e..03291874 100644 --- a/bench/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml +++ b/bench/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml @@ -19,28 +19,28 @@ - ::1 - name: Reload privilege tables - command: 'mysql -ne "{{ item }}"' + command: 'mariadb -ne "{{ item }}"' with_items: - FLUSH PRIVILEGES changed_when: False when: run_travis is not defined - name: Remove anonymous users - command: 'mysql -ne "{{ item }}"' + command: 'mariadb -ne "{{ item }}"' with_items: - DELETE FROM mysql.user WHERE User='' changed_when: False when: run_travis is not defined - name: Disallow root login remotely - command: 'mysql -ne "{{ item }}"' + command: 'mariadb -ne "{{ item }}"' with_items: - DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1') changed_when: False when: run_travis is not defined - name: Remove test database and access to it - command: 'mysql -ne "{{ item }}"' + command: 'mariadb -ne "{{ item }}"' with_items: - DROP DATABASE IF EXISTS test - DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%' @@ -48,7 +48,7 @@ when: run_travis is not defined - name: Reload privilege tables - command: 'mysql -ne "{{ item }}"' + command: 'mariadb -ne "{{ item }}"' with_items: - FLUSH PRIVILEGES changed_when: False diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 30bb1572..f72a4c35 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -54,9 +54,9 @@ class TestBenchInit(TestBenchBase): "webserver_port": 8000, "socketio_port": 9000, "file_watcher_port": 6787, - "redis_queue": "redis://localhost:11000", - "redis_socketio": "redis://localhost:13000", - "redis_cache": "redis://localhost:13000", + "redis_queue": "redis://127.0.0.1:11000", + "redis_socketio": "redis://127.0.0.1:13000", + "redis_cache": "redis://127.0.0.1:13000", }, ) @@ -66,9 +66,9 @@ class TestBenchInit(TestBenchBase): "webserver_port": 8001, "socketio_port": 9001, "file_watcher_port": 6788, - "redis_queue": "redis://localhost:11001", - "redis_socketio": "redis://localhost:13001", - "redis_cache": "redis://localhost:13001", + "redis_queue": "redis://127.0.0.1:11001", + "redis_socketio": "redis://127.0.0.1:13001", + "redis_cache": "redis://127.0.0.1:13001", }, ) diff --git a/easy-install.py b/easy-install.py index f703419f..e1890380 100755 --- a/easy-install.py +++ b/easy-install.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import argparse +import fileinput import logging import os import platform @@ -114,7 +115,10 @@ def check_repo_exists() -> bool: return os.path.exists(os.path.join(os.getcwd(), "frappe_docker")) -def setup_prod(project: str, sites, email: str, version: str = None) -> None: +def setup_prod(project: str, sites, email: str, version: str = None, image = None) -> None: + if len(sites) == 0: + sites = ["site1.localhost"] + if check_repo_exists(): compose_file_name = os.path.join(os.path.expanduser("~"), f"{project}-compose.yml") docker_repo_path = os.path.join(os.getcwd(), "frappe_docker") @@ -171,6 +175,14 @@ def setup_prod(project: str, sites, email: str, version: str = None) -> None: logging.error("Docker Compose generation failed", exc_info=True) cprint("\nGenerating Compose File failed\n") sys.exit(1) + + # Use custom image + if image: + for line in fileinput.input(compose_file_name, inplace=True): + if "image: frappe/erpnext" in line: + line = line.replace("image: frappe/erpnext", f"image: {image}") + sys.stdout.write(line) + try: # Starting with generated compose file subprocess.run( @@ -199,7 +211,7 @@ def setup_prod(project: str, sites, email: str, version: str = None) -> None: else: install_docker() clone_frappe_docker_repo() - setup_prod(project, sites, email, version) # Recursive + setup_prod(project, sites, email, version, image) # Recursive def setup_dev_instance(project: str): @@ -316,11 +328,12 @@ if __name__ == "__main__": "-s", "--sitename", help="Site Name(s) for your production bench", - default=["site1.localhost"], + default=[], action="append", dest="sites", ) parser.add_argument("-n", "--project", help="Project Name", default="frappe") + parser.add_argument("-i", "--image", help="Full Image Name") parser.add_argument( "--email", help="Add email for the SSL.", required="--prod" in sys.argv ) @@ -338,6 +351,6 @@ if __name__ == "__main__": if "example.com" in args.email: cprint("Emails with example.com not acceptable", level=1) sys.exit(1) - setup_prod(args.project, args.sites, args.email, args.version) + setup_prod(args.project, args.sites, args.email, args.version, args.image) else: parser.print_help()