From 44e0aca8ce3af1a5237ecd1f3cea14a861bcd120 Mon Sep 17 00:00:00 2001 From: Devansh Ashar Date: Fri, 19 Jan 2024 17:47:27 +0530 Subject: [PATCH 1/2] Issue #42:auto-created env files on run cmd also added env example files in respective folders co-authored-by: Dhruv co-authored-by: Tanish co-authored-by: Vidhita --- accounts/.env.example | 1 + atm-locator/.env.example | 3 + customer-auth/.env.example | 3 + dashboard/.env.example | 1 + loan/.env.example | 1 + scripts/run.py | 124 +++++++++++++++++++++++++++++++++++++ transactions/.env.example | 1 + 7 files changed, 134 insertions(+) create mode 100644 accounts/.env.example create mode 100644 atm-locator/.env.example create mode 100644 customer-auth/.env.example create mode 100644 dashboard/.env.example create mode 100644 loan/.env.example create mode 100644 scripts/run.py create mode 100644 transactions/.env.example diff --git a/accounts/.env.example b/accounts/.env.example new file mode 100644 index 0000000..adfd4cc --- /dev/null +++ b/accounts/.env.example @@ -0,0 +1 @@ +DB_URL= \ No newline at end of file diff --git a/atm-locator/.env.example b/atm-locator/.env.example new file mode 100644 index 0000000..42a7266 --- /dev/null +++ b/atm-locator/.env.example @@ -0,0 +1,3 @@ +DB_URL= +NODE_ENV= +PORT= \ No newline at end of file diff --git a/customer-auth/.env.example b/customer-auth/.env.example new file mode 100644 index 0000000..42a7266 --- /dev/null +++ b/customer-auth/.env.example @@ -0,0 +1,3 @@ +DB_URL= +NODE_ENV= +PORT= \ No newline at end of file diff --git a/dashboard/.env.example b/dashboard/.env.example new file mode 100644 index 0000000..adfd4cc --- /dev/null +++ b/dashboard/.env.example @@ -0,0 +1 @@ +DB_URL= \ No newline at end of file diff --git a/loan/.env.example b/loan/.env.example new file mode 100644 index 0000000..adfd4cc --- /dev/null +++ b/loan/.env.example @@ -0,0 +1 @@ +DB_URL= \ No newline at end of file diff --git a/scripts/run.py b/scripts/run.py new file mode 100644 index 0000000..1aff95b --- /dev/null +++ b/scripts/run.py @@ -0,0 +1,124 @@ +import os +import subprocess +import time +import shutil +import platform +####################################################################################### + +# Check for Dependencies +if not shutil.which("node"): + print("Node.js is not installed. Please install Node.js and npm.") + exit(1) +if platform.system()=='Windows': + os.chdir("..") + if not shutil.which("python"): + print("Python 3 is not installed. Please install Python 3.") + exit(1) +elif platform.system()=='Darwin': + os.chdir("..") + if not shutil.which("python3"): + print("Python 3 is not installed. Please install Python 3.") + exit(1) +elif platform.system() == 'Linux': + if not shutil.which("python3"): + print("Python 3 is not installed. Please install Python 3.") + exit(1) + +####################################################################################### +## Running Javascript microservices + +def run_javascript_microservice(service_name, service_alias): + + current_dir = os.getcwd() + print(f"Running {service_name} microservice...") + os.chdir(f"{current_dir}/{service_name}") + print(os.getcwd()) + env_file = ".env" + if not os.path.isfile(env_file): + file = ".env.example" + if os.path.isfile(file): + with open(file, 'r') as f: + for line in f: + key, _ = line.strip().split('=') + if key=='DB_URL': + new_value = input(f"Enter value for {key}: ") + else: + new_value = input(f"Enter value for {key} (optional): ") + with open(env_file, 'a') as env: + env.write(f"{key}={new_value}\n") + else: + print(f"{file} not found.") + if platform.system()=='Windows': + subprocess.run(["powershell.exe", "-command", f"Start-Process powershell.exe -ArgumentList \"-NoExit\", \"-Command\", \"npm install;npm run {service_alias}\""]) + elif platform.system()=='Darwin': + command = ( + f"osascript -e 'tell application \"Terminal\" to do script " + f"\"cd '{current_dir}' && cd '{service_name}' && " + f"npm install && npm run {service_alias}\"'" + ) + subprocess.run(command, shell=True) + elif platform.system()=='Linux': + subprocess.run(["dbus-launch", "gnome-terminal", "--", "bash", "-c", f"npm install && npm run {service_alias}"]) + else: + print('Unsupported os') + os.chdir(current_dir) + time.sleep(2) + print(f"{service_name} is running ...") + print() +run_javascript_microservice("ui", "ui") +run_javascript_microservice("customer-auth", "auth") +run_javascript_microservice("atm-locator", "atm") + +####################################################################################### +# Running Python microservices + +def run_python_microservice(service_name, service_alias): + current_dir = os.getcwd() + + print(f"Running {service_name} microservice ...") + + os.chdir(f"{current_dir}/{service_name}") + + env_file = ".env" + if not os.path.isfile(env_file): + file = ".env.example" + if os.path.isfile(file): + with open(file, 'r') as f: + for line in f: + key, _ = line.strip().split('=') + if key=='DB_URL': + new_value = input(f"Enter value for {key}: ") + else: + new_value = input(f"Enter value for {key} (optional): ") + with open(env_file, 'a') as env: + env.write(f"{key}={new_value}\n") + else: + print(f"{file} not found.") + if platform.system()=='Windows': + subprocess.run(["powershell.exe", "-command", f"Start-Process powershell.exe -ArgumentList \"-NoExit\", \"-Command\", \"python -m venv venv_bankapp; venv_bankapp\\Scripts\\activate; pip install -r requirements.txt; python {service_alias}.py\""]) + elif platform.system()=='Darwin': + command = ( + f"osascript -e 'tell application \"Terminal\" to do script " + f"\"cd '{current_dir}' && cd '{service_name}' && " + f"rm -rf venv_bankapp && python3 -m venv venv_bankapp && " + f"source venv_bankapp/bin/activate && " + f"pip3 install -r requirements.txt && python3 '{service_alias}.py'\"'" + ) + subprocess.run(command, shell=True) + elif platform.system()=='Linux': + pass + # subprocess.run(["dbus-launch","gnome-terminal", "--", "bash", "-c", f"python3 -m venv venv_bankapp && source venv_bankapp/bin/activate && pip install -r requirements.txt && python3 {service_alias}.py"]) + else: + print('Unsupported os') + os.chdir(current_dir) + time.sleep(2) + + print(f"{service_name} is running ...") + print() + +run_python_microservice("dashboard", "dashboard") +run_python_microservice("accounts", "accounts") +run_python_microservice("transactions", "transaction") +run_python_microservice("loan", "loan") + +print("Setup completed successfully!") diff --git a/transactions/.env.example b/transactions/.env.example new file mode 100644 index 0000000..adfd4cc --- /dev/null +++ b/transactions/.env.example @@ -0,0 +1 @@ +DB_URL= \ No newline at end of file From a3a8b75360515641ae72347240900e9947a53124 Mon Sep 17 00:00:00 2001 From: Devansh Ashar Date: Sun, 28 Jan 2024 11:15:49 +0530 Subject: [PATCH 2/2] Minor change co-authored-by: Dhruv co-authored-by: Tanish co-authored-by: Vidhita --- scripts/run.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/run.py b/scripts/run.py index 1aff95b..ae3d180 100644 --- a/scripts/run.py +++ b/scripts/run.py @@ -3,7 +3,6 @@ import time import shutil import platform -####################################################################################### # Check for Dependencies if not shutil.which("node"):