From f87afbc55853a57a58addf3094d4d8ed91ea3a6e Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Fri, 9 Apr 2021 09:03:25 +0300 Subject: [PATCH] fix(http): commit date & SHA in startup message --- Dockerfile | 3 +-- meilisearch-http/src/main.rs | 16 +++++++++++----- meilisearch-http/src/routes/stats.rs | 4 ++-- meilisearch-http/tests/stats/mod.rs | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index a45d2f7e5..bbaa4a570 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,8 +27,7 @@ RUN find . -path "*/src/main.rs" -delete ARG COMMIT_SHA ARG COMMIT_DATE -ENV COMMIT_SHA=${COMMIT_SHA} -ENV COMMIT_DATE=${COMMIT_DATE} +ENV COMMIT_SHA=${COMMIT_SHA} COMMIT_DATE=${COMMIT_DATE} COPY . . RUN $HOME/.cargo/bin/cargo build --release diff --git a/meilisearch-http/src/main.rs b/meilisearch-http/src/main.rs index b04c556db..eab7f4ac6 100644 --- a/meilisearch-http/src/main.rs +++ b/meilisearch-http/src/main.rs @@ -100,6 +100,15 @@ async fn run_http( } pub fn print_launch_resume(opt: &Opt, data: &Data) { + let commit_sha = match option_env!("COMMIT_SHA") { + Some("") | None => env!("VERGEN_SHA"), + Some(commit_sha) => commit_sha + }; + let commit_date = match option_env!("COMMIT_DATE") { + Some("") | None => env!("VERGEN_COMMIT_DATE"), + Some(commit_date) => commit_date + }; + let ascii_name = r#" 888b d888 d8b 888 d8b .d8888b. 888 8888b d8888 Y8P 888 Y8P d88P Y88b 888 @@ -116,11 +125,8 @@ pub fn print_launch_resume(opt: &Opt, data: &Data) { eprintln!("Database path:\t\t{:?}", opt.db_path); eprintln!("Server listening on:\t\"http://{}\"", opt.http_addr); eprintln!("Environment:\t\t{:?}", opt.env); - eprintln!("Commit SHA:\t\t{:?}", env!("VERGEN_SHA").to_string()); - eprintln!( - "Build date:\t\t{:?}", - env!("VERGEN_BUILD_TIMESTAMP").to_string() - ); + eprintln!("Commit SHA:\t\t{:?}", commit_sha.to_string()); + eprintln!("Commit date:\t\t{:?}", commit_date.to_string()); eprintln!( "Package version:\t{:?}", env!("CARGO_PKG_VERSION").to_string() diff --git a/meilisearch-http/src/routes/stats.rs b/meilisearch-http/src/routes/stats.rs index 7434f1727..988e6cf40 100644 --- a/meilisearch-http/src/routes/stats.rs +++ b/meilisearch-http/src/routes/stats.rs @@ -81,7 +81,7 @@ async fn get_stats(data: web::Data) -> Result #[serde(rename_all = "camelCase")] struct VersionResponse { commit_sha: String, - build_date: String, + commit_date: String, pkg_version: String, } @@ -98,7 +98,7 @@ async fn get_version() -> HttpResponse { HttpResponse::Ok().json(VersionResponse { commit_sha: commit_sha.to_string(), - build_date: commit_date.to_string(), + commit_date: commit_date.to_string(), pkg_version: env!("CARGO_PKG_VERSION").to_string(), }) } diff --git a/meilisearch-http/tests/stats/mod.rs b/meilisearch-http/tests/stats/mod.rs index ee10f9708..ef90dcf7f 100644 --- a/meilisearch-http/tests/stats/mod.rs +++ b/meilisearch-http/tests/stats/mod.rs @@ -9,7 +9,7 @@ async fn get_settings_unexisting_index() { assert_eq!(code, 200); let version = response.as_object().unwrap(); assert!(version.get("commitSha").is_some()); - assert!(version.get("buildDate").is_some()); + assert!(version.get("commitDate").is_some()); assert!(version.get("pkgVersion").is_some()); }