Spaces:
Runtime error
Runtime error
Commit ·
2d2d664
1
Parent(s): 5528998
chore(docker): update Dockerfile to support MySQL client and improve layer caching
Browse files- Added system dependencies for MySQL client to Dockerfile
- Reordered COPY commands to leverage Docker layer caching with requirements.txt
- Added permission setting for /app directory
- Changed CMD to run Django app using Python instead of Uvicorn
- Installed PyMySQL and configured it in Django settings to replace mysqlclient
- Updated requirements.txt to replace mysqlclient with PyMySQL and add resend package
- Dockerfile +17 -4
- Dockerfile.lightweight +29 -0
- pms_server/settings.py +4 -0
- requirements.txt +3 -2
Dockerfile
CHANGED
|
@@ -5,20 +5,33 @@ FROM python:3.11-slim
|
|
| 5 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
ENV PYTHONUNBUFFERED=1
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Set work directory
|
| 9 |
WORKDIR /app
|
| 10 |
|
| 11 |
-
# Copy
|
| 12 |
-
COPY . .
|
| 13 |
|
| 14 |
# Install Python dependencies
|
| 15 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
RUN chmod -R 777 /app
|
| 18 |
|
| 19 |
# Expose port
|
| 20 |
EXPOSE 7860
|
| 21 |
|
| 22 |
-
# Run the Django app using
|
| 23 |
CMD ["python", "app.py"]
|
| 24 |
-
# CMD ["uvicorn", "job_scraper_server.asgi:application", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 5 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
ENV PYTHONUNBUFFERED=1
|
| 7 |
|
| 8 |
+
# Install system dependencies for MySQL client
|
| 9 |
+
RUN apt-get update \
|
| 10 |
+
&& apt-get install -y \
|
| 11 |
+
pkg-config \
|
| 12 |
+
default-libmysqlclient-dev \
|
| 13 |
+
build-essential \
|
| 14 |
+
gcc \
|
| 15 |
+
g++ \
|
| 16 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
+
|
| 18 |
# Set work directory
|
| 19 |
WORKDIR /app
|
| 20 |
|
| 21 |
+
# Copy requirements first for better Docker layer caching
|
| 22 |
+
COPY requirements.txt .
|
| 23 |
|
| 24 |
# Install Python dependencies
|
| 25 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 26 |
|
| 27 |
+
# Copy project files
|
| 28 |
+
COPY . .
|
| 29 |
+
|
| 30 |
+
# Set permissions
|
| 31 |
RUN chmod -R 777 /app
|
| 32 |
|
| 33 |
# Expose port
|
| 34 |
EXPOSE 7860
|
| 35 |
|
| 36 |
+
# Run the Django app using Python
|
| 37 |
CMD ["python", "app.py"]
|
|
|
Dockerfile.lightweight
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Lightweight Dockerfile using PyMySQL (no build dependencies required)
|
| 2 |
+
# Use this if you want to avoid MySQL client compilation issues
|
| 3 |
+
|
| 4 |
+
FROM python:3.11-slim
|
| 5 |
+
|
| 6 |
+
# Set environment variables
|
| 7 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 8 |
+
ENV PYTHONUNBUFFERED=1
|
| 9 |
+
|
| 10 |
+
# Set work directory
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
|
| 13 |
+
# Copy requirements first for better Docker layer caching
|
| 14 |
+
COPY requirements.txt .
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies (PyMySQL doesn't need system libraries)
|
| 17 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 18 |
+
|
| 19 |
+
# Copy project files
|
| 20 |
+
COPY . .
|
| 21 |
+
|
| 22 |
+
# Set permissions
|
| 23 |
+
RUN chmod -R 777 /app
|
| 24 |
+
|
| 25 |
+
# Expose port
|
| 26 |
+
EXPOSE 7860
|
| 27 |
+
|
| 28 |
+
# Run the Django app
|
| 29 |
+
CMD ["python", "app.py"]
|
pms_server/settings.py
CHANGED
|
@@ -17,6 +17,10 @@ import resend
|
|
| 17 |
from dotenv import load_dotenv
|
| 18 |
import tempfile
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
load_dotenv()
|
| 21 |
|
| 22 |
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
|
|
| 17 |
from dotenv import load_dotenv
|
| 18 |
import tempfile
|
| 19 |
|
| 20 |
+
# Configure PyMySQL to work with Django
|
| 21 |
+
import pymysql
|
| 22 |
+
pymysql.install_as_MySQLdb()
|
| 23 |
+
|
| 24 |
load_dotenv()
|
| 25 |
|
| 26 |
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
requirements.txt
CHANGED
|
@@ -10,5 +10,6 @@ sendgrid
|
|
| 10 |
django-storages==1.14.3
|
| 11 |
boto3==1.35.40
|
| 12 |
botocore==1.35.40
|
| 13 |
-
|
| 14 |
-
python-dotenv==1.0.1
|
|
|
|
|
|
| 10 |
django-storages==1.14.3
|
| 11 |
boto3==1.35.40
|
| 12 |
botocore==1.35.40
|
| 13 |
+
PyMySQL==1.1.0
|
| 14 |
+
python-dotenv==1.0.1
|
| 15 |
+
resend
|