Skip to content

Commit f6d8cb8

Browse files
committed
ci: optimize docker build for space - use build cache and aggressive cleanup
1 parent 46ed4a9 commit f6d8cb8

1 file changed

Lines changed: 25 additions & 19 deletions

File tree

Dockerfile.ci

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,39 @@ ARG PYTHON_VERSION=3.10
99
ENV PYTHON_VERSION=${PYTHON_VERSION}
1010
ENV DEBIAN_FRONTEND=noninteractive
1111

12-
RUN apt-get update && apt-get install -y --no-install-recommends \
13-
git \
14-
wget \
15-
cmake \
16-
build-essential \
17-
software-properties-common \
18-
&& rm -rf /var/lib/apt/lists/*
19-
RUN add-apt-repository -y ppa:deadsnakes/ppa && \
12+
# Install system dependencies and Python versions in one layer with aggressive cleanup
13+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
14+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
2015
apt-get update && \
21-
apt-get install -y \
22-
python3.10 python3.10-venv python3.10-dev \
23-
python3.11 python3.11-venv python3.11-dev \
24-
python3.12 python3.12-venv python3.12-dev \
25-
python3.13 python3.13-venv python3.13-dev \
26-
python3-pip \
27-
&& rm -rf /var/lib/apt/lists/*
16+
apt-get install -y --no-install-recommends \
17+
git wget cmake build-essential software-properties-common && \
18+
add-apt-repository -y ppa:deadsnakes/ppa && \
19+
apt-get update && \
20+
apt-get install -y --no-install-recommends \
21+
python3.10 python3.10-venv python3.10-dev \
22+
python3.11 python3.11-venv python3.11-dev \
23+
python3.12 python3.12-venv python3.12-dev \
24+
python3.13 python3.13-venv python3.13-dev \
25+
python3-pip && \
26+
rm -rf /var/lib/apt/lists/* /var/cache/apt/* /tmp/*
2827

2928
COPY test/requirements.txt /tmp/requirements-test.txt
3029
COPY docs/requirements.txt /tmp/requirements-docs.txt
3130

3231
# Set environment variable to allow pip installs in managed environment
3332
ENV PIP_BREAK_SYSTEM_PACKAGES=1
3433

35-
RUN pip install --no-cache-dir setuptools wheel build
36-
RUN pip install --no-cache-dir \
37-
-r /tmp/requirements-test.txt \
38-
-r /tmp/requirements-docs.txt
34+
# Install all dependencies in one layer with aggressive cleanup to save space
35+
RUN --mount=type=cache,target=/root/.cache/pip \
36+
pip install --no-cache-dir setuptools wheel build && \
37+
pip install --no-cache-dir \
38+
-r /tmp/requirements-test.txt \
39+
-r /tmp/requirements-docs.txt && \
40+
rm -rf /tmp/* && \
41+
find /usr -name "*.pyc" -delete && \
42+
find /usr -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true && \
43+
apt-get clean && \
44+
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
3945
ENV CUDA_HOME="/usr/local/cuda"
4046
ENV PATH="$PATH:/usr/local/cuda/bin"
4147
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"

0 commit comments

Comments
 (0)