Skip to content

Commit 727e826

Browse files
authored
BM-244: Docker compose builds in CI (github#68)
This PR: * Runs docker compose builds in CI to validate our docker builds work before merging * Passes through the sccache s3 caching creds into the docker build context to make sure docker builds are not slow in CI * Only triggers docker builds if compose / dockerfiles change to improve CI perf
1 parent 1f7731c commit 727e826

File tree

11 files changed

+120
-61
lines changed

11 files changed

+120
-61
lines changed

.github/actions/bininstall-risc0/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ runs:
2020
- name: install rust
2121
uses: risc0/risc0/.github/actions/[email protected]
2222

23-
- uses: risc0/cargo-install@v3
23+
- uses: baptiste0928/cargo-install@904927dbe77864e0f2281519fe9d5bd097a220b3
2424
with:
2525
crate: cargo-binstall
2626
version: '=1.10.8'

.github/workflows/main.yml

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ concurrency:
1212
permissions:
1313
id-token: write
1414
contents: read
15+
pull-requests: read
1516

1617
env:
1718
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -58,7 +59,7 @@ jobs:
5859
python-version: "3.10"
5960

6061
- name: install foundry
61-
uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
62+
uses: foundry-rs/foundry-toolchain@v1
6263

6364
- name: install rust
6465
uses: risc0/risc0/.github/actions/[email protected]
@@ -75,7 +76,7 @@ jobs:
7576
toolchain-version: 'r0.1.79.0-2'
7677

7778
- name: install cargo-sort
78-
uses: risc0/cargo-install@v3
79+
uses: baptiste0928/cargo-install@904927dbe77864e0f2281519fe9d5bd097a220b3
7980
with:
8081
crate: cargo-sort
8182
version: "=1.0.9"
@@ -98,7 +99,7 @@ jobs:
9899
run: cargo check
99100

100101
- name: Install sqlx-cli
101-
uses: risc0/cargo-install@v3
102+
uses: baptiste0928/cargo-install@904927dbe77864e0f2281519fe9d5bd097a220b3
102103
with:
103104
crate: sqlx-cli
104105
version: '=0.8.2'
@@ -133,7 +134,7 @@ jobs:
133134
restore-keys: cache-lychee-
134135

135136
- name: install cargo-binstall
136-
uses: risc0/cargo-install@v3
137+
uses: baptiste0928/cargo-install@904927dbe77864e0f2281519fe9d5bd097a220b3
137138
with:
138139
crate: cargo-binstall
139140
version: '=1.10.8'
@@ -159,7 +160,7 @@ jobs:
159160
- uses: actions/checkout@v4
160161

161162
- name: install cargo-binstall
162-
uses: risc0/cargo-install@v3
163+
uses: baptiste0928/cargo-install@904927dbe77864e0f2281519fe9d5bd097a220b3
163164
with:
164165
crate: cargo-binstall
165166
version: '=1.10.8'
@@ -178,7 +179,7 @@ jobs:
178179
submodules: recursive
179180

180181
- name: install foundry
181-
uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
182+
uses: foundry-rs/foundry-toolchain@v1
182183

183184
- name: forge fmt
184185
run: forge fmt --check
@@ -203,7 +204,7 @@ jobs:
203204
submodules: recursive
204205

205206
- name: install foundry
206-
uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
207+
uses: foundry-rs/foundry-toolchain@v1
207208

208209
- name: install rust
209210
uses: risc0/risc0/.github/actions/[email protected]
@@ -220,7 +221,7 @@ jobs:
220221
toolchain-version: 'r0.1.79.0-2'
221222

222223
- name: install cargo-sort
223-
uses: risc0/cargo-install@v3
224+
uses: baptiste0928/cargo-install@904927dbe77864e0f2281519fe9d5bd097a220b3
224225
with:
225226
crate: cargo-sort
226227
version: "=1.0.9"
@@ -265,8 +266,27 @@ jobs:
265266
- name: sccache stats
266267
run: sccache --show-stats
267268

268-
docker:
269+
files-changed:
269270
runs-on: ubuntu-latest
271+
outputs:
272+
docker: ${{ steps.changes.outputs.docker }}
273+
steps:
274+
- name: checkout code
275+
uses: actions/checkout@v4
276+
277+
- uses: dorny/[email protected]
278+
id: changes
279+
with:
280+
filters: |
281+
src:
282+
- 'dockerfiles/**'
283+
- 'compose.yml'
284+
- '.env-compose'
285+
286+
docker:
287+
runs-on: [self-hosted, Linux, X64, prod, cpu]
288+
needs: files-changed
289+
if: needs.files-changed.outputs.docker == 'true'
270290
steps:
271291
- name: checkout code
272292
uses: actions/checkout@v4
@@ -275,3 +295,24 @@ jobs:
275295

276296
- name: docker-compose lint
277297
run: docker compose --profile broker --env-file ./.env-compose config
298+
299+
- name: Fetch CI AWS Creds
300+
id: aws-creds
301+
uses: aws-actions/configure-aws-credentials@v4
302+
with:
303+
aws-region: 'us-west-2'
304+
role-to-assume: 'arn:aws:iam::083632199359:role/gha_oidc_risc0_cache_shared_access'
305+
output-credentials: true
306+
307+
- name: create ci creds file
308+
run: |
309+
echo "[default]" > ./dockerfiles/ci-cache-creds.txt
310+
echo "aws_access_key_id=${{ steps.aws-creds.outputs.aws-access-key-id }}" >> ./dockerfiles/ci-cache-creds.txt && \
311+
echo "aws_secret_access_key=${{ steps.aws-creds.outputs.aws-secret-access-key }}" >> ./dockerfiles/ci-cache-creds.txt && \
312+
echo "aws_session_token=${{ steps.aws-creds.outputs.aws-session-token }}" >> ./dockerfiles/ci-cache-creds.txt
313+
314+
- name: Setup docker builder
315+
run: docker buildx create --driver docker-container --use
316+
317+
- name: docker compose build
318+
run: docker compose --profile broker --env-file ./.env-compose -f compose.yml -f ./dockerfiles/compose.ci.yml build

crates/boundless-market/src/contracts/mod.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ use url::Url;
2727

2828
use risc0_zkvm::sha::Digest;
2929

30+
#[cfg(not(target_os = "zkvm"))]
31+
pub use risc0_ethereum_contracts::encode_seal;
32+
3033
#[cfg(not(target_os = "zkvm"))]
3134
const TXN_CONFIRM_TIMEOUT: Duration = Duration::from_secs(45);
3235

@@ -412,33 +415,6 @@ pub fn eip712_domain(addr: Address, chain_id: u64) -> EIP721DomainSaltless {
412415
}
413416
}
414417

415-
// TODO: when upgrading to risc0-ethereum-contracts 1.1.0 this function will be removed.
416-
pub fn encode_seal(receipt: &risc0_zkvm::Receipt) -> anyhow::Result<Vec<u8>> {
417-
use risc0_zkvm::sha::Digestible;
418-
419-
let seal = match receipt.inner.clone() {
420-
risc0_zkvm::InnerReceipt::Fake(receipt) => {
421-
let seal = receipt.claim.digest().as_bytes().to_vec();
422-
let selector = &[0u8; 4];
423-
// Create a new vector with the capacity to hold both selector and seal
424-
let mut selector_seal = Vec::with_capacity(selector.len() + seal.len());
425-
selector_seal.extend_from_slice(selector);
426-
selector_seal.extend_from_slice(&seal);
427-
selector_seal
428-
}
429-
risc0_zkvm::InnerReceipt::Groth16(receipt) => {
430-
let selector = &receipt.verifier_parameters.as_bytes()[..4];
431-
// Create a new vector with the capacity to hold both selector and seal
432-
let mut selector_seal = Vec::with_capacity(selector.len() + receipt.seal.len());
433-
selector_seal.extend_from_slice(selector);
434-
selector_seal.extend_from_slice(receipt.seal.as_ref());
435-
selector_seal
436-
}
437-
_ => anyhow::bail!("Unsupported receipt type"),
438-
};
439-
Ok(seal)
440-
}
441-
442418
#[cfg(feature = "test-utils")]
443419
pub mod test_utils {
444420
use aggregation_set::SET_BUILDER_GUEST_ID;

crates/boundless-market/src/contracts/proof_market.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,8 @@ mod tests {
623623

624624
use super::ProofMarketService;
625625
use crate::contracts::{
626-
encode_seal, test_utils::TestCtx, AssessorJournal, Fulfillment, IProofMarket, Input,
627-
InputType, Offer, Predicate, PredicateType, ProofStatus, ProvingRequest, Requirements,
626+
test_utils::TestCtx, AssessorJournal, Fulfillment, IProofMarket, Input, InputType, Offer,
627+
Predicate, PredicateType, ProofStatus, ProvingRequest, Requirements,
628628
};
629629
use aggregation_set::{merkle_root, GuestOutput, SetInclusionReceipt, SET_BUILDER_GUEST_ID};
630630
use alloy::{
@@ -639,6 +639,7 @@ mod tests {
639639
};
640640
use guest_assessor::ASSESSOR_GUEST_ID;
641641
use guest_util::ECHO_ID;
642+
use risc0_ethereum_contracts::encode_seal;
642643
use risc0_zkvm::{
643644
sha::{Digest, Digestible},
644645
FakeReceipt, InnerReceipt, Journal, MaybePruned, Receipt, ReceiptClaim,

crates/broker/src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ impl ConfigWatcher {
231231
watcher
232232
.watch(&config_path_copy, notify::RecursiveMode::NonRecursive)
233233
.context("Failed to start watcher")?;
234-
235234
startup_notification_copy.notify_one();
236235

237236
while let Some(event) = rx.recv().await {

dockerfiles/agent.dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ENV RUSTUP_HOME=/usr/local/rustup \
1818
# Install rust and a target rust version (should match rust-toolchain.toml for best speed)
1919
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
2020
RUN chmod -R a+w $RUSTUP_HOME $CARGO_HOME
21-
RUN rustup install 1.76
21+
RUN rustup install 1.79
2222

2323
FROM rust-builder AS builder
2424

@@ -46,16 +46,14 @@ SHELL ["/bin/bash", "-c"]
4646
# Prevent sccache collision in compose-builds
4747
ENV SCCACHE_SERVER_PORT=4226
4848

49-
# This downloads and setups the rust-toolchain so docker can cache the layer
50-
RUN cargo
51-
52-
5349
RUN \
50+
--mount=type=secret,id=ci_cache_creds,target=/root/.aws/credentials \
5451
--mount=type=cache,target=/root/.cache/sccache/,id=bndlss_agent_sc \
5552
source ./sccache-config.sh && \
5653
ls /root/.cache/sccache/ && \
5754
cargo build --release -F cuda -p workflow --bin agent && \
58-
cp /src/target/release/agent /src/agent
55+
cp /src/target/release/agent /src/agent && \
56+
sccache --show-stats
5957

6058
FROM risczero/risc0-groth16-prover:v2024-05-17.1 AS binaries
6159

dockerfiles/broker.dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ RUN curl -L https://foundry.paradigm.xyz | bash && \
1515
# Prevent sccache collision in compose-builds
1616
ENV SCCACHE_SERVER_PORT=4227
1717

18-
RUN cargo
19-
2018
RUN \
19+
--mount=type=secret,id=ci_cache_creds,target=/root/.aws/credentials \
2120
--mount=type=cache,target=/root/.cache/sccache/,id=bndlss_broker_sc \
2221
source ./sccache-config.sh && \
2322
ls /root/.cache/sccache/ && \
2423
cargo install --version 1.6.9 cargo-binstall && \
2524
cargo binstall -y --force cargo-risczero --version 1.1 && \
26-
cargo risczero install
25+
cargo risczero install && \
26+
sccache --show-stats
2727

2828
FROM init AS builder
2929

@@ -41,17 +41,17 @@ COPY foundry.toml .
4141
ENV PATH="$PATH:/root/.foundry/bin"
4242
RUN forge build
4343

44-
RUN cargo
45-
4644
# Prevent sccache collision in compose-builds
4745
ENV SCCACHE_SERVER_PORT=4227
4846

4947
RUN \
48+
--mount=type=secret,id=ci_cache_creds,target=/root/.aws/credentials \
5049
--mount=type=cache,target=/root/.cache/sccache/,id=bndlss_broker_sc \
5150
source /sccache-config.sh && \
5251
ls /root/.cache/sccache/ && \
5352
cargo build --release --bin broker && \
54-
cp /src/target/release/broker /src/broker
53+
cp /src/target/release/broker /src/broker && \
54+
sccache --show-stats
5555

5656
FROM rust:1.79.0-bookworm AS runtime
5757

dockerfiles/ci-cache-creds.txt

Whitespace-only changes.

dockerfiles/compose.ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
exec_agent:
3+
build:
4+
secrets:
5+
- ci_cache_creds
6+
cache_to:
7+
- type=s3,name=agent-cache,manifests_prefix=shared/boundless/docker/manifests/,blobs_prefix=shared/boundless/docker/blobs/,region=us-west-2,bucket=risc0-ci-cache,mode=max
8+
cache_from:
9+
- type=s3,name=agent-cache,manifests_prefix=shared/boundless/docker/manifests/,blobs_prefix=shared/boundless/docker/blobs/,region=us-west-2,bucket=risc0-ci-cache
10+
11+
rest_api:
12+
build:
13+
secrets:
14+
- ci_cache_creds
15+
cache_to:
16+
- type=s3,name=rest-cache,manifests_prefix=shared/boundless/docker/manifests/,blobs_prefix=shared/boundless/docker/blobs/,region=us-west-2,bucket=risc0-ci-cache,mode=max
17+
cache_from:
18+
- type=s3,name=rest-cache,manifests_prefix=shared/boundless/docker/manifests/,blobs_prefix=shared/boundless/docker/blobs/,region=us-west-2,bucket=risc0-ci-cache
19+
20+
broker:
21+
build:
22+
secrets:
23+
- ci_cache_creds
24+
cache_to:
25+
- type=s3,name=broker-cache,manifests_prefix=shared/boundless/docker/manifests/,blobs_prefix=shared/boundless/docker/blobs/,region=us-west-2,bucket=risc0-ci-cache,mode=max
26+
cache_from:
27+
- type=s3,name=broker-cache,manifests_prefix=shared/boundless/docker/manifests/,blobs_prefix=shared/boundless/docker/blobs/,region=us-west-2,bucket=risc0-ci-cache
28+
29+
secrets:
30+
# Optional s3 credentials file, used in risc0 CI for sccache'ing inside docker builds.
31+
# unused in local builds, see sccache-config.sh for details.
32+
ci_cache_creds:
33+
file: ./dockerfiles/ci-cache-creds.txt

dockerfiles/rest_api.dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ SHELL ["/bin/bash", "-c"]
1919
# Prevent sccache collision in compose-builds
2020
ENV SCCACHE_SERVER_PORT=4228
2121

22-
RUN cargo
23-
2422
RUN \
23+
--mount=type=secret,id=ci_cache_creds,target=/root/.aws/credentials \
2524
--mount=type=cache,target=/root/.cache/sccache/,id=bndlss_api_sccache \
2625
source ./sccache-config.sh && \
2726
cargo build --release -p api --bin rest_api && \
28-
cp /src/target/release/rest_api /src/rest_api
29-
27+
cp /src/target/release/rest_api /src/rest_api && \
28+
sccache --show-stats
3029

3130
FROM rust:1.79.0-bookworm AS runtime
3231

0 commit comments

Comments
 (0)