-
Notifications
You must be signed in to change notification settings - Fork 27
Docker Deployment For Kelvin Evaluator #825
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
Changes from 5 commits
4b7bb73
d05cf1f
289d2ee
84b87b4
592a9bd
f0695f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,34 @@ | ||
| # Kelvin | ||
| tasks/ | ||
| submits/ | ||
| submit_results/ | ||
| kelvin_data/ | ||
|
|
||
| # Python | ||
| .venv/ | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *.pyd | ||
| *.pyo | ||
| *.so | ||
| .pytest_cache/ | ||
| .mypy_cache/ | ||
| .ruff_cache/ | ||
| .coverage | ||
| htmlcov/ | ||
|
|
||
| # Node | ||
| node_modules/ | ||
| **/dist/ | ||
| **/.vite/ | ||
|
|
||
| # VCS / tooling | ||
| .git/ | ||
|
|
||
| # Logs | ||
| **/*.log | ||
|
|
||
| # Editor | ||
| .vscode/ | ||
| .idea/ | ||
| .DS_Store |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
|
|
||
| import django.contrib.auth.models | ||
| import requests | ||
| from django.conf import settings | ||
| from django.http import HttpRequest | ||
| from ipware import get_client_ip | ||
|
|
||
|
|
@@ -109,6 +110,26 @@ def download_source_to_path(source_url: str, destination_path: str) -> None: | |
|
|
||
| def build_absolute_uri(request, location): | ||
| base_uri = os.getenv("API_INTERNAL_BASEURL", None) | ||
|
|
||
| # If the URL is the default Docker-internal one ('https://nginx'), only use it in DEBUG mode which means it is local development. | ||
| # | ||
| # EXPLANATION: | ||
| # 1. In Docker, 'localhost' inside a container refers to the container itself, not the host machine. | ||
| # Therefore, to reach the Nginx container from the App container, we must use the service name 'nginx', | ||
| # which Docker's internal DNS resolves to the Nginx container's IP address. | ||
| # 2. However, this internal URL (https://nginx/...) is only accessible within the Docker network. | ||
| # It MUST NOT be used in Production for generating links sent to users (e.g. emails) or redirects, | ||
| # as users cannot resolve 'nginx' or access the private Docker network. | ||
| # | ||
| # If we are in Production (DEBUG=False) and the env var is still set to the default 'https://nginx', | ||
| # we explicitly unset it (set to None). | ||
| # | ||
| # This ensures that we do not mistakenly use the internal Docker URL 'https://nginx' in production. | ||
| # Instead, the code will fall back to using 'request.build_absolute_uri(location)', which constructs | ||
| # the URL using the public hostname from the incoming HTTP request. | ||
| if base_uri == "https://nginx" and not settings.DEBUG: | ||
|
||
| base_uri = None | ||
|
|
||
| if base_uri: | ||
| return "".join([base_uri, location]) | ||
| return request.build_absolute_uri(location) | ||
Uh oh!
There was an error while loading. Please reload this page.