feat: add docker image to build binaries used in tests

This commit is contained in:
adrian
2025-09-05 08:19:49 +02:00
committed by Adrian Benavides
parent fc38403d28
commit 24504d0f94
7 changed files with 106 additions and 6 deletions

View File

@@ -0,0 +1,3 @@
*/target/
**/target/
**/src/

View File

@@ -14,5 +14,20 @@ services:
shm_size: "1gb" shm_size: "1gb"
volumes: volumes:
- postgres_data:/var/lib/postgresql/data - postgres_data:/var/lib/postgresql/data
test-runner:
build:
context: .
dockerfile: run.Dockerfile
depends_on:
- db
environment:
RUST_LOG: "info"
DATABASE_URL: postgres://postgres:mypassword@db:5432/tycho_indexer_0
RPC_URL: "${RPC_URL}"
SUBSTREAMS_API_TOKEN: "${SUBSTREAMS_API_TOKEN}"
AUTH_API_KEY: "${AUTH_API_KEY}"
entrypoint: ["/entrypoint.sh", "${PROTOCOLS}"]
volumes: volumes:
postgres_data: postgres_data:

View File

@@ -0,0 +1,12 @@
#!/bin/bash
set -e
if [ "$#" -lt 1 ]; then
echo "Usage: $0 test1 [test2 ...]"
exit 1
fi
for test in "$@"; do
echo "Running test: /app/substreams/$test"
tycho-protocol-sdk --package-path "/app/substreams/$test" --db-url "$DATABASE_URL"
done

View File

@@ -0,0 +1,53 @@
# Stage 1: Build tycho-indexer
FROM rust:1.89-bookworm AS tycho-indexer-builder
WORKDIR /build
RUN apt-get update && apt-get install -y git
RUN git clone --depth 1 --branch "0.82.0" https://github.com/propeller-heads/tycho-indexer.git
WORKDIR /build/tycho-indexer
RUN cargo build --release --bin tycho-indexer
# Stage 2: Build protocol-testing and substreams
FROM rust:1.89-bookworm AS protocol-sdk-builder
WORKDIR /build
RUN apt-get update && apt-get install -y git
RUN git clone --depth 1 --branch "testing-sdk/ab/ENG-4985-test-with-docker" https://github.com/propeller-heads/tycho-protocol-sdk.git
WORKDIR /build/tycho-protocol-sdk/protocol-testing
RUN cargo build --release
WORKDIR /build/tycho-protocol-sdk/substreams
RUN cargo build --target wasm32-unknown-unknown --release
# Stage 3: Install substreams CLI
FROM debian:bookworm AS substreams-cli-builder
WORKDIR /build
RUN apt-get update && apt-get install -y curl
# Download and install Substreams CLI
RUN curl -L https://github.com/streamingfast/substreams/releases/download/v1.16.4/substreams_linux_arm64.tar.gz \
| tar -zxf -
# Stage 4: Final image
FROM debian:bookworm
WORKDIR /app
RUN apt-get update && apt-get install -y ca-certificates libssl-dev libpq-dev
# Copy binaries from previous stages
COPY --from=tycho-indexer-builder /build/tycho-indexer/target/release/tycho-indexer /usr/local/bin/tycho-indexer
COPY --from=protocol-sdk-builder /build/tycho-protocol-sdk/protocol-testing/target/release/protocol-testing /usr/local/bin/tycho-protocol-sdk
COPY --from=protocol-sdk-builder /build/tycho-protocol-sdk/substreams /app/substreams
COPY --from=protocol-sdk-builder /build/tycho-protocol-sdk/proto /app/proto
COPY --from=substreams-cli-builder /build/substreams /usr/local/bin/substreams
# Entrypoint script to run tests
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -6,7 +6,10 @@ mod tycho_rpc;
mod tycho_runner; mod tycho_runner;
mod utils; mod utils;
use std::path::{Path, PathBuf};
use clap::Parser; use clap::Parser;
use miette::miette;
use tracing_subscriber::EnvFilter; use tracing_subscriber::EnvFilter;
use crate::test_runner::TestRunner; use crate::test_runner::TestRunner;
@@ -15,8 +18,12 @@ use crate::test_runner::TestRunner;
#[command(version, about = "Run indexer within a specified range of blocks")] #[command(version, about = "Run indexer within a specified range of blocks")]
struct Args { struct Args {
/// Name of the package to test /// Name of the package to test
#[arg(long)] #[arg(long, required_unless_present = "package_path", conflicts_with = "package_path")]
package: String, package: Option<String>,
/// Path to the package to test
#[arg(long, required_unless_present = "package", conflicts_with = "package")]
package_path: Option<String>,
/// Enable tycho logs /// Enable tycho logs
#[arg(long, default_value_t = true)] #[arg(long, default_value_t = true)]
@@ -31,6 +38,16 @@ struct Args {
vm_traces: bool, vm_traces: bool,
} }
impl Args {
fn package_path(&self) -> miette::Result<PathBuf> {
match (self.package_path.as_ref(), self.package.as_ref()) {
(Some(path), _) => Ok(Path::new(path).to_path_buf()),
(_, Some(package)) => Ok(Path::new("../substreams").join(package)),
_ => Err(miette!("Either package or package_path must be provided")),
}
}
}
fn main() -> miette::Result<()> { fn main() -> miette::Result<()> {
tracing_subscriber::fmt() tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env()) .with_env_filter(EnvFilter::from_default_env())
@@ -39,7 +56,8 @@ fn main() -> miette::Result<()> {
let args = Args::parse(); let args = Args::parse();
let test_runner = TestRunner::new(args.package, args.tycho_logs, args.db_url, args.vm_traces); let test_runner =
TestRunner::new(args.package_path()?, args.tycho_logs, args.db_url, args.vm_traces);
test_runner.run_tests() test_runner.run_tests()
} }

View File

@@ -46,8 +46,7 @@ pub struct TestRunner {
} }
impl TestRunner { impl TestRunner {
pub fn new(package: String, tycho_logs: bool, db_url: String, vm_traces: bool) -> Self { pub fn new(substreams_path: PathBuf, tycho_logs: bool, db_url: String, vm_traces: bool) -> Self {
let substreams_path = PathBuf::from("../substreams").join(&package);
let repo_root = env::current_dir().expect("Failed to get current directory"); let repo_root = env::current_dir().expect("Failed to get current directory");
let evm_path = repo_root.join("../evm"); let evm_path = repo_root.join("../evm");
let adapter_contract_builder = let adapter_contract_builder =

View File

@@ -1,4 +1,4 @@
[toolchain] [toolchain]
channel = "1.83.0" channel = "stable"
components = [ "rustfmt" ] components = [ "rustfmt" ]
targets = [ "wasm32-unknown-unknown" ] targets = [ "wasm32-unknown-unknown" ]