Skip to content

Commit 0472706

Browse files
authored
Attempt to speed up container builds (#1630)
### What does this PR do? This commit attempts the use of cargo-chef to improve our container build times. This is a follow-on from the caching improvements in PR #1629.
1 parent 122119b commit 0472706

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

.github/workflows/container.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ jobs:
5757
tags: ${{ steps.meta.outputs.tags }}
5858
push: true
5959
labels: ${{ steps.meta.outputs.labels }}
60-
cache-from: type=registry,ref=ghcr.io/datadog/lading:cache
61-
cache-to: type=registry,ref=ghcr.io/datadog/lading:cache,mode=max
60+
cache-from: type=registry,ref=ghcr.io/datadog/lading:cache-${{ matrix.arch }}
61+
cache-to: type=registry,ref=ghcr.io/datadog/lading:cache-${{ matrix.arch }},mode=max
6262

6363
copy-to-ecr:
6464
name: Copy ${{ matrix.arch }} to ECR

Dockerfile

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,53 @@
11
# Update the rust version in-sync with the version in rust-toolchain.toml
2-
FROM docker.io/rust:1.90.0-bookworm AS builder
32

3+
# Stage 0: Planner - Extract dependency metadata
4+
FROM docker.io/rust:1.90.0-slim-bookworm AS planner
5+
WORKDIR /app
6+
RUN cargo install cargo-chef --version 0.1.73
7+
COPY . .
8+
RUN cargo chef prepare --recipe-path recipe.json
9+
10+
# Stage 1: Cacher - Build dependencies only
11+
FROM docker.io/rust:1.90.0-slim-bookworm AS cacher
12+
WORKDIR /app
413
RUN apt-get update && apt-get install -y \
5-
protobuf-compiler fuse3 libfuse3-dev \
14+
pkg-config=1.8.1-1 \
15+
libssl-dev=3.0.17-1~deb12u3 \
16+
protobuf-compiler=3.21.12-3 \
17+
fuse3=3.14.0-4 \
18+
libfuse3-dev=3.14.0-4 \
619
&& rm -rf /var/lib/apt/lists/*
20+
RUN cargo install cargo-chef --version 0.1.73
21+
COPY --from=planner /app/recipe.json recipe.json
22+
# This layer is cached until Cargo.toml/Cargo.lock change
23+
RUN cargo chef cook --release --locked --features logrotate_fs --recipe-path recipe.json
724

25+
# Stage 2: Builder - Build source code
26+
FROM docker.io/rust:1.90.0-slim-bookworm AS builder
827
WORKDIR /app
9-
COPY . /app
28+
RUN apt-get update && apt-get install -y \
29+
pkg-config=1.8.1-1 \
30+
libssl-dev=3.0.17-1~deb12u3 \
31+
protobuf-compiler=3.21.12-3 \
32+
fuse3=3.14.0-4 \
33+
libfuse3-dev=3.14.0-4 \
34+
&& rm -rf /var/lib/apt/lists/*
35+
# Copy cached dependencies
36+
COPY --from=cacher /app/target target
37+
COPY --from=cacher /usr/local/cargo /usr/local/cargo
38+
# Copy source code (frequently changes)
39+
COPY . .
40+
# Build binary - reuses cached dependencies
1041
RUN cargo build --release --locked --bin lading --features logrotate_fs
1142

43+
# Stage 3: Runtime
1244
FROM docker.io/debian:bookworm-20241202-slim
13-
RUN apt-get update && apt-get install -y libfuse3-dev=3.14.0-4 fuse3=3.14.0-4 && rm -rf /var/lib/apt/lists/*
45+
RUN apt-get update && apt-get install -y \
46+
libfuse3-dev=3.14.0-4 \
47+
fuse3=3.14.0-4 \
48+
&& rm -rf /var/lib/apt/lists/*
1449
COPY --from=builder /app/target/release/lading /usr/bin/lading
1550

16-
# smoke test
51+
# Smoke test
1752
RUN ["/usr/bin/lading", "--help"]
1853
ENTRYPOINT ["/usr/bin/lading"]

0 commit comments

Comments
 (0)