Skip to content

Commit b3352e3

Browse files
authored
chore(test-suite): speed up local build/test iterations (#1736)
* chore(test-suite): speed up local builds * chore(test-suite): split local build cache by service * feat(build): add local cargo profile for faster local builds - Add 'local' profile to coprocessor and kms-connector Cargo.toml (opt-level=1, no LTO, 16 codegen-units for faster compilation) - Update all Dockerfiles to accept CARGO_PROFILE build arg - Update compose files to pass CARGO_PROFILE and RUST_IMAGE_VERSION - Add .dockerignore to reduce build context size - Fix deploy script bash 3.2 compatibility (macOS) - Add DOCKER_BUILD_PROVENANCE=false to disable attestations - Add kms-connector Cargo patch for monorepo path resolution - Add kms-connector-db-migration to local cache services list * perf(kms-connector): add target cache and cargo fetch for faster builds - Add BuildKit cache mount for target/ directory to enable incremental builds - Add cargo fetch step to cache dependency resolution separately - Copy binaries to /tmp before prod stage (cache mounts don't persist) * feat(coprocessor): add BuildKit target cache mount for incremental builds Add target directory cache mount to all coprocessor Dockerfiles to enable incremental Rust compilation caching, consistent with kms-connector pattern. Cache mounts are not committed to image layers, so binaries must be copied to /tmp before the final COPY --from stage can access them. * chore: remove superfluous CARGO_PROFILE in prod stage * chore: rename --no-compile to --no-hardhat-compile * fix(test-suite): use repo root as build context for host-sc The host-contracts Dockerfile expects repo root as build context (COPY host-contracts/... paths), but compose file incorrectly specified host-contracts/ directory as context since initial creation in commit 9a92155. This was never caught because CI uses repo root context and local deploys without --build pull pre-built images.
1 parent 93c2ebc commit b3352e3

28 files changed

+308
-95
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ logs/
3737

3838
# Build output & temporary directories (generic)
3939
.cache/
40+
.buildx-cache/
4041
temp/
4142
tmp/
4243

@@ -85,4 +86,4 @@ mochawesome-report/
8586
# Rust specific
8687
#-------------------------------------------------------------------------------
8788
# Build artifacts directory
88-
target/
89+
target/

coprocessor/fhevm-engine/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,9 @@ overflow-checks = false
101101
[profile.release]
102102
opt-level = 3
103103
lto = "fat"
104+
105+
[profile.local]
106+
inherits = "release"
107+
opt-level = 1
108+
lto = false
109+
codegen-units = 16

coprocessor/fhevm-engine/gw-listener/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ RUN npm install && \
1515
# Stage 1: Build GW Listener
1616
FROM ghcr.io/zama-ai/fhevm/gci/rust-glibc:1.91.0 AS builder
1717

18+
ARG CARGO_PROFILE=release
19+
1820
USER root
1921

2022
WORKDIR /app
@@ -30,16 +32,21 @@ COPY .git/HEAD ./coprocessor/fhevm-engine/BUILD_ID
3032
WORKDIR /app/coprocessor/fhevm-engine
3133

3234
# Build gw_listener binary
35+
# NOTE: We use a cache mount for the target directory to enable incremental compilation.
36+
# Because cache mounts are NOT committed to the image layer, we must copy the binary
37+
# to a non-mounted path (/tmp) during the same RUN instruction for COPY --from to work.
3338
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
39+
--mount=type=cache,target=/app/coprocessor/fhevm-engine/target,sharing=locked \
3440
cargo fetch && \
35-
SQLX_OFFLINE=true BUILD_ID=$(cat BUILD_ID) cargo build --release -p gw-listener
41+
SQLX_OFFLINE=true BUILD_ID=$(cat BUILD_ID) cargo build --profile=${CARGO_PROFILE} -p gw-listener && \
42+
cp target/${CARGO_PROFILE}/gw_listener /tmp/gw_listener
3643

3744
# Stage 2: Runtime image
3845
FROM cgr.dev/zama.ai/glibc-dynamic:15.2.0 AS prod
3946

4047
COPY --from=builder /etc/group /etc/group
4148
COPY --from=builder /etc/passwd /etc/passwd
42-
COPY --from=builder --chown=fhevm:fhevm /app/coprocessor/fhevm-engine/target/release/gw_listener /usr/local/bin/gw_listener
49+
COPY --from=builder --chown=fhevm:fhevm /tmp/gw_listener /usr/local/bin/gw_listener
4350

4451
USER fhevm:fhevm
4552

coprocessor/fhevm-engine/host-listener/Dockerfile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ RUN npm install && HARDHAT_NETWORK=hardhat npm run deploy:emptyProxies && npx ha
1515
# Stage 1: Build Host Listener
1616
FROM ghcr.io/zama-ai/fhevm/gci/rust-glibc:1.91.0 AS builder
1717

18+
ARG CARGO_PROFILE=release
19+
1820
USER root
1921

2022
WORKDIR /app
@@ -29,17 +31,23 @@ COPY .git/HEAD ./coprocessor/fhevm-engine/BUILD_ID
2931
WORKDIR /app/coprocessor/fhevm-engine
3032

3133
# Build host_listener binary
34+
# NOTE: We use a cache mount for the target directory to enable incremental compilation.
35+
# Because cache mounts are NOT committed to the image layer, we must copy the binary
36+
# to a non-mounted path (/tmp) during the same RUN instruction for COPY --from to work.
3237
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
38+
--mount=type=cache,target=/app/coprocessor/fhevm-engine/target,sharing=locked \
3339
cargo fetch && \
34-
SQLX_OFFLINE=true BUILD_ID=$(cat BUILD_ID) cargo build --release -p host-listener
40+
SQLX_OFFLINE=true BUILD_ID=$(cat BUILD_ID) cargo build --profile=${CARGO_PROFILE} -p host-listener && \
41+
cp target/${CARGO_PROFILE}/host_listener /tmp/host_listener && \
42+
cp target/${CARGO_PROFILE}/host_listener_poller /tmp/host_listener_poller
3543

3644
# Stage 2: Runtime image
3745
FROM cgr.dev/zama.ai/glibc-dynamic:15.2.0 AS prod
3846

3947
COPY --from=builder /etc/group /etc/group
4048
COPY --from=builder /etc/passwd /etc/passwd
41-
COPY --from=builder --chown=fhevm:fhevm /app/coprocessor/fhevm-engine/target/release/host_listener /usr/local/bin/host_listener
42-
COPY --from=builder --chown=fhevm:fhevm /app/coprocessor/fhevm-engine/target/release/host_listener_poller /usr/local/bin/host_listener_poller
49+
COPY --from=builder --chown=fhevm:fhevm /tmp/host_listener /usr/local/bin/host_listener
50+
COPY --from=builder --chown=fhevm:fhevm /tmp/host_listener_poller /usr/local/bin/host_listener_poller
4351

4452
USER fhevm:fhevm
4553

coprocessor/fhevm-engine/sns-worker/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Stage 1: Build SNS Worker
22
FROM ghcr.io/zama-ai/fhevm/gci/rust-glibc:1.91.0 AS builder
33

4+
ARG CARGO_PROFILE=release
5+
46
USER root
57

68
WORKDIR /app
@@ -12,16 +14,21 @@ COPY gateway-contracts/rust_bindings ./gateway-contracts/rust_bindings
1214
WORKDIR /app/coprocessor/fhevm-engine
1315

1416
# Build sns_executor binary
17+
# NOTE: We use a cache mount for the target directory to enable incremental compilation.
18+
# Because cache mounts are NOT committed to the image layer, we must copy the binary
19+
# to a non-mounted path (/tmp) during the same RUN instruction for COPY --from to work.
1520
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
21+
--mount=type=cache,target=/app/coprocessor/fhevm-engine/target,sharing=locked \
1622
cargo fetch && \
17-
SQLX_OFFLINE=true cargo build --release -p sns-worker
23+
SQLX_OFFLINE=true cargo build --profile=${CARGO_PROFILE} -p sns-worker && \
24+
cp target/${CARGO_PROFILE}/sns_worker /tmp/sns_worker
1825

1926
# Stage 2: Runtime image
2027
FROM cgr.dev/zama.ai/glibc-dynamic:15.2.0 AS prod
2128

2229
COPY --from=builder /etc/group /etc/group
2330
COPY --from=builder /etc/passwd /etc/passwd
24-
COPY --from=builder --chown=fhevm:fhevm /app/coprocessor/fhevm-engine/target/release/sns_worker /usr/local/bin/sns_worker
31+
COPY --from=builder --chown=fhevm:fhevm /tmp/sns_worker /usr/local/bin/sns_worker
2532

2633
USER fhevm:fhevm
2734

coprocessor/fhevm-engine/stress-test-generator/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ RUN cp .env.example .env \
2121
# Stage 1: Build Stress-Tool
2222
FROM ghcr.io/zama-ai/fhevm/gci/rust-glibc:1.91.0 AS builder
2323

24+
ARG CARGO_PROFILE=release
25+
2426
USER root
2527

2628
WORKDIR /app
@@ -34,16 +36,21 @@ COPY --from=contract_builder /app/host-contracts/artifacts/contracts /app/host-c
3436
WORKDIR /app/coprocessor/fhevm-engine
3537

3638
# Build stress_generator binary
39+
# NOTE: We use a cache mount for the target directory to enable incremental compilation.
40+
# Because cache mounts are NOT committed to the image layer, we must copy the binary
41+
# to a non-mounted path (/tmp) during the same RUN instruction for COPY --from to work.
3742
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
43+
--mount=type=cache,target=/app/coprocessor/fhevm-engine/target,sharing=locked \
3844
cargo fetch && \
39-
SQLX_OFFLINE=true cargo build --release -p stress-test-generator
45+
SQLX_OFFLINE=true cargo build --profile=${CARGO_PROFILE} -p stress-test-generator && \
46+
cp target/${CARGO_PROFILE}/stress_generator /tmp/stress_generator
4047

4148
# Stage 2: Runtime image
4249
FROM cgr.dev/chainguard/glibc-dynamic:latest AS prod
4350

4451
COPY --from=builder /etc/group /etc/group
4552
COPY --from=builder /etc/passwd /etc/passwd
46-
COPY --from=builder --chown=fhevm:fhevm /app/coprocessor/fhevm-engine/target/release/stress_generator /usr/local/bin/stress_generator
53+
COPY --from=builder --chown=fhevm:fhevm /tmp/stress_generator /usr/local/bin/stress_generator
4754
USER fhevm:fhevm
4855

4956
CMD ["/usr/local/bin/stress_generator"]

coprocessor/fhevm-engine/tfhe-worker/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Stage 1: Build TFHE Worker
22
FROM ghcr.io/zama-ai/fhevm/gci/rust-glibc:1.91.0 AS builder
33

4+
ARG CARGO_PROFILE=release
5+
46
USER root
57

68
WORKDIR /app
@@ -12,16 +14,21 @@ COPY gateway-contracts/rust_bindings ./gateway-contracts/rust_bindings
1214
WORKDIR /app/coprocessor/fhevm-engine
1315

1416
# Build tfhe_worker binary
17+
# NOTE: We use a cache mount for the target directory to enable incremental compilation.
18+
# Because cache mounts are NOT committed to the image layer, we must copy the binary
19+
# to a non-mounted path (/tmp) during the same RUN instruction for COPY --from to work.
1520
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
21+
--mount=type=cache,target=/app/coprocessor/fhevm-engine/target,sharing=locked \
1622
cargo fetch && \
17-
SQLX_OFFLINE=true cargo build --release -p tfhe-worker
23+
SQLX_OFFLINE=true cargo build --profile=${CARGO_PROFILE} -p tfhe-worker && \
24+
cp target/${CARGO_PROFILE}/tfhe_worker /tmp/tfhe_worker
1825

1926
# Stage 2: Runtime image
2027
FROM cgr.dev/zama.ai/glibc-dynamic:15.2.0 AS prod
2128

2229
COPY --from=builder /etc/group /etc/group
2330
COPY --from=builder /etc/passwd /etc/passwd
24-
COPY --from=builder --chown=fhevm:fhevm /app/coprocessor/fhevm-engine/target/release/tfhe_worker /usr/local/bin/tfhe_worker
31+
COPY --from=builder --chown=fhevm:fhevm /tmp/tfhe_worker /usr/local/bin/tfhe_worker
2532

2633
USER fhevm:fhevm
2734

coprocessor/fhevm-engine/transaction-sender/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Stage 1: Build Transaction Sender
22
FROM ghcr.io/zama-ai/fhevm/gci/rust-glibc:1.91.0 AS builder
33

4+
ARG CARGO_PROFILE=release
5+
46
USER root
57

68
WORKDIR /app
@@ -12,16 +14,21 @@ COPY gateway-contracts/rust_bindings ./gateway-contracts/rust_bindings
1214
WORKDIR /app/coprocessor/fhevm-engine
1315

1416
# Build transaction_sender binary
17+
# NOTE: We use a cache mount for the target directory to enable incremental compilation.
18+
# Because cache mounts are NOT committed to the image layer, we must copy the binary
19+
# to a non-mounted path (/tmp) during the same RUN instruction for COPY --from to work.
1520
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
21+
--mount=type=cache,target=/app/coprocessor/fhevm-engine/target,sharing=locked \
1622
cargo fetch && \
17-
SQLX_OFFLINE=true cargo build --release -p transaction-sender
23+
SQLX_OFFLINE=true cargo build --profile=${CARGO_PROFILE} -p transaction-sender && \
24+
cp target/${CARGO_PROFILE}/transaction_sender /tmp/transaction_sender
1825

1926
# Stage 2: Runtime image
2027
FROM cgr.dev/zama.ai/glibc-dynamic:15.2.0 AS prod
2128

2229
COPY --from=builder /etc/group /etc/group
2330
COPY --from=builder /etc/passwd /etc/passwd
24-
COPY --from=builder --chown=fhevm:fhevm /app/coprocessor/fhevm-engine/target/release/transaction_sender /usr/local/bin/transaction_sender
31+
COPY --from=builder --chown=fhevm:fhevm /tmp/transaction_sender /usr/local/bin/transaction_sender
2532

2633
USER fhevm:fhevm
2734

coprocessor/fhevm-engine/zkproof-worker/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Stage 1: Build ZK Proof Worker
22
FROM ghcr.io/zama-ai/fhevm/gci/rust-glibc:1.91.0 AS builder
33

4+
ARG CARGO_PROFILE=release
5+
46
USER root
57

68
WORKDIR /app
@@ -12,16 +14,21 @@ COPY gateway-contracts/rust_bindings ./gateway-contracts/rust_bindings
1214
WORKDIR /app/coprocessor/fhevm-engine
1315

1416
# Build zkproof_worker binary
17+
# NOTE: We use a cache mount for the target directory to enable incremental compilation.
18+
# Because cache mounts are NOT committed to the image layer, we must copy the binary
19+
# to a non-mounted path (/tmp) during the same RUN instruction for COPY --from to work.
1520
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
21+
--mount=type=cache,target=/app/coprocessor/fhevm-engine/target,sharing=locked \
1622
cargo fetch && \
17-
SQLX_OFFLINE=true cargo build --release -p zkproof-worker
23+
SQLX_OFFLINE=true cargo build --profile=${CARGO_PROFILE} -p zkproof-worker && \
24+
cp target/${CARGO_PROFILE}/zkproof_worker /tmp/zkproof_worker
1825

1926
# Stage 2: Runtime image
2027
FROM cgr.dev/zama.ai/glibc-dynamic:15.2.0 AS prod
2128

2229
COPY --from=builder /etc/group /etc/group
2330
COPY --from=builder /etc/passwd /etc/passwd
24-
COPY --from=builder --chown=fhevm:fhevm /app/coprocessor/fhevm-engine/target/release/zkproof_worker /usr/local/bin/zkproof_worker
31+
COPY --from=builder --chown=fhevm:fhevm /tmp/zkproof_worker /usr/local/bin/zkproof_worker
2532

2633
USER fhevm:fhevm
2734

kms-connector/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,9 @@ serial_test = "3.2.0"
102102
testcontainers = "=0.24.0"
103103
toml = { version = "=0.9.8", default-features = true }
104104
tracing-test = { version = "=0.2.5", default-features = false }
105+
106+
[profile.local]
107+
inherits = "release"
108+
opt-level = 1
109+
lto = false
110+
codegen-units = 16

0 commit comments

Comments
 (0)