diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1809787..f3bebe8 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,7 +5,8 @@ on: paths: - .github/workflows/docker.yml - proto/**.proto - - src/** + - src/**.rs + - build.rs - Cargo.toml - Cargo.lock push: diff --git a/.github/workflows/lint-rust.yml b/.github/workflows/lint-rust.yml index f6fe43c..1c6e427 100644 --- a/.github/workflows/lint-rust.yml +++ b/.github/workflows/lint-rust.yml @@ -1,10 +1,11 @@ -name: check-rust +name: lint-rust on: pull_request: paths: - - .github/workflows/lint-rust.yml - - **.rs + - .github/workflows/docker.yml + - src/**.rs + - build.rs - Cargo.toml - Cargo.lock diff --git a/Cargo.lock b/Cargo.lock index 641166d..cfff294 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -317,7 +317,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -328,7 +328,7 @@ checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -458,7 +458,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", "syn_derive", ] @@ -576,7 +576,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -824,6 +824,7 @@ dependencies = [ "tokio-stream", "tonic", "tonic-build", + "tonic-health", ] [[package]] @@ -1397,7 +1398,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -1434,7 +1435,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -1505,7 +1506,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.86", + "syn 2.0.87", "tempfile", ] @@ -1519,7 +1520,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -1742,7 +1743,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -1831,7 +1832,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -1844,7 +1845,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -1860,9 +1861,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.86" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89275301d38033efb81a6e60e3497e734dfcc62571f2854bf4b16690398824c" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -1878,7 +1879,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -1925,22 +1926,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d171f59dbaa811dbbb1aee1e73db92ec2b122911a48e1390dfe327a821ddede" +checksum = "3b3c6efbfc763e64eb85c11c25320f0737cb7364c4b6336db90aa9ebe27a0bbd" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b08be0f17bd307950653ce45db00cd31200d82b624b36e181337d9c7d92765b5" +checksum = "b607164372e89797d78b8e23a6d67d5d1038c1c65efd52e1389ef8b77caba2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -1991,7 +1992,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -2076,7 +2077,20 @@ dependencies = [ "prost-build", "prost-types", "quote", - "syn 2.0.86", + "syn 2.0.87", +] + +[[package]] +name = "tonic-health" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1eaf34ddb812120f5c601162d5429933c9b527d901ab0e7f930d3147e33a09b2" +dependencies = [ + "async-stream", + "prost", + "tokio", + "tokio-stream", + "tonic", ] [[package]] @@ -2130,7 +2144,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] [[package]] @@ -2221,7 +2235,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -2243,7 +2257,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2392,5 +2406,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.86", + "syn 2.0.87", ] diff --git a/Cargo.toml b/Cargo.toml index 66e646c..586470e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,11 @@ futures-core = { version = "0.3.31" } log = { version = "0.4.22" } prost = { version = "0.13.3" } prost-types = { version = "0.13.3" } -thiserror = { version = "1.0.66" } +thiserror = { version = "1.0.67" } tokio = { version = "1.41.0", features = ["rt-multi-thread", "macros", "sync" ] } tokio-stream = { version = "0.1.16" } tonic = { version = "0.12.3" } +tonic-health = { version = "0.12.3" } [build-dependencies] diff --git a/Dockerfile b/Dockerfile index 7d0fcdd..6451ea9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ # syntax=docker/dockerfile:1 ARG RUST_VERSION=1.82 +ARG GRPC_HEALTH_PROBE_VERSION=0.4.35 + FROM rust:${RUST_VERSION}-slim-bookworm AS builder WORKDIR /home/gduck @@ -14,10 +16,21 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ && mkdir /home/gduck/dist \ && cp /home/gduck/target/release/gduck /home/gduck/dist +FROM builder AS probe + +ARG GRPC_HEALTH_PROBE_VERSION + +RUN apt-get update -y \ + && apt-get install -y wget \ + && wget -O /grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 FROM debian:bookworm-slim +COPY --from=probe --chmod=100 /grpc_health_probe /usr/local/bin COPY --from=builder /home/gduck/dist/gduck /gduck ENV RUST_LOG=info RUST_BACKTRACE=1 -ENTRYPOINT ["/gduck"] +HEALTHCHECK --interval=10s --timeout=5s --start-period=3s --retries=3 \ + CMD [ "grpc_health_probe", "--addr=127.0.0.1:50051" ] + +ENTRYPOINT ["/gduck", "--port", "50051"] diff --git a/src/main.rs b/src/main.rs index 70b3fe6..ba8a939 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,9 +29,18 @@ async fn main() -> Result<(), Box> { env_logger::init(); let addr: SocketAddr = format!("{}:{}", args.bind_address, args.port).parse()?; + let (mut reporter, health_service) = tonic_health::server::health_reporter(); + reporter + .set_serving::>() + .await; + let service = service::DuckDbService::new_server(); log::info!("Start listening on {}", addr.to_string()); - Server::builder().add_service(service).serve(addr).await?; + Server::builder() + .add_service(health_service) + .add_service(service) + .serve(addr) + .await?; Ok(()) }