Fix: Make log directory configurable via environment variable #1411
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
[Feature]Respect LOGS_DIR value #94
Small Note: This is my first issue and PR and I found it pretty challenging so if there are any issues with my documentation or in my solution, please do provide your input so that I can do better in the future.
This PR resolves an issue where the
LOGS_DIRsetting, when defined inlocal_settings.py, was being ignored by the Docker environment. The root cause was an order-of-operations problem incms/settings.pywhere theLOGGINGdictionary was configured before local settings were imported, preventing any overrides.This fix ensures that
local_settings.pyis imported before the logging configuration is built.Additionally, this PR introduces several essential fixes to the Docker development environment, particularly for users on Windows with WSL2, to resolve common startup failures. These changes make the local setup process significantly more reliable for new contributors.
Key Changes:
cms/settings.py: Moved thelocal_settings.pyimport block to a position above theLOGGINGdictionary. This is the primary fix for the bug.cms/local_settings.py: Added logic to readLOGS_DIRfrom an environment variable, aligning with Docker best practices.docker-compose.yaml:web,migrations,celery_worker,celery_beat) to build from local source (build: .) instead of using a pre-built image. This ensures local code changes are always used.LOGS_DIRenvironment variable to all application services, making the log path configurable.healthcheckto thedbservice anddepends_onconditions to other services to prevent a startup race condition.deploy/docker/entrypoint.sh:LOGS_DIRdirectory (mkdir -p) on container startup. This resolves issues where Docker volume mounts would hide or overwrite the directory.CRLF vs LF Line Endings in Shell Scripts::deploy/docker/directory (entrypoint.sh,prestart.sh, etc.) are saved with LF line endings before building the Docker image.These changes collectively fix the reported issue and dramatically improve the developer setup experience.
Steps
Pre-deploy
No pre-deployment actions are required. These changes are self-contained within the application's configuration and startup scripts.
Post-deploy
To verify the fix and demonstrate the new functionality, follow these steps:
Configure
docker-compose.yaml:Ensure the
LOGS_DIRenvironment variable is set for the relevant services (e.g.,web,migrations).In docker-compose.yaml, under the 'web' service environment:
environment:
LOGS_DIR: /home/mediacms.io/mediacms/custom_logs
Perform a Clean Rebuild and Relaunch:
Run the following commands in the project root to ensure all changes are applied:
docker compose down --volumes
docker compose build --no-cache
docker compose up
Verify Directory Creation:
Once the application is running, exec into the
webcontainer and list the directory contents:docker compose exec web /bin/bash
ls -l
The output will now show the
custom_logsdirectory, confirming that the setting was correctly applied and the directory was created.