From 9e162804e730d7bb6a1ced8d6637c326c4a8156a Mon Sep 17 00:00:00 2001 From: Cameron Hyde Date: Tue, 17 Dec 2024 13:23:59 +1000 Subject: [PATCH] Fix bootstrap lab temp dir --- ansible/group_vars/webservers.yml | 1 + ansible/roles/galaxy_labs_engine/defaults/main.yml | 1 + ansible/roles/galaxy_labs_engine/templates/.env.j2 | 2 ++ app/app/settings/base.py | 2 +- app/labs/bootstrap.py | 4 ++-- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ansible/group_vars/webservers.yml b/ansible/group_vars/webservers.yml index 0ebe567..7b6e1b6 100644 --- a/ansible/group_vars/webservers.yml +++ b/ansible/group_vars/webservers.yml @@ -40,6 +40,7 @@ create_directories: - "{{ config_root }}" - "{{ django_root }}/app/media" - "{{ django_root }}/app/logs" + - "{{ temp_dir }}" # Admin user login for the web admin admin_user: diff --git a/ansible/roles/galaxy_labs_engine/defaults/main.yml b/ansible/roles/galaxy_labs_engine/defaults/main.yml index e42f780..ace6aa7 100644 --- a/ansible/roles/galaxy_labs_engine/defaults/main.yml +++ b/ansible/roles/galaxy_labs_engine/defaults/main.yml @@ -11,6 +11,7 @@ nginx_limit_requests_per_minute: 10 project_root: /home/ubuntu/labs-engine config_root: /home/ubuntu/config django_root: "{{ project_root }}/app" +temp_dir: /tmp/labs_engine labs_engine: templates: diff --git a/ansible/roles/galaxy_labs_engine/templates/.env.j2 b/ansible/roles/galaxy_labs_engine/templates/.env.j2 index b4bc0ca..28a0e7b 100644 --- a/ansible/roles/galaxy_labs_engine/templates/.env.j2 +++ b/ansible/roles/galaxy_labs_engine/templates/.env.j2 @@ -21,6 +21,8 @@ GITHUB_API_TOKEN={{ github_api_token }} LOG_LEVEL_CONSOLE={{ django_log_levels.console|upper }} LOG_LEVEL_CACHE={{ django_log_levels.cache|upper }} +TMP_DIR={{ temp_dir }} + {% if django_sentry_dns %} SENTRY_DNS={{ django_sentry_dns }} {% endif %} diff --git a/app/app/settings/base.py b/app/app/settings/base.py index e1bd00e..ab2b6cb 100644 --- a/app/app/settings/base.py +++ b/app/app/settings/base.py @@ -42,7 +42,7 @@ STATIC_ROOT = BASE_DIR / 'app/static' MEDIA_ROOT = BASE_DIR / 'app/media' LOG_ROOT = ensure_dir(BASE_DIR / 'app/logs') -TEMP_DIR = ensure_dir(BASE_DIR / 'app/temp') +TEMP_DIR = ensure_dir(os.getenv('TMP_DIR', '/tmp/labs_engine/')) DEFAULT_EXPORTED_LAB_CONTENT_ROOT = ( f'http://{HOSTNAME}/static/labs/content/docs/base.yml') diff --git a/app/labs/bootstrap.py b/app/labs/bootstrap.py index 1aa3535..98529a8 100644 --- a/app/labs/bootstrap.py +++ b/app/labs/bootstrap.py @@ -10,7 +10,7 @@ from django.utils.text import slugify from pathlib import Path -HOURS_72 = 3 * 24 * 60 * 60 +HOURS_1 = 60 * 60 ALPHANUMERIC = string.ascii_letters + string.digits TEMPLATE_DIR = Path('labs/bootstrap') TEMPLATES_TO_RENDER = [ @@ -111,6 +111,6 @@ def create_logo(data, output_dir): def clean_dir(directory): """Delete directories that were created more than 7 days ago.""" for path in directory.iterdir(): - if path.is_dir() and path.stat().st_ctime < time.time() - HOURS_72: + if path.is_dir() and path.stat().st_ctime < time.time() - HOURS_1: shutil.rmtree(path) return directory