Skip to content

Commit

Permalink
install build-essential to compile packages and use multi-stage build
Browse files Browse the repository at this point in the history
- Install build-essential to avoid build issues like psf#2568 when dependencies don't have prebuilt wheels available
- Use multi-stage build instead of trying to purge packages and cache from the image
  Copying `/root/.local/` installs only black's built Python dependencies (< 20 MB).
  So the image is barely larger than python:3-slim base image
  • Loading branch information
vbarbaresi committed Oct 31, 2021
1 parent 7bf233a commit 91cb0ab
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
FROM python:3-slim
FROM python:3-slim AS builder

# TODO: Remove regex version pin once we get newer arm wheels
RUN mkdir /src
COPY . /src/
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
&& apt update && apt install -y git \
# Install build tools to compile dependencies that don't have prebuilt wheels
&& apt update && apt install -y git build-essential \
&& cd /src \
&& pip install --no-cache-dir regex==2021.10.8 \
&& pip install --no-cache-dir .[colorama,d] \
&& rm -rf /src \
&& apt remove -y git \
&& apt autoremove -y \
&& rm -rf /var/lib/apt/lists/*
&& pip install --user --no-cache-dir .[colorama,d]

FROM python:3-slim

# copy only Python packages to limit the image size
COPY --from=builder /root/.local /root/.local
ENV PATH=/root/.local/bin:$PATH

CMD ["black"]

0 comments on commit 91cb0ab

Please sign in to comment.