Skip to content

Commit

Permalink
Optimize Dockerfile (#1679)
Browse files Browse the repository at this point in the history
* Optimize Dockerfile

Use --mount instead of COPY to reduce image size

* docs: add info to CHANGES

---------

Co-authored-by: Sijis Aviles <sijis.aviles@gmail.com>
  • Loading branch information
amayer5125 and sijis authored Jul 5, 2024
1 parent eb51a93 commit cbfc29f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-------------------
Expand Down
36 changes: 17 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]

0 comments on commit cbfc29f

Please sign in to comment.