forked from learning-unlimited/ESP-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
116 lines (98 loc) · 4.21 KB
/
Copy pathDockerfile
File metadata and controls
116 lines (98 loc) · 4.21 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
FROM python:3.12-slim-bullseye AS builder
# Build-time environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
DEBIAN_FRONTEND=noninteractive
# Set the working directory
WORKDIR /app
# Skip dpkg fsync calls during package installs to speed up builder apt operations
# (safe in a throwaway builder layer; not propagated to the runtime image)
RUN printf '%s\n' 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-unsafe-io
# Install only build-time dependencies (compilers, -dev headers)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
git \
curl \
ca-certificates \
gnupg \
libcurl4-openssl-dev \
libssl-dev \
libmemcached-dev \
zlib1g-dev \
libjpeg-dev \
libfreetype6-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Node.js from nodesource, then LESS
RUN echo 'Acquire::Retries "5";' > /etc/apt/apt.conf.d/80-retries \
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y --no-install-recommends nodejs \
&& rm -rf /var/lib/apt/lists/*
RUN npm install -g --prefix /usr less@3.13.1
# Pre-install Bootstrap 3 / Bootswatch theme dependencies so the runtime
# image contains node_modules without needing npm at runtime.
COPY esp/public/media/theme_editor/package.json \
esp/public/media/theme_editor/package-lock.json \
/tmp/theme-npm/
RUN cd /tmp/theme-npm && npm ci
# Install Python dependencies
# Docker layer caching speeds up rebuilds
# --prefer-binary favors prebuilt wheels over slow source builds
COPY esp/requirements.txt /tmp/requirements.txt
RUN python -m pip install --upgrade pip setuptools wheel && \
python -m pip install --prefer-binary --no-cache-dir -r /tmp/requirements.txt
# Runtime stage - smaller final image
FROM python:3.12-slim-bullseye AS runtime
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
VIRTUAL_ENV=/usr \
DEBIAN_FRONTEND=noninteractive
WORKDIR /app
# Configure apt-get retries and timeouts for heavy LaTeX downloads
RUN printf '%s\n' \
'Acquire::http::Timeout "120";' \
'Acquire::https::Timeout "120";' \
'Acquire::ftp::Timeout "120";' \
'Acquire::Retries "3";' > /etc/apt/apt.conf.d/99custom
# Install runtime dependencies:
# - Slim runtime libraries (counterparts of builder's -dev packages)
# - Runtime tools from packages_base.txt (filtering out python*, build-essential, git, postgres*, memcached, and -dev packages)
COPY esp/packages_base.txt /tmp/packages_base.txt
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
postgresql-client \
libmemcached11 \
libcurl4 \
libssl1.1 \
libjpeg62-turbo \
libfreetype6 \
zlib1g \
ca-certificates \
$(grep -v -E '^(#|$|python|build-essential|git|postgres|memcached)' /tmp/packages_base.txt | grep -v -- '-dev$' | tr '\n' ' ') \
&& rm -rf /var/lib/apt/lists/*
# Copy Node.js and LESS from builder
COPY --from=builder /usr/bin/node /usr/bin/node
COPY --from=builder /usr/lib/node_modules /usr/lib/node_modules
RUN ln -s /usr/lib/node_modules/less/bin/lessc /usr/local/bin/lessc
# Copy pre-installed theme npm dependencies from builder.
# Also bake a second copy at /opt/theme_node_modules_baked so the entrypoint
# can restore a stale named volume without needing npm at runtime.
COPY --from=builder /tmp/theme-npm/node_modules \
/app/esp/public/media/theme_editor/node_modules
COPY --from=builder /tmp/theme-npm/node_modules /opt/theme_node_modules_baked
COPY --from=builder /tmp/theme-npm/package-lock.json /tmp/theme-pkg-lock.json
RUN sha256sum /tmp/theme-pkg-lock.json | cut -d' ' -f1 \
> /opt/theme_node_modules_baked/.lock-hash && \
rm /tmp/theme-pkg-lock.json
# Copy Python packages from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy entrypoint script
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN sed -i 's/\r$//' /app/docker-entrypoint.sh && \
chmod +x /app/docker-entrypoint.sh
# Copy application code (will be overridden by volume mount in dev)
COPY esp /app/esp
EXPOSE 8000
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["python", "manage.py", "runserver_plus", "0.0.0.0:8000"]