diff --git a/.dockerignore b/.dockerignore index cf579a49c..f4ceea785 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1 @@ -.git **/target/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b00164a9..bf85b2d17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added support to `POST` *inspect state* requests - Added snapshot validation. The node will now check whether the snapshot's template hash matches the one stored in the blockchain - Added `cartesi/rollups-node` docker image with all node binaries +- Added versioning logs to all services ### Changed diff --git a/build/Dockerfile b/build/Dockerfile index 3378f1fc3..a9d53af79 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -65,6 +65,7 @@ RUN cargo chef cook --release --recipe-path recipe.json # Build application COPY ./offchain/ . +COPY ./.git ../ RUN cargo build --release # diff --git a/offchain/Cargo.lock b/offchain/Cargo.lock index c22a72032..cf049f1ea 100644 --- a/offchain/Cargo.lock +++ b/offchain/Cargo.lock @@ -862,6 +862,16 @@ dependencies = [ "uuid 0.8.2", ] +[[package]] +name = "built" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b99c4cdc7b2c2364182331055623bdf45254fcb679fea565c40c3c11c101889a" +dependencies = [ + "cargo-lock", + "git2", +] + [[package]] name = "bumpalo" version = "3.13.0" @@ -934,6 +944,18 @@ dependencies = [ "serde", ] +[[package]] +name = "cargo-lock" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11c675378efb449ed3ce8de78d75d0d80542fc98487c26aba28eb3b82feac72" +dependencies = [ + "semver", + "serde", + "toml 0.7.6", + "url", +] + [[package]] name = "cargo-platform" version = "0.1.3" @@ -2401,6 +2423,19 @@ version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +[[package]] +name = "git2" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b989d6a7ca95a362cf2cfc5ad688b3a467be1f87e480b8dad07fee8c79b0044" +dependencies = [ + "bitflags 1.3.2", + "libc", + "libgit2-sys", + "log 0.4.20", + "url", +] + [[package]] name = "glob" version = "0.3.1" @@ -2802,6 +2837,7 @@ name = "indexer" version = "1.1.0" dependencies = [ "backoff", + "built", "clap", "env_logger", "http-health-check", @@ -3046,6 +3082,30 @@ version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +[[package]] +name = "libgit2-sys" +version = "0.15.2+1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a80df2e11fb4a61f4ba2ab42dbe7f74468da143f1a75c74e11dee7c813f694fa" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + +[[package]] +name = "libz-sys" +version = "1.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -3096,7 +3156,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" name = "log" version = "1.1.0" dependencies = [ + "built", "clap", + "tracing", "tracing-subscriber", ] diff --git a/offchain/Cargo.toml b/offchain/Cargo.toml index 696760be6..f0924a6ce 100644 --- a/offchain/Cargo.toml +++ b/offchain/Cargo.toml @@ -36,6 +36,7 @@ awc = "3.1" axum = "0.6" backoff = "0.4" base64 = "0.21" +built = "0.6" byteorder = "1.4" clap = "4.3" diesel = "2.1" @@ -91,5 +92,3 @@ urlencoding = "2.1" users = "0.11" uuid = "1.4" -[profile.release] -strip = true # Automatically strip symbols from the binary. diff --git a/offchain/advance-runner/src/main.rs b/offchain/advance-runner/src/main.rs index 062a5a295..19312c6dd 100644 --- a/offchain/advance-runner/src/main.rs +++ b/offchain/advance-runner/src/main.rs @@ -11,5 +11,6 @@ async fn main() -> Result<(), Box> { log::configure(&config.log_config); info!(?config, "Starting Advance Runner"); + advance_runner::run(config).await.map_err(|e| e.into()) } diff --git a/offchain/authority-claimer/src/main.rs b/offchain/authority-claimer/src/main.rs index f08f7cd75..f3f7dd017 100644 --- a/offchain/authority-claimer/src/main.rs +++ b/offchain/authority-claimer/src/main.rs @@ -5,6 +5,7 @@ use authority_claimer::config::Config; use std::error::Error; use tracing::info; + #[tokio::main] async fn main() -> Result<(), Box> { // Getting the configuration. diff --git a/offchain/dispatcher/src/built/build.rs b/offchain/dispatcher/src/built/build.rs new file mode 100644 index 000000000..c8a3a44b7 --- /dev/null +++ b/offchain/dispatcher/src/built/build.rs @@ -0,0 +1,5 @@ +use built; + +pub(crate) fn main() { + built::write_built_file().expect("Failed to acquire build-time information"); +} \ No newline at end of file diff --git a/offchain/dispatcher/src/main.rs b/offchain/dispatcher/src/main.rs index dae55bf57..7cfe4a93d 100644 --- a/offchain/dispatcher/src/main.rs +++ b/offchain/dispatcher/src/main.rs @@ -13,5 +13,6 @@ async fn main() -> Result<(), Box> { log::configure(&config.dispatcher_config.log_config); info!(?config, "Starting Dispatcher"); + dispatcher::run(config).await.map_err(|e| e.into()) } diff --git a/offchain/graphql-server/Cargo.toml b/offchain/graphql-server/Cargo.toml index a75da1767..8becb735e 100644 --- a/offchain/graphql-server/Cargo.toml +++ b/offchain/graphql-server/Cargo.toml @@ -34,3 +34,4 @@ test-fixtures = { path = "../test-fixtures" } awc.workspace = true serial_test.workspace = true testcontainers.workspace = true + diff --git a/offchain/graphql-server/src/main.rs b/offchain/graphql-server/src/main.rs index ff7df3c6e..156ba8999 100644 --- a/offchain/graphql-server/src/main.rs +++ b/offchain/graphql-server/src/main.rs @@ -14,5 +14,6 @@ async fn main() -> Result<(), Box> { log::configure(&config.log_config); info!(?config, "Starting GraphQL Server"); + graphql_server::run(config).await.map_err(|e| e.into()) } diff --git a/offchain/host-runner/Cargo.toml b/offchain/host-runner/Cargo.toml index 51eaab757..a155d95c9 100644 --- a/offchain/host-runner/Cargo.toml +++ b/offchain/host-runner/Cargo.toml @@ -36,3 +36,4 @@ mockall.workspace = true rand.workspace = true serial_test.workspace = true tracing-test.workspace = true + diff --git a/offchain/indexer/Cargo.toml b/offchain/indexer/Cargo.toml index d3d8d524e..4351e3f9f 100644 --- a/offchain/indexer/Cargo.toml +++ b/offchain/indexer/Cargo.toml @@ -15,6 +15,7 @@ log = { path = "../log" } rollups-data = { path = "../data" } rollups-events = { path = "../rollups-events" } +built = { workspace = true, features = ["git2"] } clap = { workspace = true, features = ["derive", "env"] } snafu.workspace = true tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread"] } diff --git a/offchain/indexer/src/main.rs b/offchain/indexer/src/main.rs index 8bd930980..7272ced43 100644 --- a/offchain/indexer/src/main.rs +++ b/offchain/indexer/src/main.rs @@ -13,5 +13,6 @@ async fn main() -> Result<(), Box> { log::configure(&config.log_config); info!(?config, "Starting Indexer"); + indexer::run(config).await.map_err(|e| e.into()) } diff --git a/offchain/inspect-server/Cargo.toml b/offchain/inspect-server/Cargo.toml index 02039e551..b69db1352 100644 --- a/offchain/inspect-server/Cargo.toml +++ b/offchain/inspect-server/Cargo.toml @@ -30,3 +30,4 @@ uuid = { workspace = true, features = ["v4"] } futures.workspace = true reqwest = { workspace = true, features = ["json"] } serial_test.workspace = true + diff --git a/offchain/log/Cargo.toml b/offchain/log/Cargo.toml index e82a3e157..df4778e74 100644 --- a/offchain/log/Cargo.toml +++ b/offchain/log/Cargo.toml @@ -5,5 +5,10 @@ license.workspace = true version.workspace = true [dependencies] +built.workspace = true clap = { workspace = true, features = ["derive", "env"] } +tracing.workspace = true tracing-subscriber = { workspace = true, features = ["env-filter"] } + +[build-dependencies] +built = { workspace = true, features = ["git2"] } \ No newline at end of file diff --git a/offchain/log/build.rs b/offchain/log/build.rs new file mode 100644 index 000000000..df2e39096 --- /dev/null +++ b/offchain/log/build.rs @@ -0,0 +1,6 @@ +use built; + +pub(crate) fn main() { + built::write_built_file() + .expect("Failed to acquire build-time information"); +} diff --git a/offchain/log/src/build.rs b/offchain/log/src/build.rs new file mode 100644 index 000000000..df2e39096 --- /dev/null +++ b/offchain/log/src/build.rs @@ -0,0 +1,6 @@ +use built; + +pub(crate) fn main() { + built::write_built_file() + .expect("Failed to acquire build-time information"); +} diff --git a/offchain/log/src/lib.rs b/offchain/log/src/lib.rs index 4d4c36aa5..9f99b817e 100644 --- a/offchain/log/src/lib.rs +++ b/offchain/log/src/lib.rs @@ -1,5 +1,10 @@ use clap::Parser; use tracing_subscriber::filter::{EnvFilter, LevelFilter}; +use tracing::info; + +pub mod built_info { + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} #[derive(Debug, Parser)] #[command(name = "log_config")] @@ -51,4 +56,19 @@ pub fn configure(config: &LogConfig) { } else { subscribe_builder.init(); } + + log_build_info(); +} + +pub fn log_build_info() { + + info!("Version: {}", built_info::PKG_VERSION); + match built_info::GIT_HEAD_REF { + Some(v) => info!("Git ref: {}", v), + None => (), + } + match built_info::GIT_COMMIT_HASH { + Some(v) => info!("Git hash: {}", v), + None => (), + } }