Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove double prompts, fix app install in container and update image tag #119

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Docker/frappe/helper-function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ update_uid_gid() {
# $1 -> app_name respective to apps dir
get_app_name(){
local app="$1"
hooks_py_path="/workspce/frappe-bench/apps/$app"
local app_dir
app_dir="/workspace/frappe-bench/apps/${app}"
hooks_py_path=$(find "$app_dir" -maxdepth 2 -type f -name hooks.py)

# Extract the app name from the hooks.py file
APP_NAME=$(awk -F'"' '/app_name/{print $2}' "$hooks_py_path" || exit 0)
Expand Down
137 changes: 86 additions & 51 deletions frappe_manager/site_manager/SiteManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class SiteManager:
def __init__(self, sitesdir: Path, services = None):
def __init__(self, sitesdir: Path, services=None):
self.sitesdir = sitesdir
self.site = None
self.sitepath = None
Expand Down Expand Up @@ -57,7 +57,12 @@ def init(self, sitename: str | None = None):
f"The site '{sitename}' does not exist. Aborting operation."
)

self.site: Site = Site(sitepath, sitename, verbose=self.verbose,services=self.services)
self.site: Site = Site(
sitepath,
sitename,
verbose=self.verbose,
services=self.services,
)

def set_verbose(self):
"""
Expand Down Expand Up @@ -102,14 +107,16 @@ def stop_sites(self):
for site_compose_path in site_compose:
docker = DockerClient(compose_file_path=site_compose_path)
try:
output = docker.compose.stop(timeout=10, stream=not self.verbose)
output = docker.compose.stop(
timeout=10, stream=not self.verbose
)
if not self.verbose:
richprint.live_lines(output, padding=(0, 0, 0, 2))
except DockerException as e:
richprint.exit(f"{status_text}: Failed")
richprint.print(f"{status_text}: Done")

def create_site(self, template_inputs: dict,template_site: bool = False):
def create_site(self, template_inputs: dict, template_site: bool = False):
"""
Creates a new site using the provided template inputs.

Expand All @@ -130,7 +137,10 @@ def create_site(self, template_inputs: dict,template_site: bool = False):

if template_site:
self.site.remove_secrets()
richprint.exit(f"Created template site: {self.site.name}",emoji_code=":white_check_mark:")
richprint.exit(
f"Created template site: {self.site.name}",
emoji_code=":white_check_mark:",
)

richprint.change_head(f"Starting Site")
self.site.start()
Expand All @@ -149,10 +159,14 @@ def create_site(self, template_inputs: dict,template_site: bool = False):
)
richprint.print(f"Started site")
self.info()
if not '.localhost' in self.site.name:
richprint.print(f"Please note that You will have to add a host entry to your system's hosts file to access the site locally.")
if not ".localhost" in self.site.name:
richprint.print(
f"Please note that You will have to add a host entry to your system's hosts file to access the site locally."
)
else:
self.typer_context.obj["logger"].error(f"{self.site.name}: NOT WORKING")
self.typer_context.obj["logger"].error(
f"{self.site.name}: NOT WORKING"
)

richprint.stop()

Expand All @@ -165,23 +179,27 @@ def create_site(self, template_inputs: dict,template_site: bool = False):

richprint.error(error_message.format(log_path))

# prompt if site not working to delete the site
if typer.confirm(f"Do you want to delete this site {self.site.name}?"):
richprint.start("Removing Site")
self.remove_site()
else:
remove_status = self.remove_site()
if not remove_status:
self.info()

def remove_site(self):
def remove_site(self) -> bool:
"""
Removes the site.
"""
richprint.stop()
continue_remove= Prompt.ask(f"🤔 Do you want to remove [bold][green]'{self.site.name}'[/bold][/green]", choices=["yes", "no"],default='no')
if continue_remove == 'yes':
richprint.start('Removing Site')
self.site.remove_database_and_user()
self.site.remove()
continue_remove = Prompt.ask(
f"🤔 Do you want to remove [bold][green]'{self.site.name}'[/bold][/green]",
choices=["yes", "no"],
default="no",
)
if continue_remove == "no":
return False

richprint.start("Removing Site")
self.site.remove_database_and_user()
self.site.remove()
return True

def list_sites(self):
"""
Expand All @@ -206,7 +224,9 @@ def list_sites(self):
temp_site = Site(site_path, site_name)

row_data = f"[link=http://{temp_site.name}]{temp_site.name}[/link]"
path_data = f"[link=file://{temp_site.path}]{temp_site.path}[/link]"
path_data = (
f"[link=file://{temp_site.path}]{temp_site.path}[/link]"
)

status_color = "white"
status_msg = "Inactive"
Expand Down Expand Up @@ -237,13 +257,15 @@ def start_site(self):
"""
Starts the site.
"""
#self.migrate_site()
# self.migrate_site()
self.site.sync_site_common_site_config()
self.site.start()
self.site.frappe_logs_till_start(status_msg="Starting Site")
self.site.sync_workers_compose()

def attach_to_site(self, user: str, extensions: List[str], debugger: bool = False):
def attach_to_site(
self, user: str, extensions: List[str], debugger: bool = False
):
"""
Attaches to a running site's container using Visual Studio Code Remote Containers extension.

Expand Down Expand Up @@ -276,15 +298,15 @@ def attach_to_site(self, user: str, extensions: List[str], debugger: bool = Fals
vscode_config_json = [
{
"remoteUser": user,
"remoteEnv": {
"SHELL": "/bin/zsh"
"remoteEnv": {"SHELL": "/bin/zsh"},
"customizations": {
"vscode": {
"settings": {
"python.pythonPath": "/workspace/frappe-bench/env/bin/python"
},
"extensions": extensions,
}
},
"customizations": {"vscode": {
"settings": {
"python.pythonPath": "/workspace/frappe-bench/env/bin/python"
},
"extensions": extensions
}},
}
]

Expand All @@ -295,10 +317,12 @@ def attach_to_site(self, user: str, extensions: List[str], debugger: bool = Fals
# check if the extension are the same if they are different then only update
# check if customizations key available
try:
extensions_previous = json.loads(labels_previous["devcontainer.metadata"])
extensions_previous = extensions_previous[0]["customizations"]["vscode"][
"extensions"
]
extensions_previous = json.loads(
labels_previous["devcontainer.metadata"]
)
extensions_previous = extensions_previous[0]["customizations"][
"vscode"
]["extensions"]

except KeyError:
extensions_previous = []
Expand All @@ -315,27 +339,32 @@ def attach_to_site(self, user: str, extensions: List[str], debugger: bool = Fals
# sync debugger files
if debugger:
richprint.change_head("Sync vscode debugger configuration")
dot_vscode_dir = self.site.path / 'workspace' / '.vscode'
tasks_json_path = dot_vscode_dir / 'tasks'
launch_json_path = dot_vscode_dir / 'launch'
dot_vscode_dir = self.site.path / "workspace" / ".vscode"
tasks_json_path = dot_vscode_dir / "tasks"
launch_json_path = dot_vscode_dir / "launch"

dot_vscode_config = {
tasks_json_path : VSCODE_TASKS_JSON,
launch_json_path : VSCODE_LAUNCH_JSON,
tasks_json_path: VSCODE_TASKS_JSON,
launch_json_path: VSCODE_LAUNCH_JSON,
}

if not dot_vscode_dir.exists():
dot_vscode_dir.mkdir(exist_ok=True,parents=True)
dot_vscode_dir.mkdir(exist_ok=True, parents=True)

for file_path in [launch_json_path,tasks_json_path]:
file_name = f'{file_path.name}.json'
for file_path in [launch_json_path, tasks_json_path]:
file_name = f"{file_path.name}.json"
real_file_path = file_path.parent / file_name
if real_file_path.exists():
backup_tasks_path = file_path.parent / f"{file_path.name}.{datetime.now().strftime('%d-%b-%y--%H-%M-%S')}.json"
backup_tasks_path = (
file_path.parent
/ f"{file_path.name}.{datetime.now().strftime('%d-%b-%y--%H-%M-%S')}.json"
)
shutil.copy2(real_file_path, backup_tasks_path)
richprint.print(f"Backup previous '{file_name}' : {backup_tasks_path}")
richprint.print(
f"Backup previous '{file_name}' : {backup_tasks_path}"
)

with open(real_file_path, 'w+') as f:
with open(real_file_path, "w+") as f:
f.write(json.dumps(dot_vscode_config[file_path]))

richprint.print("Sync vscode debugger configuration: Done")
Expand Down Expand Up @@ -419,13 +448,17 @@ def info(self):
db_user = site_config["db_name"]
db_pass = site_config["db_password"]

frappe_password = self.site.composefile.get_envs("frappe")["ADMIN_PASS"]
frappe_password = self.site.composefile.get_envs("frappe")[
"ADMIN_PASS"
]
services_db_info = self.services.get_database_info()
root_db_password = services_db_info['password']
root_db_host = services_db_info['host']
root_db_user = services_db_info['user']
root_db_password = services_db_info["password"]
root_db_host = services_db_info["host"]
root_db_user = services_db_info["user"]

site_info_table = Table(show_lines=True, show_header=False, highlight=True)
site_info_table = Table(
show_lines=True, show_header=False, highlight=True
)

data = {
"Site Url": f"http://{self.site.name}",
Expand Down Expand Up @@ -468,7 +501,9 @@ def info(self):
running_site_workers = self.site.workers.get_services_running_status()

if running_site_services:
site_services_table = generate_services_table(running_site_services)
site_services_table = generate_services_table(
running_site_services
)
site_info_table.add_row("Site Services", site_services_table)

if running_site_workers:
Expand Down
4 changes: 2 additions & 2 deletions frappe_manager/templates/docker-compose.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ services:
global-backend-network:

socketio:
image: ghcr.io/rtcamp/frappe-manager-frappe:v0.10.0
image: ghcr.io/rtcamp/frappe-manager-frappe:v0.11.0
container_name: REPLACE_ME_WITH_CONTAINER_NAME
restart: always
environment:
Expand All @@ -95,7 +95,7 @@ services:
site-network:

schedule:
image: ghcr.io/rtcamp/frappe-manager-frappe:v0.10.0
image: ghcr.io/rtcamp/frappe-manager-frappe:v0.11.0
container_name: REPLACE_ME_WITH_CONTAINER_NAME
restart: always
environment:
Expand Down
2 changes: 1 addition & 1 deletion frappe_manager/templates/docker-compose.workers.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
worker-name:
image: ghcr.io/rtcamp/frappe-manager-frappe:v0.10.0
image: ghcr.io/rtcamp/frappe-manager-frappe:v0.11.0
restart: always
environment:
TIMEOUT: 6000
Expand Down