From 883ca71fda1d21cc9fe5a0ab3d2be20d34ea7405 Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Thu, 27 Jun 2024 09:41:23 -0600 Subject: [PATCH] feat: docker images --- .dockerignore | 4 ++++ Cargo.lock | 24 +++++++++++++++--------- Cargo.toml | 12 ++++++++++-- dockerfiles/runehook.dockerfile | 23 +++++++++++++++++++++++ dockerfiles/runes-api.dockerfile | 14 ++++++++++++++ src/scan/bitcoin.rs | 4 ++-- src/service.rs | 15 ++++++++++++--- 7 files changed, 80 insertions(+), 16 deletions(-) create mode 100644 .dockerignore create mode 100644 dockerfiles/runehook.dockerfile create mode 100644 dockerfiles/runes-api.dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0f653a6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +target/ +dockerfiles/ +.dockerignore +*.tar.gz diff --git a/Cargo.lock b/Cargo.lock index 42f66f7..7da0d39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -523,6 +523,8 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "chainhook-sdk" version = "0.12.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14eeb8a1a055202ca86122c9508dc4f9d9cd8643ef9f25773173b645c33b09ac" dependencies = [ "base58", "base64 0.21.7", @@ -556,7 +558,9 @@ dependencies = [ [[package]] name = "chainhook-types" -version = "1.3.6" +version = "1.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63f0d358e5c530dd6888e4678ef4ba3f7782525653a1012d33e96a48020c418d" dependencies = [ "hex", "schemars", @@ -3203,8 +3207,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.16" -source = "git+https://github.com/hirosystems/schemars.git?branch=feat-chainhook-fixes#d0c10b50478a06198a54e5b90be460112b38b357" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" dependencies = [ "dyn-clone", "schemars_derive", @@ -3214,13 +3219,14 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.16" -source = "git+https://github.com/hirosystems/schemars.git?branch=feat-chainhook-fixes#d0c10b50478a06198a54e5b90be460112b38b357" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 1.0.109", + "syn 2.0.61", ] [[package]] @@ -3367,13 +3373,13 @@ dependencies = [ [[package]] name = "serde_derive_internals" -version = "0.26.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.61", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3f9e3a7..681c4bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,11 +3,15 @@ name = "runehook" version = "0.1.0" edition = "2021" +[[bin]] +name = "runehook" +path = "src/main.rs" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -# chainhook-sdk = { version = "0.12.10", features = ["zeromq"] } -chainhook-sdk = { version = "=0.12.10", path = "../chainhook/components/chainhook-sdk", features = ["zeromq"] } +chainhook-sdk = { version = "0.12.10", features = ["zeromq"] } +# chainhook-sdk = { version = "=0.12.10", path = "../chainhook/components/chainhook-sdk", features = ["zeromq"] } bitcoin = { version = "0.30.1", features = ["rand"] } lru = "0.12.3" ordinals = "0.0.8" @@ -31,3 +35,7 @@ num-traits = "0.2.14" [dev-dependencies] test-case = "3.1.0" + +[features] +debug = ["hiro-system-kit/debug"] +release = ["hiro-system-kit/release"] diff --git a/dockerfiles/runehook.dockerfile b/dockerfiles/runehook.dockerfile new file mode 100644 index 0000000..03a907a --- /dev/null +++ b/dockerfiles/runehook.dockerfile @@ -0,0 +1,23 @@ +FROM rust:bullseye as build + +WORKDIR /app + +RUN apt-get update && apt-get install -y ca-certificates pkg-config libssl-dev libclang-11-dev libunwind-dev libunwind8 curl gnupg +RUN rustup update 1.77.1 && rustup default 1.77.1 + +RUN mkdir /out +COPY ./Cargo.toml /app/Cargo.toml +COPY ./Cargo.lock /app/Cargo.lock +COPY ./src /app/src +COPY ./migrations /app/migrations + +RUN cargo build --features release --release +RUN cp /app/target/release/runehook /out + +FROM debian:bullseye-slim + +COPY --from=build /out/runehook /bin/runehook + +WORKDIR /workspace + +ENTRYPOINT ["runehook"] diff --git a/dockerfiles/runes-api.dockerfile b/dockerfiles/runes-api.dockerfile new file mode 100644 index 0000000..e916709 --- /dev/null +++ b/dockerfiles/runes-api.dockerfile @@ -0,0 +1,14 @@ +FROM node:18-alpine + +WORKDIR /app +COPY ./api /app +COPY .git /app/.git + +RUN apk add --no-cache --virtual .build-deps git +RUN npm ci --no-audit && \ + npm run build && \ + npm run generate:git-info && \ + npm prune --production +RUN apk del .build-deps + +CMD ["node", "./dist/src/index.js"] diff --git a/src/scan/bitcoin.rs b/src/scan/bitcoin.rs index f33ca9a..ad31f44 100644 --- a/src/scan/bitcoin.rs +++ b/src/scan/bitcoin.rs @@ -7,7 +7,7 @@ use chainhook_sdk::chainhooks::bitcoin::{ BitcoinChainhookOccurrence, BitcoinTriggerChainhook, }; use chainhook_sdk::chainhooks::types::{ - BitcoinChainhookSpecification, BitcoinPredicateType, RunesOperations, + BitcoinChainhookSpecification, BitcoinPredicateType, }; use chainhook_sdk::indexer::bitcoin::{ build_http_client, download_and_parse_block_with_retry, retrieve_block_hash_with_retry, @@ -39,7 +39,7 @@ pub async fn scan_blocks( end_block: None, expired_at: None, expire_after_occurrence: None, - predicate: BitcoinPredicateType::RunesProtocol(RunesOperations::Feed), + predicate: BitcoinPredicateType::Block, action: chainhook_sdk::chainhooks::types::HookAction::Noop, include_proof: false, include_inputs: true, diff --git a/src/service.rs b/src/service.rs index bdd663c..7019954 100644 --- a/src/service.rs +++ b/src/service.rs @@ -39,9 +39,7 @@ pub async fn start_service(config: &Config, ctx: &Context) -> Result<(), String> } else if bitcoind_chain_tip > chain_tip { info!( ctx.expect_logger(), - "Scanning on block range {} to {}", - chain_tip, - bitcoind_chain_tip + "Scanning on block range {} to {}", chain_tip, bitcoind_chain_tip ); scan_blocks( ((chain_tip + 1)..bitcoind_chain_tip).collect(), @@ -100,6 +98,17 @@ pub async fn start_service(config: &Config, ctx: &Context) -> Result<(), String> index_block(&mut pg_client, &mut index_cache, block, ctx).await; } } + ObserverEvent::BitcoinChainEvent(( + BitcoinChainEvent::ChainUpdatedWithReorg(mut event), + _, + )) => { + for block in event.blocks_to_rollback.iter() { + // rollback + } + for block in event.blocks_to_apply.iter() { + // apply + } + } ObserverEvent::Terminate => {} _ => {} }