From 8ba685cc50ee333cf764181e82096c80ece4ab28 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Tue, 12 Sep 2023 14:27:24 +0530 Subject: [PATCH 1/3] feat: allow custom image in easy install --- easy-install.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/easy-install.py b/easy-install.py index f703419f3..1b188b302 100755 --- a/easy-install.py +++ b/easy-install.py @@ -114,7 +114,7 @@ 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 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") @@ -125,6 +125,11 @@ def setup_prod(project: str, sites, email: str, version: str = None) -> None: admin_pass = "" db_pass = "" with open(compose_file_name, "w") as f: + if image: + filedata = f.read() + filedata = filedata.replace("image: frappe/erpnext", f"image: {image}") + f.write(filedata) + # Writing to compose file if not os.path.exists(os.path.join(docker_repo_path, ".env")): admin_pass = generate_pass() @@ -199,7 +204,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): @@ -321,6 +326,7 @@ def create_site( 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 +344,6 @@ def create_site( 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() From f93f065ba3477c3316f21422406d0f65e813c8eb Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Fri, 22 Sep 2023 13:20:30 +0530 Subject: [PATCH 2/3] fix: image replace and site creation --- easy-install.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/easy-install.py b/easy-install.py index 1b188b302..326021211 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 @@ -115,6 +116,9 @@ def check_repo_exists() -> bool: def setup_prod(project: str, sites, email: str, version: str = None, image = None) -> None: + if len(sites) == 0: + sites = ["site.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") @@ -125,11 +129,6 @@ def setup_prod(project: str, sites, email: str, version: str = None, image = Non admin_pass = "" db_pass = "" with open(compose_file_name, "w") as f: - if image: - filedata = f.read() - filedata = filedata.replace("image: frappe/erpnext", f"image: {image}") - f.write(filedata) - # Writing to compose file if not os.path.exists(os.path.join(docker_repo_path, ".env")): admin_pass = generate_pass() @@ -176,6 +175,14 @@ def setup_prod(project: str, sites, email: str, version: str = None, image = Non 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( @@ -321,7 +328,7 @@ def create_site( "-s", "--sitename", help="Site Name(s) for your production bench", - default=["site1.localhost"], + default=[], action="append", dest="sites", ) From fde7a8209dbdbb8b50b413fe1174ae62bb06b395 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Fri, 22 Sep 2023 13:27:15 +0530 Subject: [PATCH 3/3] fix(easy-install): set default site to site1.localhost --- easy-install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easy-install.py b/easy-install.py index 326021211..e1890380e 100755 --- a/easy-install.py +++ b/easy-install.py @@ -117,7 +117,7 @@ def check_repo_exists() -> bool: def setup_prod(project: str, sites, email: str, version: str = None, image = None) -> None: if len(sites) == 0: - sites = ["site.localhost"] + sites = ["site1.localhost"] if check_repo_exists(): compose_file_name = os.path.join(os.path.expanduser("~"), f"{project}-compose.yml")