Skip to content

Commit ead3de3

Browse files
Merge pull request #11 from huggingface/feat/sscache
feat: use sccache in CI
2 parents 70f1796 + 87cc674 commit ead3de3

File tree

3 files changed

+50
-16
lines changed

3 files changed

+50
-16
lines changed

.github/workflows/build.yaml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
uses: docker/setup-buildx-action@v2.0.0
7777
with:
7878
install: true
79+
- name: Configure sccache
80+
uses: actions/github-script@v6
81+
with:
82+
script: |
83+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
84+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
7985
- name: Inject slug/short variables
8086
uses: rlespinasse/github-slug-action@v4.4.1
8187
- name: Tailscale
@@ -164,13 +170,14 @@
164170
push: ${{ github.event_name != 'pull_request' }}
165171
platforms: 'linux/amd64'
166172
build-args: |
173+
SCCACHE_GHA_ENABLED=on
174+
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
175+
ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }}
167176
CUDA_COMPUTE_CAP=75
168177
GIT_SHA=${{ env.GITHUB_SHA }}
169178
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
170179
tags: ${{ steps.meta-75.outputs.tags }}
171180
labels: ${{ steps.meta-75.outputs.labels }}
172-
cache-from: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-75,mode=min
173-
cache-to: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-75,mode=min
174181
- name: Build and push Docker image
175182
id: build-and-push-80
176183
uses: docker/build-push-action@v4
@@ -180,13 +187,14 @@
180187
push: ${{ github.event_name != 'pull_request' }}
181188
platforms: 'linux/amd64'
182189
build-args: |
190+
SCCACHE_GHA_ENABLED=on
191+
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
192+
ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }}
183193
CUDA_COMPUTE_CAP=80
184194
GIT_SHA=${{ env.GITHUB_SHA }}
185195
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
186196
tags: ${{ steps.meta-80.outputs.tags }}
187197
labels: ${{ steps.meta-80.outputs.labels }}
188-
cache-from: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-80,mode=min
189-
cache-to: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-80,mode=min
190198
- name: Build and push Docker image
191199
id: build-and-push-86
192200
uses: docker/build-push-action@v4
@@ -196,13 +204,14 @@
196204
push: ${{ github.event_name != 'pull_request' }}
197205
platforms: 'linux/amd64'
198206
build-args: |
207+
SCCACHE_GHA_ENABLED=on
208+
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
209+
ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }}
199210
CUDA_COMPUTE_CAP=86
200211
GIT_SHA=${{ env.GITHUB_SHA }}
201212
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
202213
tags: ${{ steps.meta-86.outputs.tags }}
203214
labels: ${{ steps.meta-86.outputs.labels }}
204-
cache-from: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-86,mode=min
205-
cache-to: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-86,mode=min
206215
- name: Build and push Docker image
207216
id: build-and-push-90
208217
uses: docker/build-push-action@v4
@@ -212,13 +221,14 @@
212221
push: ${{ github.event_name != 'pull_request' }}
213222
platforms: 'linux/amd64'
214223
build-args: |
224+
SCCACHE_GHA_ENABLED=on
225+
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
226+
ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }}
215227
CUDA_COMPUTE_CAP=90
216228
GIT_SHA=${{ env.GITHUB_SHA }}
217229
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
218230
tags: ${{ steps.meta-90.outputs.tags }}
219231
labels: ${{ steps.meta-90.outputs.labels }}
220-
cache-from: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-90,mode=min
221-
cache-to: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-90,mode=min
222232
- name: Build and push Docker image
223233
id: build-and-push-cpu
224234
uses: docker/build-push-action@v4
@@ -228,12 +238,13 @@
228238
push: ${{ github.event_name != 'pull_request' }}
229239
platforms: 'linux/amd64'
230240
build-args: |
241+
SCCACHE_GHA_ENABLED=on
242+
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
243+
ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }}
231244
GIT_SHA=${{ env.GITHUB_SHA }}
232245
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
233246
tags: ${{ steps.meta-cpu.outputs.tags }}
234247
labels: ${{ steps.meta-cpu.outputs.labels }}
235-
cache-from: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-cpu,mode=min
236-
cache-to: type=registry,ref=registry.internal.huggingface.tech/api-inference/text-embeddings-inference:cache-cpu,mode=min
237248

238249
stop-runner:
239250
name: Stop self-hosted EC2 runner

Dockerfile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
FROM lukemathwalker/cargo-chef:latest-rust-1.73-bookworm AS chef
22
WORKDIR /usr/src
33

4+
ENV SCCACHE=0.5.4
5+
ENV RUSTC_WRAPPER=/usr/local/bin/sccache
6+
7+
# Donwload and configure sccache
8+
RUN curl -fsSL https://github.com/mozilla/sccache/releases/download/v$SCCACHE/sccache-v$SCCACHE-x86_64-unknown-linux-musl.tar.gz | tar -xzv --strip-components=1 -C /usr/local/bin sccache-v$SCCACHE-x86_64-unknown-linux-musl/sccache && \
9+
chmod +x /usr/local/bin/sccache
10+
411
FROM chef AS planner
512

613
COPY backends backends
@@ -16,6 +23,11 @@ FROM chef AS builder
1623
ARG GIT_SHA
1724
ARG DOCKER_LABEL
1825

26+
# sccache specific variables
27+
ARG ACTIONS_CACHE_URL
28+
ARG ACTIONS_RUNTIME_TOKEN
29+
ARG SCCACHE_GHA_ENABLED
30+
1931
RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
2032
| gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null && \
2133
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | \
@@ -27,15 +39,15 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins
2739

2840
COPY --from=planner /usr/src/recipe.json recipe.json
2941

30-
RUN cargo chef cook --release --features candle --features mkl --no-default-features --recipe-path recipe.json
42+
RUN cargo chef cook --release --features candle --features mkl --no-default-features --recipe-path recipe.json && sccache -s
3143

3244
COPY backends backends
3345
COPY core core
3446
COPY router router
3547
COPY Cargo.toml ./
3648
COPY Cargo.lock ./
3749

38-
RUN cargo build --release --bin text-embeddings-router -F candle -F mkl --no-default-features
50+
RUN cargo build --release --bin text-embeddings-router -F candle -F mkl --no-default-features && sccache -s
3951

4052
FROM debian:bookworm-slim
4153

Dockerfile-cuda

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM nvidia/cuda:12.2.0-devel-ubuntu22.04 AS base-builder
22

3+
ENV SCCACHE=0.5.4
4+
ENV RUSTC_WRAPPER=/usr/local/bin/sccache
35
ENV PATH="/root/.cargo/bin:${PATH}"
46

57
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
@@ -8,6 +10,10 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins
810
pkg-config \
911
&& rm -rf /var/lib/apt/lists/*
1012

13+
# Donwload and configure sccache
14+
RUN curl -fsSL https://github.com/mozilla/sccache/releases/download/v$SCCACHE/sccache-v$SCCACHE-x86_64-unknown-linux-musl.tar.gz | tar -xzv --strip-components=1 -C /usr/local/bin sccache-v$SCCACHE-x86_64-unknown-linux-musl/sccache && \
15+
chmod +x /usr/local/bin/sccache
16+
1117
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
1218
RUN cargo install cargo-chef --locked
1319

@@ -29,6 +35,11 @@ ARG CUDA_COMPUTE_CAP=80
2935
ARG GIT_SHA
3036
ARG DOCKER_LABEL
3137

38+
# sccache specific variables
39+
ARG ACTIONS_CACHE_URL
40+
ARG ACTIONS_RUNTIME_TOKEN
41+
ARG SCCACHE_GHA_ENABLED
42+
3243
WORKDIR /usr/src
3344

3445
RUN if [ ${CUDA_COMPUTE_CAP} -ge 75 -a ${CUDA_COMPUTE_CAP} -lt 80 ]; \
@@ -48,9 +59,9 @@ COPY --from=planner /usr/src/recipe.json recipe.json
4859

4960
RUN if [ ${CUDA_COMPUTE_CAP} -ge 75 -a ${CUDA_COMPUTE_CAP} -lt 80 ]; \
5061
then \
51-
cargo chef cook --release --features candle-cuda-turing --features static-linking --no-default-features --recipe-path recipe.json; \
62+
cargo chef cook --release --features candle-cuda-turing --features static-linking --no-default-features --recipe-path recipe.json && sccache -s; \
5263
else \
53-
cargo chef cook --release --features candle-cuda --features static-linking --no-default-features --recipe-path recipe.json; \
64+
cargo chef cook --release --features candle-cuda --features static-linking --no-default-features --recipe-path recipe.json && sccache -s; \
5465
fi;
5566

5667
COPY backends backends
@@ -61,9 +72,9 @@ COPY Cargo.lock ./
6172

6273
RUN if [ ${CUDA_COMPUTE_CAP} -ge 75 -a ${CUDA_COMPUTE_CAP} -lt 80 ]; \
6374
then \
64-
cargo build --release --bin text-embeddings-router -F candle-cuda-turing -F static-linking --no-default-features; \
75+
cargo build --release --bin text-embeddings-router -F candle-cuda-turing -F static-linking --no-default-features && sccache -s; \
6576
else \
66-
cargo build --release --bin text-embeddings-router -F candle-cuda -F static-linking --no-default-features; \
77+
cargo build --release --bin text-embeddings-router -F candle-cuda -F static-linking --no-default-features && sccache -s; \
6778
fi;
6879

6980
FROM nvidia/cuda:12.2.0-base-ubuntu22.04

0 commit comments

Comments
 (0)