-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
website: updating settings file #4035
Conversation
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThe pull request introduces significant updates to the Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## staging #4035 +/- ##
========================================
Coverage 11.73% 11.73%
========================================
Files 114 114
Lines 15331 15372 +41
Branches 319 319
========================================
+ Hits 1799 1804 +5
- Misses 13532 13568 +36 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (1)
src/website/core/settings.py (1)
275-280
: Adding file upload size limits enhances securitySetting
FILE_UPLOAD_MAX_MEMORY_SIZE
andDATA_UPLOAD_MAX_MEMORY_SIZE
to 10 MB imposes reasonable limits on upload sizes, which helps prevent potential denial-of-service attacks from excessively large uploads.Consider making upload size limits configurable
For greater flexibility across different environments, consider sourcing these upload size limits from environment variables. This allows for easy adjustments without modifying the codebase.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/website/core/settings.py
(3 hunks)src/website/entrypoint.sh
(1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
src/website/entrypoint.sh
[warning] 9-9: child is referenced but not assigned.
(SC2154)
[warning] 13-13: In POSIX sh, prefixing signal names with 'SIG' is undefined.
(SC3048)
🔇 Additional comments (2)
src/website/core/settings.py (2)
58-58
: Clearer section heading for installed apps
Renaming the comment to Installed Apps improves clarity and aligns with Django's standard terminology.
118-122
: Consistent handling of trailing slashes in origins
The addition of code to strip trailing slashes from CORS_ALLOWED_ORIGINS
, CORS_ALLOWED_ORIGIN_REGEXES
, and CSRF_TRUSTED_ORIGINS
ensures consistency and prevents potential issues caused by mismatched URLs due to trailing slashes. This is a thoughtful improvement.
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') | ||
USE_X_FORWARDED_HOST = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Ensure SSL and proxy settings align with deployment environment
Enabling SECURE_PROXY_SSL_HEADER
and USE_X_FORWARDED_HOST
is appropriate when the application is behind a reverse proxy that sets the X-Forwarded-Proto
header, such as Nginx. If this isn't always the case, consider making these settings conditional based on an environment variable to prevent potential misconfigurations in other environments.
LOG_DIR = BASE_DIR / 'logs' | ||
LOG_DIR.mkdir(exist_ok=True) # Ensure log directory exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid side effects in settings.py
by removing directory creation
Creating directories within settings.py
can lead to unintended side effects since settings are imported at various points during the application's lifecycle. It's recommended to avoid I/O operations in settings files. Consider removing LOG_DIR.mkdir(exist_ok=True)
and ensuring that the log directory is created during the application's startup sequence or via deployment scripts.
src/website/entrypoint.sh
Outdated
echo "Collecting static files..." | ||
python manage.py collectstatic --noinput | ||
|
||
# Pre-create logs directory if not exists | ||
echo "Ensuring log directory exists..." | ||
mkdir -p /app/logs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Ensure consistent log directory paths across the application
The logs directory is being created at /app/logs
, whereas in settings.py
, it is defined as BASE_DIR / 'logs'
. Depending on how BASE_DIR
is resolved, these might point to different locations, potentially causing confusion or missing logs. Verify that both paths refer to the same directory, and consider centralizing the log directory path definition.
src/website/entrypoint.sh
Outdated
} | ||
|
||
# Trap SIGTERM signal | ||
trap _term SIGTERM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct signal name in trap command for POSIX compliance
In POSIX sh
, signal names should not include the SIG
prefix. Update the trap
command to use TERM
instead of SIGTERM
to ensure proper signal trapping.
Apply this change:
-trap _term SIGTERM
+trap _term TERM
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
trap _term SIGTERM | |
trap _term TERM |
🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 13-13: In POSIX sh, prefixing signal names with 'SIG' is undefined.
(SC3048)
src/website/entrypoint.sh
Outdated
# Function to handle signals and gracefully shut down Gunicorn | ||
_term() { | ||
echo "Caught SIGTERM signal! Shutting down Gunicorn..." | ||
kill -TERM "$child" 2>/dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assign the child
process ID to enable graceful shutdown
The variable $child
is referenced in the _term
function but hasn't been assigned. Without capturing the Gunicorn process ID, the script cannot gracefully terminate Gunicorn upon receiving a SIGTERM signal. Assign the PID of the Gunicorn process to $child
when starting it.
Suggested fix:
Start Gunicorn in the background and capture its PID:
-exec gunicorn core.wsgi:application \
+gunicorn core.wsgi:application \
--bind 0.0.0.0:8000 \
--timeout 600 \
--log-level info \
--workers "${GUNICORN_WORKERS:-3}" \
--access-logfile '-' \
--error-logfile '-' &
child=$!
wait "$child"
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
kill -TERM "$child" 2>/dev/null | |
gunicorn core.wsgi:application \ | |
--bind 0.0.0.0:8000 \ | |
--timeout 600 \ | |
--log-level info \ | |
--workers "${GUNICORN_WORKERS:-3}" \ | |
--access-logfile '-' \ | |
--error-logfile '-' & | |
child=$! | |
wait "$child" |
🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 9-9: child is referenced but not assigned.
(SC2154)
src/website/entrypoint.sh
Outdated
# Start Gunicorn server to serve the Django application | ||
echo "Starting Gunicorn server..." | ||
exec gunicorn core.wsgi:application --bind 0.0.0.0:8000 --timeout 600 --log-level info | ||
# exec gunicorn core.wsgi:application --bind 0.0.0.0:8000 --timeout 600 --workers ${GUNICORN_WORKERS:-3} --log-level info | ||
exec gunicorn core.wsgi:application \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Adjust Gunicorn execution to respect signal handling
Using exec
replaces the current shell with the Gunicorn process, which prevents the trap for TERM
from working correctly. By starting Gunicorn without exec
and capturing its PID, the script can handle signals properly and ensure a graceful shutdown.
Suggested change:
-exec gunicorn core.wsgi:application \
+gunicorn core.wsgi:application \
This aligns with the earlier suggestion to assign the Gunicorn process ID to $child
.
Committable suggestion skipped: line range outside the PR's diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
src/website/core/settings.py (2)
118-122
: Consider using list comprehension for CORS settingsThe current implementation can be more concise using list comprehension.
-CORS_ALLOWED_ORIGINS = [origin.rstrip('/') for origin in CORS_ALLOWED_ORIGINS] -CORS_ALLOWED_ORIGIN_REGEXES = [regex.rstrip( - '/') for regex in CORS_ALLOWED_ORIGIN_REGEXES] -CSRF_TRUSTED_ORIGINS = [origin.rstrip('/') for origin in CSRF_TRUSTED_ORIGINS] +CORS_ALLOWED_ORIGINS = [origin.rstrip('/') for origin in CORS_ALLOWED_ORIGINS] +CORS_ALLOWED_ORIGIN_REGEXES = [regex.rstrip('/') for regex in CORS_ALLOWED_ORIGIN_REGEXES] +CSRF_TRUSTED_ORIGINS = [origin.rstrip('/') for origin in CSRF_TRUSTED_ORIGINS]
279-280
: Consider environment variables for upload size limitsHard-coded upload size limits might need to be adjusted for different environments.
-FILE_UPLOAD_MAX_MEMORY_SIZE = 10485760 # 10 MB -DATA_UPLOAD_MAX_MEMORY_SIZE = 10485760 # 10 MB +FILE_UPLOAD_MAX_MEMORY_SIZE = int(os.getenv('FILE_UPLOAD_MAX_SIZE', 10485760)) # Default: 10 MB +DATA_UPLOAD_MAX_MEMORY_SIZE = int(os.getenv('DATA_UPLOAD_MAX_SIZE', 10485760)) # Default: 10 MB
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
src/website/Dockerfile
(1 hunks)src/website/core/settings.py
(3 hunks)src/website/entrypoint.sh
(1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
src/website/entrypoint.sh
[warning] 9-9: child is referenced but not assigned.
(SC2154)
[warning] 13-13: In POSIX sh, prefixing signal names with 'SIG' is undefined.
(SC3048)
🔇 Additional comments (6)
src/website/Dockerfile (1)
25-25
: Verify PORT environment variable configuration
The change from port 8000 to 8080 requires the PORT
environment variable to be properly set, as it's referenced in entrypoint.sh. Ensure this change is coordinated with your deployment configurations.
✅ Verification successful
Let me analyze the PORT configuration more thoroughly by checking configuration files, entrypoint scripts, and Dockerfiles for any PORT-related settings. This will help us verify if the port change is properly configured across the codebase.
I noticed the PORT is used in the entrypoint.sh and docker-compose.yaml. Let's examine these configurations more closely to ensure the port change is properly coordinated across the environment settings.
Port change is properly configured
The port change from 8000 to 8080 is correctly implemented as the PORT
environment variable is properly handled in the entrypoint.sh script, which uses it to configure Gunicorn's binding (--bind 0.0.0.0:$PORT
). This change aligns with the standard practices observed in the codebase where environment variables are used for port configuration.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if PORT is defined in any environment files
fd -t f ".*env.*" -x grep -l "PORT="
Length of output: 36
Script:
#!/bin/bash
# Let's check for PORT configuration in various configuration files and scripts
rg -l "PORT" --type-add 'config:*.{yaml,yml,json,conf,env}' -t config
# Check entrypoint.sh and similar files for PORT usage
fd "entrypoint" -x cat {}
# Check Dockerfile for PORT-related configurations
fd "Dockerfile" -x cat {}
Length of output: 18446
Script:
#!/bin/bash
# Let's check docker-compose.yaml for PORT configuration
cat src/workflows/docker-compose.yaml
# Let's also check for any environment variable defaults in the codebase
rg "PORT.*=" -g "!*.{md,txt}"
Length of output: 8458
src/website/entrypoint.sh (3)
13-13
:
Update signal name for POSIX compliance
The signal name should not include the 'SIG' prefix for POSIX compliance.
-trap _term SIGTERM
+trap _term TERM
Likely invalid or redundant comment.
🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 13-13: In POSIX sh, prefixing signal names with 'SIG' is undefined.
(SC3048)
29-35
:
Implement proper process management for Gunicorn
The current implementation using exec
prevents proper signal handling.
-exec gunicorn core.wsgi:application \
+gunicorn core.wsgi:application \
--bind 0.0.0.0:$PORT \
--timeout 600 \
--log-level info \
--workers "${GUNICORN_WORKERS:-3}" \
--access-logfile '-' \
--error-logfile '-' &
+
+child=$!
+wait "$child"
Likely invalid or redundant comment.
7-10
:
Fix signal handling implementation
The signal handling implementation has a critical issue where $child
is referenced but not assigned.
Apply this fix:
-_term() {
- echo "Caught SIGTERM signal! Shutting down Gunicorn..."
- kill -TERM "$child" 2>/dev/null
-}
+_term() {
+ echo "Caught SIGTERM signal! Shutting down Gunicorn..."
+ if [ -n "$child" ]; then
+ kill -TERM "$child" 2>/dev/null
+ fi
+}
Likely invalid or redundant comment.
🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 9-9: child is referenced but not assigned.
(SC2154)
src/website/core/settings.py (2)
294-349
: LGTM: Well-structured logging configuration
The logging configuration is comprehensive and well-organized, with appropriate handlers and formatters for different components.
291-292
:
Move directory creation to application startup
Creating directories in settings.py can lead to side effects.
Remove the directory creation from settings.py and move it to the application's startup sequence (e.g., in entrypoint.sh where other directories are created).
-LOG_DIR = BASE_DIR / 'logs'
-LOG_DIR.mkdir(exist_ok=True) # Ensure log directory exists
+LOG_DIR = BASE_DIR / 'logs'
Likely invalid or redundant comment.
website changes in this PR available for preview here |
website changes in this PR available for preview here |
Description
Summary by CodeRabbit
New Features
Bug Fixes
Chores