Skip to content

Commit

Permalink
feat!: Restore site config from backup
Browse files Browse the repository at this point in the history
  • Loading branch information
cogk committed Oct 14, 2024
1 parent b0a2780 commit c1f5070
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions press/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ def restore_site(self, site: "Site", skip_failing_patches=False):
"managed_database_config": self._get_managed_db_config(site),
}

if site.remote_config_file:
data["site_config"] = json.dumps(self._restore_site_config(site))

return self.create_agent_job(
"Restore Site",
f"benches/{site.bench}/sites/{site.name}/restore",
Expand Down Expand Up @@ -251,22 +254,6 @@ def new_site_from_backup(self, site: "Site", skip_failing_patches=False):
site.check_enough_space_on_server()
apps = [app.app for app in site.apps]

def sanitized_site_config(site):
sanitized_config = {}
if site.remote_config_file:
from press.press.doctype.site_activity.site_activity import log_site_activity

site_config = frappe.get_doc("Remote File", site.remote_config_file)
new_config = site_config.get_content()
new_config["maintenance_mode"] = 0 # Don't allow deactivated sites to be created
sanitized_config = sanitize_config(new_config)
existing_config = json.loads(site.config)
existing_config.update(sanitized_config)
site._update_configuration(existing_config)
log_site_activity(site.name, "Update Configuration")

return json.dumps(sanitized_config)

public_link, private_link = None, None

if site.remote_public_file:
Expand All @@ -280,7 +267,7 @@ def sanitized_site_config(site):
"name": site.name,
"mariadb_root_password": self._get_mariadb_root_password(site),
"admin_password": site.get_password("admin_password"),
"site_config": sanitized_site_config(site),
"site_config": json.dumps(self._restore_site_config(site) or {}),
"database": frappe.get_doc("Remote File", site.remote_database_file).download_link,
"public": public_link,
"private": private_link,
Expand All @@ -296,6 +283,22 @@ def sanitized_site_config(site):
site=site.name,
)

def _restore_site_config(self, site: "Site"):
if not site.remote_config_file:
return None

from press.press.doctype.site_activity.site_activity import log_site_activity

site_config = frappe.get_doc("Remote File", site.remote_config_file)
new_config = site_config.get_content()
new_config["maintenance_mode"] = 0 # Don't allow deactivated sites to be created
sanitized_config = sanitize_config(new_config)
existing_config = json.loads(site.config)
existing_config.update(sanitized_config)
site._update_configuration(existing_config)
log_site_activity(site.name, "Update Configuration")
return sanitized_config

def install_app_site(self, site, app):
data = {"name": app}
return self.create_agent_job(
Expand Down

0 comments on commit c1f5070

Please sign in to comment.