Skip to content

Commit 0983b22

Browse files
vbarbaresiJelleZijlstra
authored andcommitted
install build-essential to compile dependencies and use multi-stage build (#2582)
- 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
1 parent 74985a3 commit 0983b22

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
### Integrations
2828

2929
- Allow to pass `target_version` in the vim plugin (#1319)
30-
- Pin regex module to 2021.10.8 in our docker file as it has arm wheels available
31-
(#2579)
30+
- Install build tools in docker file and use multi-stage build to keep the image size
31+
down (#2582)
3232

3333
## 21.9b0
3434

Dockerfile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
FROM python:3-slim
1+
FROM python:3-slim AS builder
22

3-
# TODO: Remove regex version pin once we get newer arm wheels
43
RUN mkdir /src
54
COPY . /src/
65
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
7-
&& apt update && apt install -y git \
6+
# Install build tools to compile dependencies that don't have prebuilt wheels
7+
&& apt update && apt install -y git build-essential \
88
&& cd /src \
9-
&& pip install --no-cache-dir regex==2021.10.8 \
10-
&& pip install --no-cache-dir .[colorama,d] \
11-
&& rm -rf /src \
12-
&& apt remove -y git \
13-
&& apt autoremove -y \
14-
&& rm -rf /var/lib/apt/lists/*
9+
&& pip install --user --no-cache-dir .[colorama,d]
10+
11+
FROM python:3-slim
12+
13+
# copy only Python packages to limit the image size
14+
COPY --from=builder /root/.local /root/.local
15+
ENV PATH=/root/.local/bin:$PATH
1516

1617
CMD ["black"]

0 commit comments

Comments
 (0)