2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-10 00:37:51 +00:00

fix: image replace and site creation

This commit is contained in:
Revant Nandgaonkar 2023-09-22 13:20:30 +05:30
parent 8ba685cc50
commit f93f065ba3

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse import argparse
import fileinput
import logging import logging
import os import os
import platform 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: 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(): if check_repo_exists():
compose_file_name = os.path.join(os.path.expanduser("~"), f"{project}-compose.yml") compose_file_name = os.path.join(os.path.expanduser("~"), f"{project}-compose.yml")
docker_repo_path = os.path.join(os.getcwd(), "frappe_docker") 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 = "" admin_pass = ""
db_pass = "" db_pass = ""
with open(compose_file_name, "w") as f: 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 # Writing to compose file
if not os.path.exists(os.path.join(docker_repo_path, ".env")): if not os.path.exists(os.path.join(docker_repo_path, ".env")):
admin_pass = generate_pass() 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) logging.error("Docker Compose generation failed", exc_info=True)
cprint("\nGenerating Compose File failed\n") cprint("\nGenerating Compose File failed\n")
sys.exit(1) 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: try:
# Starting with generated compose file # Starting with generated compose file
subprocess.run( subprocess.run(
@ -321,7 +328,7 @@ if __name__ == "__main__":
"-s", "-s",
"--sitename", "--sitename",
help="Site Name(s) for your production bench", help="Site Name(s) for your production bench",
default=["site1.localhost"], default=[],
action="append", action="append",
dest="sites", dest="sites",
) )