From c571bcab4d7c1926d98411cae83976df8d339f43 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Fri, 18 Aug 2023 17:27:32 +0000 Subject: [PATCH 1/2] feat: add docker --- Dockerfile | 44 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 17 ++++++++++++----- 2 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..1eafd271 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +# syntax=docker/dockerfile:1.4 + +# Use Ubuntu 22.04 as the build environment +FROM ubuntu:22.04 as build-environment + +# Set non-interactive mode for apt so it doesn't ask for user input during the build +ENV DEBIAN_FRONTEND=noninteractive + +# Install required dependencies +RUN apt-get update && apt-get install -y clang lld curl build-essential linux-generic git \ + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh \ + && chmod +x ./rustup.sh \ + && ./rustup.sh -y + +ARG TARGETARCH +WORKDIR /opt + + +# Add the required CFLAGS if the TARGETARCH matches +RUN [[ "$TARGETARCH" = "x86_64-unknown-linux-gnu" ]] && echo "export CFLAGS=-mno-outline-atomics" >> $HOME/.profile || true + +WORKDIR /opt/cryo +COPY . . + +RUN . $HOME/.profile && cargo build --bin cryo --release \ + && mkdir out \ + && mv target/release/cryo out/cryo \ + && strip out/cryo + +# Use Ubuntu 22.04 for the client as well, but you can use a smaller or different version if needed +FROM ubuntu:22.04 as cryo-client + +ENV DEBIAN_FRONTEND=noninteractive + +# Install required dependencies +RUN apt-get update -y && apt-get install linux-generic git -y + +# Copy the compiled binary from the build environment +COPY --from=build-environment /opt/cryo/out/cryo /usr/local/bin/cryo + +# Add a user for cryo +RUN useradd -ms /bin/bash cryo + +ENTRYPOINT ["cryo"] diff --git a/README.md b/README.md index ef149caa..cdff7ede 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ cryo can extract the following datasets from EVM nodes: - `blocks` - `transactions` (alias = `txs`) - `logs` (alias = `events`) -- `contracts` - `traces` (alias = `call_traces`) - `state_diffs` (alias for `storage_diffs` + `balance_diff` + `nonce_diffs` + `code_diffs`) - `balance_diffs` @@ -62,7 +61,7 @@ This method requires having rust installed. See [rustup](https://rustup.rs/) for Make sure that `~/.cargo/bin` is on your `PATH`. One way to do this is by adding the line `export PATH="$HOME/.cargo/bin:$PATH"` to your `~/.bashrc` or `~/.profile`. -#### Installing `cryo_python` from pypi +#### Method 3: Installing `cryo_python` from pypi (make sure rust is installed first, see [rustup](https://www.rust-lang.org/tools/install)) @@ -71,7 +70,7 @@ pip install maturin pip install cryo_python ``` -#### Installing `cryo_python` from source +#### Method 4: Installing `cryo_python` from source ```bash pip install maturin @@ -81,6 +80,16 @@ maturin build --release pip install .whl ``` +#### Method 5: Docker + +In order to run `cryo` in a docker container + +```shell +docker build -t . +docker run -it +``` + + ## Data Schema Many `cryo` cli options will affect output schemas by adding/removing columns or changing column datatypes. @@ -96,7 +105,6 @@ Many `cryo` cli options will affect output schemas by adding/removing columns or |Blocks|1|1|`eth_getBlockByNumber`| |Transactions|1|multiple|`eth_getBlockByNumber`| |Logs|multiple|multiple|`eth_getLogs`| -|Contracts|1|multiple|`trace_block`| |Traces|1|multiple|`trace_block`| |State Diffs|1|multiple|`trace_replayBlockTransactions`| |Vm Traces|1|multiple|`trace_replayBlockTransactions`| @@ -119,7 +127,6 @@ Arguments: - blocks - transactions (alias = txs) - logs (alias = events) - - contracts - traces (alias = call_traces) - state_diffs (= balance + code + nonce + storage diffs) - balance_diffs From 89ee71e41c38cb43da16116fdd6912d03b2fa6b6 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Sat, 19 Aug 2023 07:21:28 +0000 Subject: [PATCH 2/2] fix: review comments --- Dockerfile | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1eafd271..e1e01341 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,18 @@ # syntax=docker/dockerfile:1.4 -# Use Ubuntu 22.04 as the build environment -FROM ubuntu:22.04 as build-environment +# Use rust:bookworm as the build environment +FROM rust:bookworm as build-environment # Set non-interactive mode for apt so it doesn't ask for user input during the build ENV DEBIAN_FRONTEND=noninteractive -# Install required dependencies -RUN apt-get update && apt-get install -y clang lld curl build-essential linux-generic git \ - && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh \ - && chmod +x ./rustup.sh \ - && ./rustup.sh -y +# # Install required dependencies +# RUN apt-get update && apt-get install -y clang lld curl build-essential linux-generic git \ +# && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh \ +# && chmod +x ./rustup.sh \ +# && ./rustup.sh -y + +RUN apt-get update && apt-get install cmake -y ARG TARGETARCH WORKDIR /opt @@ -22,18 +24,20 @@ RUN [[ "$TARGETARCH" = "x86_64-unknown-linux-gnu" ]] && echo "export CFLAGS=-mno WORKDIR /opt/cryo COPY . . -RUN . $HOME/.profile && cargo build --bin cryo --release \ +RUN . $HOME/.profile && cargo build --bin cryo --release --locked \ && mkdir out \ && mv target/release/cryo out/cryo \ && strip out/cryo -# Use Ubuntu 22.04 for the client as well, but you can use a smaller or different version if needed -FROM ubuntu:22.04 as cryo-client +# Use debian:bookworm-slim for the client +FROM debian:bookworm-slim as cryo-client ENV DEBIAN_FRONTEND=noninteractive # Install required dependencies -RUN apt-get update -y && apt-get install linux-generic git -y +# RUN apt-get update -y && apt-get install linux-generic git -y + +RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/* # Copy the compiled binary from the build environment COPY --from=build-environment /opt/cryo/out/cryo /usr/local/bin/cryo