From 8732b70b309de278478b0c9a7393d3b12f4a3c78 Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Fri, 4 Nov 2022 15:15:19 +0100 Subject: [PATCH] Add shell script to run admin dev environment --- core/admin/.gitignore | 1 + core/admin/mailu/__init__.py | 6 ++- core/admin/mailu/configuration.py | 2 + core/admin/run_dev.sh | 83 +++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100755 core/admin/run_dev.sh diff --git a/core/admin/.gitignore b/core/admin/.gitignore index 5bb3bd8e..10ac2b76 100644 --- a/core/admin/.gitignore +++ b/core/admin/.gitignore @@ -2,3 +2,4 @@ lib64 .vscode tags +dev diff --git a/core/admin/mailu/__init__.py b/core/admin/mailu/__init__.py index fe1f376c..5bb40447 100644 --- a/core/admin/mailu/__init__.py +++ b/core/admin/mailu/__init__.py @@ -44,8 +44,10 @@ def create_app_from_config(config): # Initialize debugging tools if app.config.get("DEBUG"): debug.toolbar.init_app(app) - # TODO: add a specific configuration variable for profiling - # debug.profiler.init_app(app) + if app.config.get("DEBUG_PROFILER"): + debug.profiler.init_app(app) + if assets := app.config.get('DEBUG_ASSETS'): + app.static_folder = assets # Inject the default variables in the Jinja parser # TODO: move this to blueprints when needed diff --git a/core/admin/mailu/configuration.py b/core/admin/mailu/configuration.py index 081c4ee0..a4c8c537 100644 --- a/core/admin/mailu/configuration.py +++ b/core/admin/mailu/configuration.py @@ -13,6 +13,8 @@ DEFAULT_CONFIG = { 'RATELIMIT_STORAGE_URL': '', 'QUOTA_STORAGE_URL': '', 'DEBUG': False, + 'DEBUG_PROFILER': False, + 'DEBUG_ASSETS': '', 'DOMAIN_REGISTRATION': False, 'TEMPLATES_AUTO_RELOAD': True, 'MEMORY_SESSIONS': False, diff --git a/core/admin/run_dev.sh b/core/admin/run_dev.sh new file mode 100755 index 00000000..74bce531 --- /dev/null +++ b/core/admin/run_dev.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +### CONFIG + +DEV_PORT="${DEV_PORT:-8080}" +DEV_NAME="${DEV_NAME:-mailu-dev}" +DEV_PROFILE="${DEV_PROFILE:-false}" + + +### MAIN + +here="$(realpath "$(pwd)/${0%/*}")" +cd "${here}" + +docker="$(command -v podman || command -v docker || echo echo docker)" + +[[ -d dev ]] && rm -rf dev +mkdir -p dev/data || exit 1 + +# base +cp ../base/requirements-* dev/ +cp -r ../base/libs dev/ +sed -E '/^#/d;s:^FROM system$:FROM system AS base:' ../base/Dockerfile > dev/Dockerfile + +# assets +cp -r assets/content dev/ +sed -E '/^#/d;s:^(FROM [^ ]+$):\1 AS assets:' assets/Dockerfile >> dev/Dockerfile + +cat >> dev/Dockerfile <> dev/Dockerfile + +cat >> dev/Dockerfile <