Skip to content

Commit ebbc12a

Browse files
committed
updated dockerfile and settings for production
1 parent 91e60ac commit ebbc12a

3 files changed

Lines changed: 63 additions & 19 deletions

File tree

Dockerfile

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,68 @@
1-
FROM python:3.12
1+
# FROM python:3.12
22

3-
# Ensure Python output is not buffered
4-
ENV PYTHONUNBUFFERED=1
3+
# # Ensure Python output is not buffered
4+
# ENV PYTHONUNBUFFERED=1
55

6-
# Set working directory inside the container
6+
# # Set working directory inside the container
7+
# WORKDIR /app
8+
9+
# # Copy dependencies list to container
10+
# COPY requirements.txt .
11+
12+
# # Install dependencies
13+
# RUN pip install --no-cache-dir -r requirements.txt
14+
15+
# # Copy the entire application to the container
16+
# COPY . .
17+
18+
# # Create static directory
19+
# RUN mkdir -p /app/static
20+
21+
# # # Collect static files during image build
22+
# # RUN python manage.py collectstatic --noinput
23+
24+
25+
# # Expose the port your application will run on
26+
# EXPOSE 8000
27+
28+
# # Default command to run the application
29+
# CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
30+
31+
# Use a slim Python image to reduce size
32+
FROM python:3.12-slim
33+
34+
# Set environment variables
35+
ENV PYTHONUNBUFFERED=1 \
36+
PYTHONDONTWRITEBYTECODE=1 \
37+
PIP_NO_CACHE_DIR=1 \
38+
PIP_DISABLE_PIP_VERSION_CHECK=1
39+
40+
# Install system dependencies (needed for PostgreSQL, etc.)
41+
RUN apt-get update && \
42+
apt-get install -y --no-install-recommends \
43+
build-essential \
44+
libpq-dev \
45+
&& rm -rf /var/lib/apt/lists/*
46+
47+
# Set the working directory
748
WORKDIR /app
849

9-
# Copy dependencies list to container
50+
# Copy and install Python dependencies first (for caching)
1051
COPY requirements.txt .
11-
12-
# Install dependencies
1352
RUN pip install --no-cache-dir -r requirements.txt
1453

15-
# Copy the entire application to the container
54+
# Copy the rest of the application
1655
COPY . .
1756

18-
# Create static directory
19-
RUN mkdir -p /app/static
20-
21-
# # Collect static files during image build
22-
# RUN python manage.py collectstatic --noinput
57+
# Collect static files (Render expects them in `/app/static`)
58+
RUN python manage.py collectstatic --noinput
2359

60+
# Run as a non-root user (security best practice)
61+
RUN useradd -m appuser && chown -R appuser:appuser /app
62+
USER appuser
2463

25-
# Expose the port your application will run on
64+
# Expose the port Render will use (8000 by default)
2665
EXPOSE 8000
2766

28-
# Default command to run the application
29-
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
67+
# Start Gunicorn (production-ready WSGI server)
68+
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "4", "IOLGenv2_BackEnd.wsgi:application"]

IOLGenv2_BackEnd/settings.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
'rest_framework_simplejwt.token_blacklist',
5151
"corsheaders",
5252
'import_export',
53-
'debug_toolbar',
5453
'widget_tweaks',
5554
'accounts',
5655
'ACGen',
@@ -69,7 +68,6 @@
6968
'django.contrib.auth.middleware.AuthenticationMiddleware',
7069
'django.contrib.messages.middleware.MessageMiddleware',
7170
'django.middleware.clickjacking.XFrameOptionsMiddleware',
72-
'debug_toolbar.middleware.DebugToolbarMiddleware',
7371
]
7472

7573
ROOT_URLCONF = 'IOLGenv2_BackEnd.urls'
@@ -124,6 +122,12 @@
124122

125123
load_dotenv()
126124

125+
DEBUG = os.getenv('DEBUG', 'False') == 'True'
126+
127+
if DEBUG:
128+
INSTALLED_APPS += ['debug_toolbar']
129+
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware']
130+
127131
DATABASE_URL = os.getenv("DATABASE_URL") # Get the env variable
128132

129133
if DATABASE_URL: # Only parse if DATABASE_URL is set

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ pandas
1717
django-widget-tweaks
1818
whitenoise
1919
waitress
20-
ioview-firebase-adminsdk
20+
ioview-firebase-adminsdk
21+
gunicorn==21.2.0

0 commit comments

Comments
 (0)