1 changed files with 39 additions and 49 deletions
@ -1,61 +1,51 @@ |
|||
# pull official base image |
|||
FROM python:3.10-alpine |
|||
|
|||
# set work directory |
|||
# ======================================================= |
|||
# Optimized Production Dockerfile for Django Backend |
|||
# Using Debian-slim for instant pre-compiled binary wheels |
|||
# (scikit-image, numpy, scipy install in seconds vs 10m on Alpine) |
|||
# ======================================================= |
|||
FROM python:3.10-slim |
|||
|
|||
# Set work directory |
|||
WORKDIR /usr/src/app |
|||
|
|||
# set environment variables |
|||
ENV PYTHONDONTWRITEBYTECODE 1 |
|||
ENV PYTHONUNBUFFERED 1 |
|||
|
|||
# install psycopg2 dependencies and ffmpeg |
|||
RUN apk update && apk add --no-cache \ |
|||
git \ |
|||
wget \ |
|||
unzip \ |
|||
curl \ |
|||
postgresql-dev \ |
|||
# Set environment variables |
|||
ENV PYTHONDONTWRITEBYTECODE=1 \ |
|||
PYTHONUNBUFFERED=1 \ |
|||
PIP_NO_CACHE_DIR=1 \ |
|||
PIP_DISABLE_PIP_VERSION_CHECK=1 \ |
|||
CHROME_BIN=/usr/bin/chromium \ |
|||
CHROME_DRIVER=/usr/bin/chromedriver \ |
|||
DISPLAY=:99 |
|||
|
|||
# 1. System Dependencies (Cached permanently unless system packages change) |
|||
RUN apt-get update && apt-get install -y --no-install-recommends \ |
|||
gcc \ |
|||
g++ \ |
|||
python3-dev \ |
|||
musl-dev \ |
|||
jpeg-dev \ |
|||
zlib-dev \ |
|||
freetype-dev \ |
|||
gnupg \ |
|||
chromium \ |
|||
chromium-chromedriver \ |
|||
harfbuzz \ |
|||
nss \ |
|||
freetype \ |
|||
ttf-freefont \ |
|||
mesa-gl \ |
|||
alsa-lib \ |
|||
curl \ |
|||
git \ |
|||
libpq-dev \ |
|||
libjpeg62-turbo-dev \ |
|||
zlib1g-dev \ |
|||
libfreetype6-dev \ |
|||
gettext \ |
|||
ffmpeg \ |
|||
gettext |
|||
|
|||
|
|||
# Set environment variables for Chrome |
|||
ENV CHROME_BIN=/usr/bin/chromium-browser |
|||
ENV CHROME_DRIVER=/usr/bin/chromedriver |
|||
|
|||
# install dependencies |
|||
RUN pip install --upgrade pip |
|||
#RUN python -m pip install Pillow |
|||
chromium \ |
|||
chromium-driver \ |
|||
&& rm -rf /var/lib/apt/lists/* |
|||
|
|||
# 2. Python Dependencies (Cached unless requirements.txt changes) |
|||
COPY ./requirements.txt . |
|||
RUN pip install --upgrade pip && \ |
|||
pip install -r requirements.txt |
|||
|
|||
RUN --mount=type=cache,target=/root/.cache pip install -r requirements.txt |
|||
|
|||
# copy entrypoint.sh |
|||
COPY .env.prod .env |
|||
# 3. Entrypoint script (Cached) |
|||
COPY ./entrypoint.sh . |
|||
RUN sed -i 's/\r$//g' /usr/src/app/entrypoint.sh |
|||
RUN chmod +x /usr/src/app/entrypoint.sh |
|||
RUN sed -i 's/\r$//g' /usr/src/app/entrypoint.sh && \ |
|||
chmod +x /usr/src/app/entrypoint.sh |
|||
|
|||
# copy project |
|||
# 4. Application Source Code (Changes frequently on git push) |
|||
COPY . . |
|||
# Set display port to avoid crash |
|||
ENV DISPLAY=:99 |
|||
# run entrypoint.sh |
|||
|
|||
# Run entrypoint |
|||
ENTRYPOINT ["/usr/src/app/entrypoint.sh"] |
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue