init commit
This commit is contained in:
48
Dockerfile
Normal file
48
Dockerfile
Normal file
@@ -0,0 +1,48 @@
|
||||
# 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
|
||||
|
||||
# Start the Django server with wait for database
|
||||
CMD ["sh", "-c", "./wait-for-it.sh postgres_db:5432 -- python smartsoltech/manage.py migrate && python smartsoltech/manage.py runserver 0.0.0.0:8000"]
|
||||
Reference in New Issue
Block a user