#FROM python:3.10-alpine FROM docker.io/python:3.10-slim AS base ENV \ LANG=C.UTF-8 \ LC_ALL=C.UTF-8 \ # python: PYTHONFAULTHANDLER=1 \ PYTHONUNBUFFERED=1 \ PYTHONHASHSEED=random \ PYTHONDONTWRITEBYTECODE=1 RUN apt-get update RUN apt-get install -y --no-install-recommends libmagic-dev libglib2.0-dev libpango-1.0-0 libpangoft2-1.0-0 ENV VIRTUAL_ENV=/venv # Use production configuration. ENV DJANGO_SETTINGS_MODULE=project.settings ENV DJANGO_CONFIGURATION=production ### builder image FROM base as build ENV \ # pip: PIP_NO_CACHE_DIR=off \ PIP_DISABLE_PIP_VERSION_CHECK=on \ PIP_DEFAULT_TIMEOUT=100 \ RUN apt-get install -y --no-install-recommends build-essential gcc # Install python build tools. RUN pip install --upgrade pip RUN pip install poetry wheel RUN python3 -m venv $VIRTUAL_ENV RUN mkdir -p /build WORKDIR /build # Install python dependencies. COPY requirements.txt requirements.txt ./ RUN . /venv/bin/activate && pip install -r requirements.txt # We will run dumb-init as pid 1. RUN . /venv/bin/activate && pip install dumb-init # We will run our app using gunicorn. RUN . /venv/bin/activate && pip install gunicorn # Copy local code into to the build image. COPY . /build # Copy code required for runtime to the /app folder. RUN mkdir /app RUN cp -r apps project templates manage.py /app/ # Collect static data into /app/static. RUN . /venv/bin/activate && \ DJANGO_STATIC_ROOT=/app/static ./manage.py collectstatic --no-input RUN ls -al /app/ ### runtime image FROM base as runtime #RUN apt-get install -y --no-install-recommends libpango-1.0-0 libpangoft2-1.0-0 #RUN apt-get install -y --no-install-recommends procps iproute2 curl COPY --from=build /venv /venv COPY --from=build /app /app WORKDIR /app # Ensure exectutables from virtualenv are prefered. ENV PATH="/venv/bin:$PATH" ENTRYPOINT ["/venv/bin/dumb-init", "--", "gunicorn", \ "-b [::]:8000", \ "--log-file=-", \ "--worker-tmp-dir", "/dev/shm", \ "--workers=2", "--threads=4", "--worker-class=gthread"] CMD ["project.wsgi"]