Skip to content

Commit ce2f771

Browse files
committed
ci: build separate CI image per python version to reduce disk usage
1 parent 27e2821 commit ce2f771

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@ jobs:
4848
- 'docs/**'
4949
- '*.md'
5050
51-
build-ci-image:
52-
name: Build CI Image
51+
build-ci-images:
52+
name: Build CI Image (Python ${{ matrix.python-version }})
5353
runs-on: ubuntu-latest
5454
timeout-minutes: 30
5555
needs: check-changes
5656
if: needs.check-changes.outputs.source-changed == 'true'
57+
strategy:
58+
fail-fast: false
59+
matrix:
60+
python-version: ["3.10", "3.11", "3.12", "3.13"]
5761
outputs:
58-
image-tag: ${{ steps.meta.outputs.tags }}
59-
image-digest: ${{ steps.build.outputs.digest }}
62+
image-tag-py${{ matrix.python-version }}: ${{ steps.meta.outputs.tags }}
6063
steps:
6164
- name: Free disk space
6265
run: |
@@ -86,7 +89,7 @@ jobs:
8689
id: meta
8790
uses: docker/metadata-action@v5
8891
with:
89-
images: ghcr.io/${{ github.repository }}/ci
92+
images: ghcr.io/${{ github.repository }}/ci-py${{ matrix.python-version }}
9093
tags: |
9194
type=sha,prefix={{branch}}-
9295
@@ -103,9 +106,11 @@ jobs:
103106
push: true
104107
tags: ${{ steps.meta.outputs.tags }}
105108
labels: ${{ steps.meta.outputs.labels }}
106-
cache-from: type=gha
107-
cache-to: type=gha,mode=max
109+
cache-from: type=gha,scope=py${{ matrix.python-version }}
110+
cache-to: type=gha,mode=max,scope=py${{ matrix.python-version }}
108111
outputs: type=registry,compression=zstd
112+
build-args: |
113+
PYTHON_VERSION=${{ matrix.python-version }}
109114
lint:
110115
name: Lint
111116
runs-on: ubuntu-latest
@@ -136,11 +141,11 @@ jobs:
136141
build-wheel:
137142
name: Build wheel (Linux x86_64, Python ${{ matrix.python-version }})
138143
runs-on: ubuntu-latest
139-
needs: [check-changes, build-ci-image]
144+
needs: [check-changes, build-ci-images]
140145
if: needs.check-changes.outputs.source-changed == 'true'
141146
timeout-minutes: 30
142147
container:
143-
image: ${{ needs.build-ci-image.outputs.image-tag }}
148+
image: ghcr.io/${{ github.repository }}/ci-py${{ matrix.python-version }}:${{ github.ref_name }}-${{ github.sha }}
144149
credentials:
145150
username: ${{ github.actor }}
146151
password: ${{ secrets.GITHUB_TOKEN }}
@@ -169,11 +174,11 @@ jobs:
169174
build-docs:
170175
name: Build docs
171176
runs-on: ubuntu-latest
172-
needs: [check-changes, build-ci-image, build-wheel]
177+
needs: [check-changes, build-ci-images, build-wheel]
173178
if: always() && (needs.check-changes.outputs.source-changed == 'true' || needs.check-changes.outputs.docs-changed == 'true')
174179
timeout-minutes: 15
175180
container:
176-
image: ${{ needs.build-ci-image.outputs.image-tag }}
181+
image: ghcr.io/${{ github.repository }}/ci-py3.10:${{ github.ref_name }}-${{ github.sha }}
177182
credentials:
178183
username: ${{ github.actor }}
179184
password: ${{ secrets.GITHUB_TOKEN }}

Dockerfile.ci

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

12-
# Install system dependencies and Python versions in one layer with aggressive cleanup
12+
# Install system dependencies and specific Python version
1313
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
1414
--mount=type=cache,target=/var/lib/apt,sharing=locked \
1515
apt-get update && \
@@ -18,10 +18,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
1818
add-apt-repository -y ppa:deadsnakes/ppa && \
1919
apt-get update && \
2020
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 \
21+
python${PYTHON_VERSION} python${PYTHON_VERSION}-venv python${PYTHON_VERSION}-dev \
2522
python3-pip && \
2623
rm -rf /var/lib/apt/lists/* /var/cache/apt/* /tmp/*
2724

0 commit comments

Comments
 (0)