docker: try to reduce image size

This commit is contained in:
Herculino Trotta
2024-10-25 15:48:36 -03:00
parent e9d1956048
commit d2be0be72d
2 changed files with 53 additions and 80 deletions

View File

@@ -1,47 +1,35 @@
# pull official base image
FROM python:3.11-slim-buster AS python
LABEL authors="Herculino de Miranda Trotta"
FROM python:3.11-slim-buster AS python-build-stage
FROM docker.io/python AS python-build-stage
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
gettext \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
RUN apt update && apt install --no-install-recommends -y \
# dependencies for building Python packages \
build-essential \
# psycopg2 dependencies \
gettext \
libpq-dev
# Requirements are installed here to ensure they will be cached.
COPY ../requirements.txt .
RUN pip wheel --wheel-dir /usr/src/app/wheels -r requirements.txt
# Create Python Dependency and Sub-Dependency Wheels.
RUN pip wheel --wheel-dir /usr/src/app/wheels \
-r requirements.txt
FROM python:3.11-slim-buster AS python-run-stage
FROM docker.io/python AS python-run-stage
#COPY --from=webpack_build /usr/src/frontend/build /usr/src/frontend/build
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
RUN apt update && apt install --no-install-recommends -y gettext
RUN pip install --upgrade pip
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
&& rm -rf /wheels/
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
RUN apt-get update && \
apt-get install --no-install-recommends -y gettext && \
rm -rf /var/lib/apt/lists/* && \
pip install --upgrade pip && \
pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* && \
rm -rf /wheels/ ~/.cache/pip/*
COPY ./docker/dev/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start
COPY ./docker/dev/procrastinate/start /start-procrastinate
RUN sed -i 's/\r$//g' /start-procrastinate
RUN chmod +x /start-procrastinate
RUN sed -i 's/\r$//g' /start && \
chmod +x /start && \
sed -i 's/\r$//g' /start-procrastinate && \
chmod +x /start-procrastinate
# copy project
COPY ./app .