Skip to content

Commit

Permalink
add DATABASE_URL support
Browse files Browse the repository at this point in the history
  • Loading branch information
hUwUtao committed Nov 24, 2024
1 parent c2ace31 commit 0daed16
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 36 deletions.
16 changes: 6 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ USER wagtailuser

EXPOSE 8000

CMD [".venv/bin/gunicorn", \
"--bind", "0.0.0.0:8000", \
"--workers", "4", \
"--worker-class", "uvicorn.workers.UvicornWorker", \
"--max-requests", "1000", \
"--max-requests-jitter", "50", \
"--access-logfile", "-", \
"--error-logfile", "-", \
"--timeout", "120", \
"fuhoblog.wsgi:application"]
CMD . .venv/bin/activate && \
python manage.py migrate --noinput && \
.venv/bin/gunicorn --bind 0.0.0.0:8000 \
--workers 4 --worker-class uvicorn.workers.UvicornWorker \
--max-requests 1000 --max-requests-jitter 50 --access-logfile - --error-logfile - \
--timeout 120 fuhoblog.wsgi:application
10 changes: 6 additions & 4 deletions fuhoblog/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import dj_database_url
import dotenv

dotenv.load_dotenv()
Expand Down Expand Up @@ -117,10 +118,11 @@
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
"default": dj_database_url.config(
default="sqlite://./db.sqlite3",
conn_max_age=600,
conn_health_checks=True
)
}


Expand Down
22 changes: 0 additions & 22 deletions fuhoblog/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,6 @@
DATABASES = DATABASES # noqa: F405
WAGTAILSEARCH_BACKENDS = WAGTAILSEARCH_BACKENDS # noqa: F405

if os.environ.get('DATABASE') is not None:
try:
DATABASE_ENVIRON = urlparse(os.environ['DATABASE'])
if DATABASE_ENVIRON.scheme == 'mysql':
DATABASES |= {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': DATABASE_ENVIRON.path.replace('/', '') or 'wagtail',
'USER': DATABASE_ENVIRON.username or 'root',
'PASSWORD': DATABASE_ENVIRON.password or '',
'HOST': DATABASE_ENVIRON.hostname or 'localhost',
'PORT': int(DATABASE_ENVIRON.port or 3306) or 3306,
},
}
else:
print('DATABASE environment unknown scheme', DATABASE_ENVIRON.scheme)
except ValueError:
print('DATABASE environment variable invalid')
else:
print('Did not tried using DATABASE despite tried to load PRODUCTION config')


if os.environ['OPENSEARCH_HOST'] is not None:
WAGTAILSEARCH_BACKENDS = {
'default': {
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies = [
"uvicorn[standard]>=0.32.1",
"whitenoise>=6.8.2",
"django-storages[s3]>=1.14.4",
"dj-database-url>=2.3.0",
]

[project.optional-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ colorama==0.4.6 ; sys_platform == 'win32' or platform_system == 'Windows' \
defusedxml==0.7.1 \
--hash=sha256:1bb3032db185915b62d7c6209c5a8792be6a32ab2fedacc84e01b52c51aa3e69 \
--hash=sha256:a352e7e428770286cc899e2542b6cdaedb2b4953ff269a210103ec58f6198a61
dj-database-url==2.3.0 \
--hash=sha256:ae52e8e634186b57e5a45e445da5dc407a819c2ceed8a53d1fac004cc5288787 \
--hash=sha256:bb0d414ba0ac5cd62773ec7f86f8cc378a9dbb00a80884c2fc08cc570452521e
django==4.2.16 \
--hash=sha256:6f1616c2786c408ce86ab7e10f792b8f15742f7b7b7460243929cb371e7f1dad \
--hash=sha256:1ddc333a16fc139fd253035a1606bb24261951bbc3a6ca256717fa06cc41a898
Expand Down
15 changes: 15 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0daed16

Please sign in to comment.