diff --git a/build/common/commands/constants.py b/build/common/commands/constants.py index 48093f13..9f888099 100644 --- a/build/common/commands/constants.py +++ b/build/common/commands/constants.py @@ -10,3 +10,4 @@ COMMON_SITE_CONFIG_FILE = 'common_site_config.json' DATE_FORMAT = "%Y%m%d_%H%M%S" RDS_DB = 'rds_db' RDS_PRIVILEGES = "SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, CREATE VIEW, EVENT, TRIGGER, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE, LOCK TABLES" +ARCHIVE_SITES_PATH = '/home/frappe/frappe-bench/sites/archive_sites' \ No newline at end of file diff --git a/build/common/commands/drop.py b/build/common/commands/drop.py new file mode 100644 index 00000000..da759524 --- /dev/null +++ b/build/common/commands/drop.py @@ -0,0 +1,39 @@ +import os +import frappe + +from frappe.commands.site import _drop_site +from constants import ARCHIVE_SITES_PATH +from utils import get_password + + +def main(): + site_name = os.environ.get("SITE_NAME", 'site1.localhost') + db_root_username = os.environ.get("DB_ROOT_USER", 'root') + mariadb_root_password = get_password("MYSQL_ROOT_PASSWORD", 'admin') + postgres_root_password = get_password("POSTGRES_PASSWORD") + db_root_password = mariadb_root_password + + if postgres_root_password: + db_root_password = postgres_root_password + + force = True if os.environ.get("FORCE", None) else False + no_backup = True if os.environ.get("NO_BACKUP", None) else False + frappe.init(site_name, new_site=True) + + _drop_site( + site=site_name, + root_login=db_root_username, + root_password=db_root_password, + archived_sites_path=ARCHIVE_SITES_PATH, + force=force, + no_backup=no_backup + ) + + if frappe.redis_server: + frappe.redis_server.connection_pool.disconnect() + + exit(0) + + +if __name__ == "__main__": + main() diff --git a/build/common/worker/docker-entrypoint.sh b/build/common/worker/docker-entrypoint.sh index 9e9bd831..6b617e56 100755 --- a/build/common/worker/docker-entrypoint.sh +++ b/build/common/worker/docker-entrypoint.sh @@ -149,6 +149,18 @@ elif [ "$1" = 'new' ]; then python /home/frappe/frappe-bench/commands/new.py fi +elif [ "$1" = 'drop' ]; then + checkConfigExists + checkConnection + if [[ -z "$RUN_AS_ROOT" ]]; then + su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \ + && python /home/frappe/frappe-bench/commands/drop.py" + exit + else + . /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/drop.py + fi + elif [ "$1" = 'migrate' ]; then su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \