53 lines
1.5 KiB
Docker
53 lines
1.5 KiB
Docker
# Dockerfile for Django Application
|
|
|
|
# Base image
|
|
FROM python:3.10-slim
|
|
|
|
# Set environment variables
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
# Set work directory
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
postgresql-client \
|
|
netcat-traditional \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Python dependencies
|
|
COPY requirements.txt /app/
|
|
RUN pip install --upgrade pip && pip install -r requirements.txt
|
|
|
|
# Copy the project files to the container
|
|
COPY . /app/
|
|
|
|
# Replace the template file inside the container
|
|
RUN if [ -f patch/fieldset.html ]; then \
|
|
cp patch/fieldset.html /usr/local/lib/python3.10/site-packages/jazzmin/templates/admin/includes/fieldset.html; \
|
|
fi
|
|
|
|
# Make wait-for-it script executable
|
|
RUN chmod +x wait-for-it.sh
|
|
|
|
# Create directories for static and media files
|
|
RUN mkdir -p /app/smartsoltech/static /app/smartsoltech/media
|
|
|
|
# Collect static files (with error handling)
|
|
RUN python smartsoltech/manage.py collectstatic --noinput || echo "Collectstatic will run after database is ready"
|
|
|
|
# Expose the port for the Django application
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000').read()" || exit 1
|
|
|
|
# Entrypoint scripts
|
|
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
|
COPY docker-entrypoint-bot.sh /docker-entrypoint-bot.sh
|
|
RUN chmod +x /docker-entrypoint.sh /docker-entrypoint-bot.sh
|
|
|
|
# Start the Django server
|
|
CMD ["/docker-entrypoint.sh"] |