fix(http): commit date & SHA in startup message

This commit is contained in:
Alexey Shekhirin 2021-04-09 09:03:25 +03:00
parent 8df5f73706
commit f87afbc558
No known key found for this signature in database
GPG Key ID: AF9A26AA133B5B98
4 changed files with 15 additions and 10 deletions

View File

@ -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

View File

@ -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()

View File

@ -81,7 +81,7 @@ async fn get_stats(data: web::Data<Data>) -> Result<HttpResponse, ResponseError>
#[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(),
})
}

View File

@ -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());
}