-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.django.prod
81 lines (60 loc) · 1.88 KB
/
Dockerfile.django.prod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Use Python 3.10 slim as base image
FROM python:3.10-slim AS builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE=backend.settings_production
# Set work directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
&& curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY backend/requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
# Install Tailwind CSS
RUN npm install -g tailwindcss
# Final stage
FROM python:3.10-slim
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE=backend.settings_production
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
&& curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy wheels from builder
COPY --from=builder /app/wheels /wheels
RUN pip install --no-cache /wheels/*
# Copy project
COPY backend .
COPY backend/docker-entrypoint.sh .
COPY backend/theme/static_src /app/backend/theme/static_src
# Create static and media directories
RUN mkdir -p /app/staticfiles /app/mediafiles
# Run Tailwind build
RUN python manage.py tailwind install
RUN python manage.py tailwind build
# Collect static files
RUN python manage.py collectstatic --noinput
# Set permissions
RUN chmod +x docker-entrypoint.sh
# Run as non-root user
RUN useradd -m django
RUN chown -R django:django /app
USER django
RUN pip install gunicorn
# Expose port
EXPOSE 8000
# Run entrypoint script
ENTRYPOINT ["/app/docker-entrypoint.sh"]