more docker improvements
This commit is contained in:
@@ -8,7 +8,35 @@ import os
|
|||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
INTERNAL_IPS = ["82.69.88.125", "217.155.198.96", "localhost"]
|
INTERNAL_IPS = ["82.69.88.125", "217.155.198.96", "localhost", "127.0.0.1"]
|
||||||
|
|
||||||
|
# When running in Docker (dev), requests will often come from an internal
|
||||||
|
# container/network address. Add any discovered host/container IPs (and a
|
||||||
|
# likely gateway address) to INTERNAL_IPS so the debug toolbar can render.
|
||||||
|
if DEBUG:
|
||||||
|
try:
|
||||||
|
import socket
|
||||||
|
|
||||||
|
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
|
||||||
|
for ip in ips:
|
||||||
|
if ip not in INTERNAL_IPS:
|
||||||
|
INTERNAL_IPS.append(ip)
|
||||||
|
# common docker gateway pattern: replace last octet with '1'
|
||||||
|
parts = ip.split('.')
|
||||||
|
if len(parts) == 4:
|
||||||
|
parts[-1] = '1'
|
||||||
|
gw = '.'.join(parts)
|
||||||
|
if gw not in INTERNAL_IPS:
|
||||||
|
INTERNAL_IPS.append(gw)
|
||||||
|
except Exception:
|
||||||
|
# best-effort only; don't fail startup if this lookup doesn't work
|
||||||
|
pass
|
||||||
|
|
||||||
|
# In local/dev enable the toolbar unconditionally to avoid IP/proxy
|
||||||
|
# headaches while developing inside Docker/behind nginx.
|
||||||
|
DEBUG_TOOLBAR_CONFIG = {
|
||||||
|
"SHOW_TOOLBAR_CALLBACK": lambda request: True,
|
||||||
|
}
|
||||||
|
|
||||||
# Paths inside the nginx container / host-mounted deploy directories.
|
# Paths inside the nginx container / host-mounted deploy directories.
|
||||||
# On the server, these paths are mounted into nginx as described in the
|
# On the server, these paths are mounted into nginx as described in the
|
||||||
@@ -76,3 +104,17 @@ DATABASES = {
|
|||||||
#"PORT": os.environ.get("DB_PORT", "5432"),
|
#"PORT": os.environ.get("DB_PORT", "5432"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Development overrides to avoid forcing HTTPS and secure cookies in local dev
|
||||||
|
# (production should keep these True).
|
||||||
|
SECURE_SSL_REDIRECT = False
|
||||||
|
SESSION_COOKIE_SECURE = False
|
||||||
|
CSRF_COOKIE_SECURE = False
|
||||||
|
SECURE_HSTS_SECONDS = 0
|
||||||
|
|
||||||
|
# Allow requests from the local dev nginx/dev server and direct runserver
|
||||||
|
# (include scheme+host+port for Django's origin checking).
|
||||||
|
CSRF_TRUSTED_ORIGINS = [
|
||||||
|
"http://127.0.0.1:8000",
|
||||||
|
"http://localhost:8000",
|
||||||
|
]
|
||||||
@@ -5,6 +5,16 @@ services:
|
|||||||
web:
|
web:
|
||||||
env_file:
|
env_file:
|
||||||
- ../.env.dev
|
- ../.env.dev
|
||||||
|
# Development: run Django's autoreloading development server instead of
|
||||||
|
# the production entrypoint/gunicorn. Mount the repository into the
|
||||||
|
# container so code edits on the host trigger Django's autoreload.
|
||||||
|
entrypoint: ["python", "manage.py", "runserver", "0.0.0.0:8000"]
|
||||||
|
# Clear any command set by the prod compose file (which would be passed
|
||||||
|
# as an extra argument to manage.py). Setting an empty command prevents
|
||||||
|
# the image `command` from being appended to the entrypoint.
|
||||||
|
command: []
|
||||||
|
volumes:
|
||||||
|
- ../:/usr/src/app:cached
|
||||||
nginx:
|
nginx:
|
||||||
# Development nginx override: mount a simplified config that does not
|
# Development nginx override: mount a simplified config that does not
|
||||||
# reference LetsEncrypt certs so the container can start without real
|
# reference LetsEncrypt certs so the container can start without real
|
||||||
|
|||||||
Reference in New Issue
Block a user