diff --git a/.gitignore b/.gitignore index 7f3ad858..9d7e5c73 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ env.bak/ venv.bak/ .idea/ +/import/ /imports/ /servers/ /app/frontend/static/assets/images/auth/custom/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a02b859..e89ad4c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Add a wait to the call for the directory so we can make sure the wait dialogue has time to show up first ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/637)) - Fix bug where a reaction loop could be created, but would be cut short by an error when the loop occurred ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/636)) - Use controller on update user call ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/640)) +- Move `imports` to `import/upload` in bind mount to better serve users on unraid with limited vdisk storage ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/642)) ### Refactor - Consolidate remaining frontend functions into API V2, and remove ajax internal API ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/585)) - Replace bleach with nh3 ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/628)) @@ -30,6 +31,7 @@ - Add additional logging for server bootstrap & moves unnecessary logging to `debug` for improved log clarity ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/635)) - Bump orjson to 3.9.7 for python 3.12 support ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/638)) - Bump all Crafty required python dependancies, maintaining minimum 3.9 support ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/639)) +- Better optimize and refactor docker launcher sh ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/642)) ### Lang TBD

diff --git a/app/classes/shared/tasks.py b/app/classes/shared/tasks.py index 2322ac70..09627eba 100644 --- a/app/classes/shared/tasks.py +++ b/app/classes/shared/tasks.py @@ -757,11 +757,13 @@ class TasksManager: ) # Search for old files in imports self.helper.ensure_dir_exists( - os.path.join(self.controller.project_root, "imports") + os.path.join(self.controller.project_root, "import", "upload") ) - for file in os.listdir(os.path.join(self.controller.project_root, "imports")): + for file in os.listdir( + os.path.join(self.controller.project_root, "import", "upload") + ): if self.helper.is_file_older_than_x_days( - os.path.join(self.controller.project_root, "imports", file) + os.path.join(self.controller.project_root, "import", "upload", file) ): try: os.remove(os.path.join(file)) diff --git a/app/classes/web/routes/api/crafty/imports/index.py b/app/classes/web/routes/api/crafty/imports/index.py index 643a0aa4..e6c8c548 100644 --- a/app/classes/web/routes/api/crafty/imports/index.py +++ b/app/classes/web/routes/api/crafty/imports/index.py @@ -64,7 +64,9 @@ class ApiImportFilesIndexHandler(BaseApiHandler): # JSON we need to remove this and just send # the path. if data["upload"]: - folder = os.path.join(self.controller.project_root, "imports", folder) + folder = os.path.join( + self.controller.project_root, "import", "upload", folder + ) if Helpers.check_file_exists(folder): folder = self.file_helper.unzip_server(folder, user_id) root_path = True diff --git a/app/classes/web/upload_handler.py b/app/classes/web/upload_handler.py index 2d7653f9..0667dd12 100644 --- a/app/classes/web/upload_handler.py +++ b/app/classes/web/upload_handler.py @@ -102,7 +102,8 @@ class UploadHandler(BaseHandler): ) self.do_upload = False - path = os.path.join(self.controller.project_root, "imports") + path = os.path.join(self.controller.project_root, "import", "upload") + self.helper.ensure_dir_exists(path) # Delete existing files if len(os.listdir(path)) > 0: for item in os.listdir(): diff --git a/docker_launcher.sh b/docker_launcher.sh index c270ad2e..5f415d5b 100644 --- a/docker_launcher.sh +++ b/docker_launcher.sh @@ -1,19 +1,30 @@ #!/bin/sh +repair_permissions () { + printf "\033[36mWrapper | \033[35m📋 (1/3) Ensuring root group ownership...\033[0m\n" + find . ! -group root -print0 | xargs -0 -r chgrp root + printf "\033[36mWrapper | \033[35m📋 (2/3) Ensuring group read-write is present on files...\033[0m\n" + find . ! -perm g+rw -print0 | xargs -0 -r chmod g+rw + printf "\033[36mWrapper | \033[35m📋 (3/3) Ensuring sticky bit is present on directories...\033[0m\n" + find . -type d ! -perm g+s -print0 | xargs -0 -r chmod g+s +} + # Check if config exists taking one from image if needed. if [ ! "$(ls -A --ignore=.gitkeep ./app/config)" ]; then - echo "\033[36mWrapper | \033[33m🏗️ Config not found, pulling defaults..." + printf "\033[36mWrapper | \033[33m🏗️ Config not found, pulling defaults...\033[0m\n" mkdir ./app/config/ 2> /dev/null cp -r ./app/config_original/* ./app/config/ if [ $(id -u) -eq 0 ]; then # We're running as root; + # Look for files & dirs that require group permissions to be fixed # This will do the full /crafty dir, so will take a miniute. - echo "\033[36mWrapper | \033[35m📋 Looking for problem bind mount permissions globally..." - find . ! -group root -exec chgrp root {} \; - find . ! -perm g+rw -exec chmod g+rw {} \; - find . -type d ! -perm g+s -exec chmod g+s {} \; + printf "\033[36mWrapper | \033[35m📋 Looking for problem bind mount permissions globally...\033[0m\n" + + repair_permissions + + printf "\033[36mWrapper | \033[32m✅ Initialization complete!\033[0m\n" fi else # Keep version file up to date with image @@ -26,24 +37,24 @@ if [ $(id -u) -eq 0 ]; then # If we find files in import directory, we need to ensure all dirs are owned by the root group, # This fixes bind mounts that may have incorrect perms. - if [ "$(ls -A --ignore=.gitkeep ./import)" ]; then - echo "\033[36mWrapper | \033[35m📋 Files present in import directory, checking/fixing permissions..." - echo "\033[36mWrapper | \033[33m⏳ Please be paitent for larger servers..." - find . ! -group root -exec chgrp root {} \; - find . ! -perm g+rw -exec chmod g+rw {} \; - find . -type d ! -perm g+s -exec chmod g+s {} \; - echo "\033[36mWrapper | \033[32m✅ Permissions Fixed! (This will happen every boot until /import is empty!)" + if [ "$(find ./import -type f ! -name '.gitkeep')" ]; then + printf "\033[36mWrapper | \033[35m📋 Files present in import directory, checking/fixing permissions...\033[0m\n" + printf "\033[36mWrapper | \033[33m⏳ Please be patient for larger servers...\033[0m\n" + + repair_permissions + + printf "\033[36mWrapper | \033[32m✅ Permissions Fixed! (This will happen every boot until /import is empty!)\033[0m\n" fi - # Switch user, activate our prepared venv and lauch crafty + # Switch user, activate our prepared venv and launch crafty args="$@" - echo "\033[36mWrapper | \033[32m🚀 Launching crafty with [\033[34m$args\033[32m]" + printf "\033[36mWrapper | \033[32m🚀 Launching crafty with [\033[34m%s\033[32m]\033[0m\n" "$args" exec sudo -u crafty bash -c "source ./.venv/bin/activate && exec python3 main.py $args" else # Activate our prepared venv - echo "\033[36mWrapper | \033[32m🚀 Non-root host detected, using normal exec" + printf "\033[36mWrapper | \033[32m🚀 Non-root host detected, using normal exec\033[0m\n" . ./.venv/bin/activate # Use exec as our perms are already correct # This is likely if using Kubernetes/OpenShift etc - exec python3 main.py $@ + exec python3 main.py "$@" fi