2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-09 16:36:25 +00:00

chore: get exact versions from example.env file

This commit is contained in:
Athul Cyriac Ajay 2022-12-06 19:33:47 +05:30
parent 7c8ce31a8d
commit 3ff7bfb35f

View File

@ -5,10 +5,11 @@ import os
import sys import sys
import time import time
import urllib.request import urllib.request
from shutil import which, unpack_archive, move
import platform
from hashlib import sha224
import logging import logging
import platform
from shutil import which, unpack_archive, move
from hashlib import sha224
from typing import Dict
logging.basicConfig( logging.basicConfig(
filename="easy-install.log", filename="easy-install.log",
@ -58,14 +59,24 @@ def clone_frappe_docker_repo() -> None:
logging.error("Download and unzip failed", exc_info=True) logging.error("Download and unzip failed", exc_info=True)
cprint("\nCloning frappe_docker Failed\n\n", "[ERROR]: ", e, level=1) cprint("\nCloning frappe_docker Failed\n\n", "[ERROR]: ", e, level=1)
def get_latest_version(dir) -> Dict:
env_vars ={}
with open(os.path.join(dir,"example.env")) as f:
for line in f:
if line.startswith('#') or not line.strip():
continue
key, value = line.strip().split('=', 1)
env_vars[key] = value
return env_vars
def write_to_env(wd: str, site: str, db_pass: str, admin_pass: str, email: str) -> None: def write_to_env(wd: str, site: str, db_pass: str, admin_pass: str, email: str) -> None:
site_name = site or "" site_name = site or ""
example_env = get_latest_version(wd)
with open(os.path.join(wd, ".env"), "w") as f: with open(os.path.join(wd, ".env"), "w") as f:
f.writelines( f.writelines(
[ [
"FRAPPE_VERSION=v14\n", # Defaults to latest version of Frappe f"FRAPPE_VERSION={example_env['FRAPPE_VERSION']}\n", # Defaults to latest version of Frappe
"ERPNEXT_VERSION=v14\n", # defaults to latest version of ERPNext f"ERPNEXT_VERSION={example_env['ERPNEXT_VERSION']}\n", # defaults to latest version of ERPNext
f"DB_PASSWORD={db_pass}\n", f"DB_PASSWORD={db_pass}\n",
"DB_HOST=db\n", "DB_HOST=db\n",
"DB_PORT=3306\n", "DB_PORT=3306\n",
@ -98,9 +109,10 @@ def setup_prod(project: str, sitename: str, email: str) -> None:
level=3, level=3,
) )
with open(compose_file_name, "w") as f: with open(compose_file_name, "w") as f:
# Writing to compose file
if not os.path.exists(os.path.join(docker_repo_path, ".env")):
admin_pass = generate_pass() admin_pass = generate_pass()
db_pass = generate_pass(9) db_pass = generate_pass(9)
if not os.path.exists(os.path.join(docker_repo_path, ".env")):
write_to_env(docker_repo_path, sitename, db_pass, admin_pass, email) write_to_env(docker_repo_path, sitename, db_pass, admin_pass, email)
cprint( cprint(
"\nA .env file is generated with basic configs. Please edit it to fit to your needs \n", "\nA .env file is generated with basic configs. Please edit it to fit to your needs \n",
@ -144,6 +156,7 @@ def setup_prod(project: str, sitename: str, email: str) -> None:
cprint("\nGenerating Compose File failed\n") cprint("\nGenerating Compose File failed\n")
sys.exit(1) sys.exit(1)
try: try:
# Starting with generated compose file
subprocess.run( subprocess.run(
[ [
which("docker"), which("docker"),