Skip to content

Commit 101cbba

Browse files
authored
Merge pull request #207 from AAdewunmi/feat/ship-gunicorn-container-start-up
Feat/ship gunicorn container start up
2 parents e66398e + 8cde64a commit 101cbba

7 files changed

Lines changed: 45 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ coverage.xml
4747

4848
# Shell scripts
4949
*.sh
50+
!docker/entrypoint.sh

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# path: Dockerfile
22
FROM python:3.12-slim
33

4-
ENV PYTHONDONTWRITEBYTECODE=1
5-
ENV PYTHONUNBUFFERED=1
4+
ENV PYTHONDONTWRITEBYTECODE=1 \
5+
PYTHONUNBUFFERED=1 \
6+
PIP_NO_CACHE_DIR=1
67

78
WORKDIR /app
89

@@ -18,6 +19,9 @@ RUN pip install --upgrade pip \
1819

1920
COPY . /app
2021

22+
RUN chmod +x /app/docker/entrypoint.sh
23+
2124
EXPOSE 8000
2225

23-
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
26+
ENTRYPOINT ["sh", "/app/docker/entrypoint.sh"]
27+
CMD ["gunicorn", "config.wsgi:application", "-c", "gunicorn.conf.py"]

config/settings/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
MIDDLEWARE = [
3838
"django.middleware.security.SecurityMiddleware",
39+
"whitenoise.middleware.WhiteNoiseMiddleware",
3940
"django.contrib.sessions.middleware.SessionMiddleware",
4041
"django.middleware.common.CommonMiddleware",
4142
"django.middleware.csrf.CsrfViewMiddleware",
@@ -92,6 +93,7 @@
9293
STATIC_URL = "/static/"
9394
STATIC_ROOT = BASE_DIR / "staticfiles"
9495
STATICFILES_DIRS = [BASE_DIR / "static"]
96+
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
9597

9698
MEDIA_URL = "/media/"
9799
MEDIA_ROOT = BASE_DIR / "media"

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ services:
2020
web:
2121
build:
2222
context: .
23-
command: python manage.py runserver 0.0.0.0:8000
2423
env_file:
2524
- .env
2625
volumes:
@@ -32,4 +31,4 @@ services:
3231
condition: service_healthy
3332

3433
volumes:
35-
returnhub_postgres_data:
34+
returnhub_postgres_data:

docker/entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# path: docker/entrypoint.sh
2+
#!/usr/bin/env sh
3+
set -eu
4+
5+
if [ "${DJANGO_SETTINGS_MODULE:-config.settings.dev}" = "config.settings.production" ]; then
6+
python manage.py check --deploy --fail-level WARNING
7+
else
8+
python manage.py check
9+
fi
10+
11+
python manage.py migrate --noinput
12+
python manage.py collectstatic --noinput
13+
14+
exec "$@"

gunicorn.conf.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# path: gunicorn.conf.py
2+
"""Gunicorn process configuration for ReturnHub."""
3+
4+
from __future__ import annotations
5+
6+
import os
7+
8+
bind = "0.0.0.0:8000"
9+
workers = int(os.getenv("GUNICORN_WORKERS", "3"))
10+
worker_class = "gthread"
11+
threads = int(os.getenv("GUNICORN_THREADS", "4"))
12+
timeout = int(os.getenv("GUNICORN_TIMEOUT", "60"))
13+
graceful_timeout = 30
14+
keepalive = 5
15+
16+
accesslog = "-"
17+
errorlog = "-"
18+
capture_output = True
19+
loglevel = os.getenv("GUNICORN_LOG_LEVEL", "info")

requirements/base.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ djangorestframework>=3.15,<4.0
44
psycopg[binary]>=3.2,<4.0
55
python-dotenv>=1.0,<2.0
66
gunicorn>=23.0,<24.0
7+
whitenoise>=6.8,<7.0
78
joblib>=1.4,<2.0
89
pandas>=2.2,<3.0
910
scikit-learn>=1.5,<2.0

0 commit comments

Comments
 (0)