Skip to content

Commit 0c056c0

Browse files
committed
improve dockerfile caching
1 parent bac1561 commit 0c056c0

12 files changed

Lines changed: 140 additions & 95 deletions

File tree

.github/actions/rust-test-action/action.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/rust-build-and-tests.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ env:
1717
SCCACHE_GCS_KEY_PREFIX: sccache_dcipher
1818
SCCACHE_GCS_RW_MODE: READ_WRITE
1919
CARGO_TERM_COLOR: always
20-
TESTNETS_PRIVATE_KEY: ${{ secrets.TESTNETS_PRIVATE_KEY }}
21-
POLYGON_RPC_URL: ${{ secrets.POLYGON_RPC_URL }}
22-
BASE_SEPOLIA_RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }}
23-
AVALANCHE_FUJI_RPC_URL: ${{ secrets.AVALANCHE_FUJI_RPC_URL }}
20+
2421

2522
jobs:
2623
rust-tests:
@@ -47,6 +44,11 @@ jobs:
4744
- name: Run all tests
4845
run: cargo nextest run --target-dir './target' --no-tests warn --profile ci
4946
shell: bash
47+
env:
48+
TESTNETS_PRIVATE_KEY: ${{ secrets.TESTNETS_PRIVATE_KEY }}
49+
POLYGON_RPC_URL: ${{ secrets.POLYGON_RPC_URL }}
50+
BASE_SEPOLIA_RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }}
51+
AVALANCHE_FUJI_RPC_URL: ${{ secrets.AVALANCHE_FUJI_RPC_URL }}
5052

5153
rust-clippy:
5254
name: Run clippy

bin/adkg-cli/Dockerfile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ WORKDIR /app
55

66
FROM chef AS planner
77
COPY . .
8-
RUN cargo chef prepare --recipe-path recipe.json
8+
RUN cargo chef prepare --recipe-path recipe.json --bin adkg-cli
99

1010
FROM chef AS builder
1111
COPY --from=planner /app/recipe.json recipe.json
1212
# Build dependencies - this is the caching Docker layer!
13-
RUN cargo chef cook --release --recipe-path recipe.json
13+
RUN cargo chef cook --release --recipe-path recipe.json --bin adkg-cli
14+
# Copy local dependencies
15+
COPY Cargo.toml Cargo.lock ./
16+
COPY bin/adkg-cli/ ./bin/adkg-cli
17+
COPY crates/adkg ./crates/adkg
18+
COPY crates/config ./crates/config
19+
COPY crates/network ./crates/network
20+
COPY crates/utils ./crates/utils
1421
# Build application
15-
COPY . .
16-
RUN cargo build --release -p adkg-cli
17-
RUN strip target/release/adkg-cli
22+
RUN cargo build --release -p adkg-cli --bin adkg-cli
1823

1924
# We do not need the Rust toolchain to run the binary!
2025
FROM debian:bookworm-slim AS runtime

bin/blocklock-agent/Dockerfile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ WORKDIR /app
66

77
FROM chef AS planner
88
COPY . .
9-
RUN cargo chef prepare --recipe-path recipe.json
9+
RUN cargo chef prepare --recipe-path recipe.json --bin blocklock-agent
1010

1111
FROM chef AS builder
1212
COPY --from=planner /app/recipe.json recipe.json
13-
1413
# Build dependencies - this is the caching Docker layer!
15-
RUN cargo chef cook --release --recipe-path recipe.json
16-
14+
RUN cargo chef cook --release --recipe-path recipe.json --bin blocklock-agent
1715
# Build application
18-
COPY . .
16+
COPY Cargo.toml Cargo.lock ./
17+
COPY bin/blocklock-agent/ ./bin/blocklock-agent
18+
COPY crates/dcipher-agents ./crates/dcipher-agents
19+
COPY crates/generated ./crates/generated
20+
COPY crates/utils ./crates/utils
21+
COPY crates/config ./crates/config
22+
COPY crates/network ./crates/network
23+
COPY crates/signer ./crates/signer
24+
COPY crates/superalloy ./crates/superalloy
25+
1926
RUN cargo build --release -p blocklock-agent --example blocklock
2027

2128
# We do not need the Rust toolchain to run the binary!

bin/dsigner/examples/dsigner_grpc/Dockerfile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,33 @@
22

33
# Base image for rust
44
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
5-
RUN apt-get update && apt-get install -y protobuf-compiler
6-
5+
RUN apt-get update \
6+
&& apt-get install -y protobuf-compiler \
7+
&& rm -rf /var/lib/apt/lists/*
78
WORKDIR /app
89

910
FROM chef AS planner
1011
COPY . .
12+
# chef prepare --bin sadly doesn't support binaries of kind "example"
1113
RUN cargo chef prepare --recipe-path recipe.json
1214

1315
FROM chef AS builder
1416
COPY --from=planner /app/recipe.json recipe.json
1517

1618
# Build dependencies - this is the caching Docker layer!
19+
# --bin sadly doesn't support binaries of kind "example"
1720
RUN cargo chef cook --release --recipe-path recipe.json
1821

1922
# Build application
20-
COPY . .
23+
COPY Cargo.toml Cargo.lock ./
24+
25+
COPY bin/dsigner/ ./bin/dsigner
26+
COPY crates/network ./crates/network
27+
COPY crates/signer ./crates/signer
28+
COPY crates/superalloy ./crates/superalloy
29+
COPY crates/utils ./crates/utils
30+
COPY modules/dcipher-proto ./modules/dcipher-proto
31+
2132
RUN cargo build --release --example dsigner_grpc --all-features
2233

2334
# We do not need the Rust toolchain to run the binary!

bin/dsigner/examples/dsigner_legacy_http/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,27 @@ WORKDIR /app
88

99
FROM chef AS planner
1010
COPY . .
11+
# chef prepare --bin sadly doesn't support binaries of kind "example"
1112
RUN cargo chef prepare --recipe-path recipe.json
1213

1314
FROM chef AS builder
1415
COPY --from=planner /app/recipe.json recipe.json
1516

1617
# Build dependencies - this is the caching Docker layer!
18+
# --bin sadly doesn't support binaries of kind "example"
1719
RUN cargo chef cook --release --recipe-path recipe.json
1820

1921
# Build application
20-
COPY . .
22+
COPY Cargo.toml Cargo.lock ./
23+
24+
COPY bin/dsigner/ ./bin/dsigner
25+
COPY crates/config ./crates/config
26+
COPY crates/network ./crates/network
27+
COPY crates/signer ./crates/signer
28+
COPY crates/superalloy ./crates/superalloy
29+
COPY crates/utils ./crates/utils
30+
COPY modules/dcipher-proto ./modules/dcipher-proto
31+
2132
RUN cargo build --release --example dsigner_legacy_http --all-features
2233

2334
# We do not need the Rust toolchain to run the binary!

bin/monitoring/Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
# Image building solidity contracts
2-
# Base image for rust
1+
# Image must be built from the root
2+
33
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
4-
RUN apt-get update \
5-
&& apt-get install -y protobuf-compiler \
6-
&& rm -rf /var/lib/apt/lists/*
74
WORKDIR /app
85

96
FROM chef AS planner
107
COPY . .
11-
RUN cargo chef prepare --recipe-path recipe.json
8+
RUN cargo chef prepare --recipe-path recipe.json --bin monitoring
129

1310
FROM chef AS builder
1411
COPY --from=planner /app/recipe.json recipe.json
1512

1613
# Build dependencies - this is the caching Docker layer!
17-
RUN cargo chef cook --release --recipe-path recipe.json
14+
RUN cargo chef cook --release --recipe-path recipe.json --bin monitoring
1815

1916
# Build application
20-
COPY . .
21-
RUN cargo build --release -p monitoring
17+
COPY Cargo.toml Cargo.lock ./
18+
19+
COPY bin/monitoring/ ./bin/monitoring
20+
COPY crates/agent-utils ./crates/agent-utils
21+
COPY crates/config ./crates/config
22+
COPY crates/generated ./crates/generated
23+
COPY crates/utils ./crates/utils
24+
25+
RUN cargo build --release -p monitoring --bin monitoring
2226

2327
# We do not need the Rust toolchain to run the binary!
2428
FROM debian:bookworm-slim AS runtime

bin/onlyswaps-smoketest/Dockerfile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Image building solidity contracts
2-
# Base image for rust
1+
# Image must be built from the root
2+
33
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
44
RUN apt-get update \
55
&& apt-get install -y protobuf-compiler \
@@ -8,16 +8,25 @@ WORKDIR /app
88

99
FROM chef AS planner
1010
COPY . .
11-
RUN cargo chef prepare --recipe-path recipe.json
11+
RUN cargo chef prepare --recipe-path recipe.json --bin onlyswaps-smoketest
1212

1313
FROM chef AS builder
1414
COPY --from=planner /app/recipe.json recipe.json
1515

1616
# Build dependencies - this is the caching Docker layer!
17-
RUN cargo chef cook --release --recipe-path recipe.json
17+
RUN cargo chef cook --release --recipe-path recipe.json --bin onlyswaps-smoketest
1818

1919
# Build application
20-
COPY . .
20+
COPY Cargo.toml Cargo.lock ./
21+
22+
COPY bin/onlyswaps-smoketest/ ./bin/onlyswaps-smoketest
23+
COPY crates/agent-utils ./crates/agent-utils
24+
COPY crates/config ./crates/config
25+
COPY crates/generated ./crates/generated
26+
COPY crates/onlyswaps-client ./crates/onlyswaps-client
27+
COPY crates/superalloy ./crates/superalloy
28+
COPY crates/utils ./crates/utils
29+
2130
RUN cargo build --release -p onlyswaps-smoketest
2231

2332
# We do not need the Rust toolchain to run the binary!

bin/onlyswaps-solver/Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1+
# Image must be built from the root
2+
13
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
24
WORKDIR /app
35

46
FROM chef AS planner
57
COPY . .
6-
RUN cargo chef prepare --recipe-path recipe.json
8+
RUN cargo chef prepare --recipe-path recipe.json --bin onlyswaps-solver
79

810
FROM chef AS builder
911
COPY --from=planner /app/recipe.json recipe.json
1012

1113
# Build dependencies - this is the caching Docker layer!
12-
RUN cargo chef cook --release --recipe-path recipe.json
14+
RUN cargo chef cook --release --recipe-path recipe.json --bin onlyswaps-solver
1315

1416
# Build application
15-
COPY . .
16-
RUN cargo build --release -p onlyswaps-solver
17+
COPY Cargo.toml Cargo.lock ./
18+
19+
COPY bin/onlyswaps-solver/ ./bin/onlyswaps-solver
20+
COPY crates/agent-utils ./crates/agent-utils
21+
COPY crates/config ./crates/config
22+
COPY crates/generated ./crates/generated
23+
COPY crates/utils ./crates/utils
24+
25+
RUN cargo build --release -p onlyswaps-solver --bin onlyswaps-solver --all-features
1726

1827
# We do not need the Rust toolchain to run the binary!
1928
FROM debian:bookworm-slim AS runtime

bin/onlyswaps-state-api/Dockerfile

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Image building solidity contracts
2-
# Base image for rust
1+
# Image must be built from the root
2+
33
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
44
RUN apt-get update \
55
&& apt-get install -y protobuf-compiler \
@@ -8,17 +8,27 @@ WORKDIR /app
88

99
FROM chef AS planner
1010
COPY . .
11-
RUN cargo chef prepare --recipe-path recipe.json
11+
RUN cargo chef prepare --recipe-path recipe.json --bin onlyswaps-state-api
1212

1313
FROM chef AS builder
1414
COPY --from=planner /app/recipe.json recipe.json
1515

1616
# Build dependencies - this is the caching Docker layer!
17-
RUN cargo chef cook --release --recipe-path recipe.json
17+
RUN cargo chef cook --release --recipe-path recipe.json --bin onlyswaps-state-api
1818

1919
# Build application
20-
COPY . .
21-
RUN cargo build --release -p onlyswaps-state-api
20+
COPY Cargo.toml Cargo.lock ./
21+
22+
COPY bin/onlyswaps-state-api/ ./bin/onlyswaps-state-api
23+
COPY crates/agent-utils ./crates/agent-utils
24+
COPY crates/config ./crates/config
25+
COPY crates/generated ./crates/generated
26+
COPY crates/omnievent ./crates/omnievent
27+
COPY crates/superalloy ./crates/superalloy
28+
COPY crates/utils ./crates/utils
29+
COPY modules/dcipher-proto ./modules/dcipher-proto
30+
31+
RUN cargo build --release -p onlyswaps-state-api --bin onlyswaps-state-api
2232

2333
# We do not need the Rust toolchain to run the binary!
2434
FROM debian:bookworm-slim AS runtime

0 commit comments

Comments
 (0)