
- Install build-essential to avoid build issues like #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
18 lines
501 B
Docker
18 lines
501 B
Docker
FROM python:3-slim AS builder
|
|
|
|
RUN mkdir /src
|
|
COPY . /src/
|
|
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
|
|
# Install build tools to compile dependencies that don't have prebuilt wheels
|
|
&& apt update && apt install -y git build-essential \
|
|
&& cd /src \
|
|
&& 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"]
|