From af8ba238c62a4d70d84e7c3e65fa8cb53bf142b9 Mon Sep 17 00:00:00 2001 From: Micah Date: Wed, 13 Nov 2024 14:40:52 -0800 Subject: [PATCH 1/2] Add version endpoint to registry backend --- wally-registry-backend/src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wally-registry-backend/src/main.rs b/wally-registry-backend/src/main.rs index 07ca2c6b..02ce83b4 100644 --- a/wally-registry-backend/src/main.rs +++ b/wally-registry-backend/src/main.rs @@ -59,6 +59,11 @@ fn root() -> content::RawJson { })) } +#[get("/version")] +fn version() -> content::RawText<&'static str> { + content::RawText(option_env!("GIT_HASH").unwrap_or(env!("CARGO_PKG_VERSION"))) +} + #[get("/v1/package-contents///")] async fn package_contents( storage: &State>, @@ -155,7 +160,7 @@ async fn publish( let manifest = get_manifest(&mut archive).status(Status::BadRequest)?; let package_id = manifest.package_id(); - if !authorization.can_write_package(&package_id, &index)? { + if !authorization.can_write_package(&package_id, index)? { return Err(format_err!( "you do not have permission to write in scope {}", package_id.name().scope() @@ -195,7 +200,7 @@ async fn publish( if let Ok(mut search_backend) = search_backend.try_write() { // TODO: Recrawling the whole index for each publish is very wasteful! // Eventually this will get too expensive and we should only add the new package. - search_backend.crawl_packages(&index)?; + search_backend.crawl_packages(index)?; } Ok(Json(json!({ @@ -251,6 +256,7 @@ pub fn server(figment: Figment) -> rocket::Rocket { "/", routes![ root, + version, package_contents, publish, package_info, From 6f7b0ce163f0b73353781de3dbb190161e8faf43 Mon Sep 17 00:00:00 2001 From: Micah Date: Wed, 13 Nov 2024 15:07:51 -0800 Subject: [PATCH 2/2] ...Docker magic? --- wally-registry-backend/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wally-registry-backend/Dockerfile b/wally-registry-backend/Dockerfile index 07e07c01..e7194518 100644 --- a/wally-registry-backend/Dockerfile +++ b/wally-registry-backend/Dockerfile @@ -1,6 +1,9 @@ FROM rust:1.81-slim-bookworm AS build WORKDIR /usr/app +ARG COMMIT_SHA +ENV COMMIT_SHA=$COMMIT_SHA + # Debian Slim doesn't install certificates by default, but we kinda want those. # pkg-config is used by some dependencies to locate system libraries. RUN apt-get update