Skip to content

Commit 99bd4c7

Browse files
feat: use sccache in CI
1 parent 70f1796 commit 99bd4c7

File tree

3 files changed

+94
-72
lines changed

3 files changed

+94
-72
lines changed

.github/workflows/build.yaml

Lines changed: 65 additions & 66 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
@@ -155,70 +161,62 @@
155161
type=semver,pattern=cpu-{{major}}.{{minor}}
156162
type=raw,value=cpu-latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
157163
type=raw,value=cpu-sha-${{ env.GITHUB_SHA_SHORT }}
158-
- name: Build and push Docker image
159-
id: build-and-push-75
160-
uses: docker/build-push-action@v4
161-
with:
162-
context: .
163-
file: Dockerfile-cuda
164-
push: ${{ github.event_name != 'pull_request' }}
165-
platforms: 'linux/amd64'
166-
build-args: |
167-
CUDA_COMPUTE_CAP=75
168-
GIT_SHA=${{ env.GITHUB_SHA }}
169-
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
170-
tags: ${{ steps.meta-75.outputs.tags }}
171-
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
174-
- name: Build and push Docker image
175-
id: build-and-push-80
176-
uses: docker/build-push-action@v4
177-
with:
178-
context: .
179-
file: Dockerfile-cuda
180-
push: ${{ github.event_name != 'pull_request' }}
181-
platforms: 'linux/amd64'
182-
build-args: |
183-
CUDA_COMPUTE_CAP=80
184-
GIT_SHA=${{ env.GITHUB_SHA }}
185-
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
186-
tags: ${{ steps.meta-80.outputs.tags }}
187-
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
190-
- name: Build and push Docker image
191-
id: build-and-push-86
192-
uses: docker/build-push-action@v4
193-
with:
194-
context: .
195-
file: Dockerfile-cuda
196-
push: ${{ github.event_name != 'pull_request' }}
197-
platforms: 'linux/amd64'
198-
build-args: |
199-
CUDA_COMPUTE_CAP=86
200-
GIT_SHA=${{ env.GITHUB_SHA }}
201-
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
202-
tags: ${{ steps.meta-86.outputs.tags }}
203-
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
206-
- name: Build and push Docker image
207-
id: build-and-push-90
208-
uses: docker/build-push-action@v4
209-
with:
210-
context: .
211-
file: Dockerfile-cuda
212-
push: ${{ github.event_name != 'pull_request' }}
213-
platforms: 'linux/amd64'
214-
build-args: |
215-
CUDA_COMPUTE_CAP=90
216-
GIT_SHA=${{ env.GITHUB_SHA }}
217-
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
218-
tags: ${{ steps.meta-90.outputs.tags }}
219-
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
164+
# - name: Build and push Docker image
165+
# id: build-and-push-75
166+
# uses: docker/build-push-action@v4
167+
# with:
168+
# context: .
169+
# file: Dockerfile-cuda
170+
# push: ${{ github.event_name != 'pull_request' }}
171+
# platforms: 'linux/amd64'
172+
# build-args: |
173+
# CUDA_COMPUTE_CAP=75
174+
# GIT_SHA=${{ env.GITHUB_SHA }}
175+
# DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
176+
# tags: ${{ steps.meta-75.outputs.tags }}
177+
# labels: ${{ steps.meta-75.outputs.labels }}
178+
# - name: Build and push Docker image
179+
# id: build-and-push-80
180+
# uses: docker/build-push-action@v4
181+
# with:
182+
# context: .
183+
# file: Dockerfile-cuda
184+
# push: ${{ github.event_name != 'pull_request' }}
185+
# platforms: 'linux/amd64'
186+
# build-args: |
187+
# CUDA_COMPUTE_CAP=80
188+
# GIT_SHA=${{ env.GITHUB_SHA }}
189+
# DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
190+
# tags: ${{ steps.meta-80.outputs.tags }}
191+
# labels: ${{ steps.meta-80.outputs.labels }}
192+
# - name: Build and push Docker image
193+
# id: build-and-push-86
194+
# uses: docker/build-push-action@v4
195+
# with:
196+
# context: .
197+
# file: Dockerfile-cuda
198+
# push: ${{ github.event_name != 'pull_request' }}
199+
# platforms: 'linux/amd64'
200+
# build-args: |
201+
# CUDA_COMPUTE_CAP=86
202+
# GIT_SHA=${{ env.GITHUB_SHA }}
203+
# DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
204+
# tags: ${{ steps.meta-86.outputs.tags }}
205+
# labels: ${{ steps.meta-86.outputs.labels }}
206+
# - name: Build and push Docker image
207+
# id: build-and-push-90
208+
# uses: docker/build-push-action@v4
209+
# with:
210+
# context: .
211+
# file: Dockerfile-cuda
212+
# push: ${{ github.event_name != 'pull_request' }}
213+
# platforms: 'linux/amd64'
214+
# build-args: |
215+
# CUDA_COMPUTE_CAP=90
216+
# GIT_SHA=${{ env.GITHUB_SHA }}
217+
# DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
218+
# tags: ${{ steps.meta-90.outputs.tags }}
219+
# labels: ${{ steps.meta-90.outputs.labels }}
222220
- name: Build and push Docker image
223221
id: build-and-push-cpu
224222
uses: docker/build-push-action@v4
@@ -228,12 +226,13 @@
228226
push: ${{ github.event_name != 'pull_request' }}
229227
platforms: 'linux/amd64'
230228
build-args: |
229+
SCCACHE_GHA_ENABLED="true"
230+
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
231+
ACTIONS_RUNTIME_TOKEN=${{ env.ACTIONS_RUNTIME_TOKEN }}
231232
GIT_SHA=${{ env.GITHUB_SHA }}
232233
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
233234
tags: ${{ steps.meta-cpu.outputs.tags }}
234235
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
237236

238237
stop-runner:
239238
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="false"
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="false"
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)