From cbfc29f0e50790278e24890a239553cd14abd45c Mon Sep 17 00:00:00 2001 From: Alex Mayer Date: Fri, 5 Jul 2024 01:03:09 -0400 Subject: [PATCH] Optimize Dockerfile (#1679) * Optimize Dockerfile Use --mount instead of COPY to reduce image size * docs: add info to CHANGES --------- Co-authored-by: Sijis Aviles --- CHANGES.rst | 1 + Dockerfile | 36 +++++++++++++++++------------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 627517dc8..450fd1a0c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,7 @@ fixes: - chore: bump jinja to 3.1.3 (#1684) - chore: bump actions/setup-python version (#1686) - chore: bump actions/checkout version (#1696) +- chore: optimize Dockerfile (#1679) v6.2.0 (2024-01-01) ------------------- diff --git a/Dockerfile b/Dockerfile index f8a4872fa..3d3f0a4c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,28 @@ -ARG BASE_IMAGE=python:3.9-slim ARG INSTALL_EXTRAS=irc,XMPP,telegram,slack -FROM ${BASE_IMAGE} AS build +FROM python:3.9 AS build ARG INSTALL_EXTRAS + WORKDIR /wheel + COPY . . -RUN apt update && apt install -y build-essential git -RUN pip3 wheel --wheel-dir=/wheel \ - wheel . .[${INSTALL_EXTRAS}] +RUN pip wheel --wheel-dir=/wheel wheel . .[${INSTALL_EXTRAS}] -FROM ${BASE_IMAGE} AS base +FROM python:3.9-slim ARG INSTALL_EXTRAS -COPY --from=build /wheel /wheel -RUN apt update && \ - apt install -y git && \ - cd /wheel && \ - pip3 -vv install --no-cache-dir --no-index --find-links /wheel \ - errbot errbot[${INSTALL_EXTRAS}] && \ - rm -rf /wheel /var/lib/apt/lists/* -RUN useradd -m errbot - -FROM base -EXPOSE 3141 3142 -VOLUME /home/errbot -WORKDIR /home/errbot + +RUN --mount=from=build,source=/wheel,target=/wheel \ + pip install --no-cache-dir --no-index --find-links /wheel \ + errbot errbot[${INSTALL_EXTRAS}] + +RUN useradd --create-home --shell /bin/bash errbot USER errbot +WORKDIR /home/errbot + RUN errbot --init + +EXPOSE 3141 3142 +VOLUME /home/errbot STOPSIGNAL SIGINT + ENTRYPOINT [ "/usr/local/bin/errbot" ]