Version 5.3.0

This commit is contained in:
George Tsiamasiotis 2025-01-18 22:02:17 +02:00
parent 7a39656e45
commit 06db6b1cdb
3 changed files with 9 additions and 262 deletions

View file

@ -1,6 +1,6 @@
pkgbase = kellnr
pkgdesc = The registry for Rust crates
pkgver = 5.2.7
pkgver = 5.3.0
pkgrel = 1
url = https://kellnr.io/
install = kellnr.install
@ -17,14 +17,12 @@ pkgbase = kellnr
depends = glibc
depends = gcc-libs
options = !lto
source = kellnr-5.2.7.tar.gz::https://github.com/kellnr/kellnr/archive/refs/tags/v5.2.7.tar.gz
source = pr-535.patch
source = kellnr-5.3.0.tar.gz::https://github.com/kellnr/kellnr/archive/refs/tags/v5.3.0.tar.gz
source = default.toml
source = kellnr.service
source = kellnr.sysusers
source = kellnr.tmpfiles
sha256sums = b7c8dfd1c6d782f90c512991b6b456913d1cda30c6fb968dd3c19200c832eed6
sha256sums = f31495eb6bd942ce6129bda32249777d22f47116e98a7b253ed853a7c311fb11
sha256sums = 0293cf392fb093612884071be173f20ea1eb0f2a2740cd5d97b994b4791508e1
sha256sums = 0578c49efb3e81ece93cff2da758fd7248abb3f0c062d7ed2e98d8de5218cff6
sha256sums = 28c931c3b6c1ab2e16e318a55e137300a9bfdd8581d7d668a3350574094e1c6d
sha256sums = a268b595b0048f3dda5d6cf8dea37d9c60b2333d8f4aae76ac93deb4b6e2e62e

View file

@ -2,7 +2,7 @@
# vim: set ts=4 sw=4 et:
pkgname=kellnr
pkgver=5.2.7
pkgver=5.3.0
pkgrel=1
pkgdesc='The registry for Rust crates'
arch=('x86_64')
@ -30,30 +30,23 @@ install=kellnr.install
options=(!lto)
source=("$pkgname-$pkgver.tar.gz::https://github.com/kellnr/kellnr/archive/refs/tags/v$pkgver.tar.gz"
"pr-535.patch" # https://patch-diff.githubusercontent.com/raw/kellnr/kellnr/pull/535.patch
"default.toml"
"kellnr.service"
"kellnr.sysusers"
"kellnr.tmpfiles")
sha256sums=('b7c8dfd1c6d782f90c512991b6b456913d1cda30c6fb968dd3c19200c832eed6'
'f31495eb6bd942ce6129bda32249777d22f47116e98a7b253ed853a7c311fb11'
sha256sums=('0293cf392fb093612884071be173f20ea1eb0f2a2740cd5d97b994b4791508e1'
'0578c49efb3e81ece93cff2da758fd7248abb3f0c062d7ed2e98d8de5218cff6'
'28c931c3b6c1ab2e16e318a55e137300a9bfdd8581d7d668a3350574094e1c6d'
'a268b595b0048f3dda5d6cf8dea37d9c60b2333d8f4aae76ac93deb4b6e2e62e'
'e81b1299bd28ca1691f7189c373f3672ec235a0ade8c23e195aeaf92a70ec1d6')
export RUSTUP_TOOLCHAIN=stable
export CARGO_TARGET_DIR=target
export RUSTUP_TOOLCHAIN="stable"
export CARGO_TARGET_DIR="target"
export CARGO_BUILD_TARGET="$CARCH-unknown-linux-gnu"
prepare() {
cd "$pkgname-$pkgver"
# PR written by me to make packaging less painful.
# TODO: Remove on update if merged.
patch -Np1 -i ../pr-535.patch
cargo fetch --locked
just npm-install
}
@ -77,7 +70,7 @@ check() {
package() {
cd "$pkgname-$pkgver"
# Install the kellnr binary into `/usr/bin`.
install -Dm0755 "target/$CARGO_BUILD_TARGET/release/$pkgname" -t "$pkgdir/usr/bin/"
@ -93,7 +86,7 @@ package() {
install -Dm644 "$srcdir/$pkgname.service" -t "$pkgdir/usr/lib/systemd/system"
install -Dm644 "$srcdir/$pkgname.sysusers" "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
install -Dm644 "$srcdir/$pkgname.tmpfiles" "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
# Install the license file (this is required for MIT).
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

View file

@ -1,244 +0,0 @@
From a4cdec88247bbb55a6dbf0756a4a4ac00886ae2b Mon Sep 17 00:00:00 2001
From: George Tsiamasiotis <gtsiam@windowslive.com>
Date: Thu, 12 Dec 2024 14:33:16 +0200
Subject: [PATCH 1/4] make config and static directories configurable
---
README.md | 11 +++++++++++
crates/kellnr/src/main.rs | 16 +++++-----------
crates/settings/src/settings.rs | 4 +++-
3 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index aa2108f4..0b36703b 100644
--- a/README.md
+++ b/README.md
@@ -74,6 +74,9 @@ just build
# Build the project (release)
just build-release
+# Build the frontend (result is placed in ./static)
+just npm-build
+
# Test the project (without Docker integration tests, requires cargo-nextest)
just test
@@ -94,6 +97,14 @@ nix develop
nix build
```
+#### Build options
+
+The following environment variables can be set at compile time to tell kellnr where it can find some
+relevant files.
+
+- `KELLNR_CONFIG_DIR`: The configuration directory (default: `./config`, `../config`, or `../../config`).
+- `KELLNR_STATIC_DIR`: The static html directory (default: `./static`).
+
### Sea ORM & PostgreSQL
**kellnr** uses Sqlite or PostreSQL as the storage backend for all crate related information. If you need a local PostgreSQL to test against, this Docker command sets one up on your local machine.
diff --git a/crates/kellnr/src/main.rs b/crates/kellnr/src/main.rs
index e148bdf0..ca98cb8c 100644
--- a/crates/kellnr/src/main.rs
+++ b/crates/kellnr/src/main.rs
@@ -14,12 +14,7 @@ use index::{
};
use registry::{cratesio_api, kellnr_api};
use settings::{LogFormat, Settings};
-use std::{
- convert::TryFrom,
- net::SocketAddr,
- path::{Path, PathBuf},
- sync::Arc,
-};
+use std::{net::SocketAddr, path::Path, sync::Arc};
use storage::{
cratesio_crate_storage::CratesIoCrateStorage, kellnr_crate_storage::KellnrCrateStorage,
};
@@ -31,9 +26,7 @@ use web_ui::{session, ui, user};
#[tokio::main]
async fn main() {
- let settings: Arc<Settings> = Settings::try_from(Path::new("config"))
- .expect("Cannot read config")
- .into();
+ let settings: Arc<Settings> = settings::get_settings().expect("Cannot read config").into();
let addr = SocketAddr::from((settings.local.ip, settings.local.port));
// Configure tracing subscriber
@@ -110,10 +103,11 @@ async fn main() {
middleware::from_fn_with_state(state.clone(), session::session_auth_when_required),
);
+ let static_path = Path::new(option_env!("KELLNR_STATIC_DIR").unwrap_or("./static"));
let static_files_service = get_service(
- ServeDir::new(PathBuf::from("static"))
+ ServeDir::new(&static_path)
.append_index_html_on_directories(true)
- .fallback(ServeFile::new(PathBuf::from("static/index.html"))),
+ .fallback(ServeFile::new(static_path.join("index.html"))),
);
let kellnr_api = Router::new()
diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs
index beda0131..739cb155 100644
--- a/crates/settings/src/settings.rs
+++ b/crates/settings/src/settings.rs
@@ -96,7 +96,9 @@ impl Settings {
}
pub fn get_settings() -> Result<Settings, ConfigError> {
- let path = if Path::new("./config").exists() {
+ let path = if let Some(path) = option_env!("KELLNR_CONFIG_DIR") {
+ Path::new(path)
+ } else if Path::new("./config").exists() {
Path::new("./config")
} else if Path::new("../config").exists() {
Path::new("../config")
From ffa74868841ae71efeaf73248e89755b60fe0a15 Mon Sep 17 00:00:00 2001
From: George Tsiamasiotis <gtsiam@windowslive.com>
Date: Thu, 12 Dec 2024 14:34:09 +0200
Subject: [PATCH 2/4] fix typo
---
crates/db/migration/src/m20220101_000009_create_table.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/crates/db/migration/src/m20220101_000009_create_table.rs b/crates/db/migration/src/m20220101_000009_create_table.rs
index deefc7b7..77e9aad6 100644
--- a/crates/db/migration/src/m20220101_000009_create_table.rs
+++ b/crates/db/migration/src/m20220101_000009_create_table.rs
@@ -32,14 +32,14 @@ async fn move_cached_crates(db: &SchemaManagerConnection<'_>) -> Result<(), DbEr
}
// Get all cached crate versions
- let cached_indicies = cratesio_index::Entity::find()
+ let cached_indices = cratesio_index::Entity::find()
.all(db)
.await?
.into_iter()
.collect::<Vec<_>>();
// Move each crate to the new location
- for cached_index in cached_indicies {
+ for cached_index in cached_indices {
let cached_crate = cached_index
.find_related(cratesio_crate::Entity)
.one(db)
From 6408770bb502cfa15d5c3cd3d79c48547d8df65b Mon Sep 17 00:00:00 2001
From: George Tsiamasiotis <gtsiam@windowslive.com>
Date: Thu, 12 Dec 2024 16:11:47 +0200
Subject: [PATCH 3/4] fix crates.io migration
---
.../src/m20220101_000009_create_table.rs | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/crates/db/migration/src/m20220101_000009_create_table.rs b/crates/db/migration/src/m20220101_000009_create_table.rs
index 77e9aad6..2ac16eb3 100644
--- a/crates/db/migration/src/m20220101_000009_create_table.rs
+++ b/crates/db/migration/src/m20220101_000009_create_table.rs
@@ -25,12 +25,6 @@ async fn move_cached_crates(db: &SchemaManagerConnection<'_>) -> Result<(), DbEr
debug!("Moving cached crates...");
let settings = get_settings().map_err(|e| DbErr::Custom(e.to_string()))?;
- // Make sure the cratesio bin path exists
- if !settings.crates_io_bin_path().exists() {
- std::fs::create_dir_all(settings.crates_io_bin_path())
- .map_err(|e| DbErr::Custom(e.to_string()))?;
- }
-
// Get all cached crate versions
let cached_indices = cratesio_index::Entity::find()
.all(db)
@@ -38,6 +32,18 @@ async fn move_cached_crates(db: &SchemaManagerConnection<'_>) -> Result<(), DbEr
.into_iter()
.collect::<Vec<_>>();
+ if cached_indices.is_empty() {
+ // There is nothing to do
+ debug!("No cached crates to move...");
+ return Ok(());
+ }
+
+ // Make sure the cratesio bin path exists
+ if !settings.crates_io_bin_path().exists() {
+ std::fs::create_dir_all(settings.crates_io_bin_path())
+ .map_err(|e| DbErr::Custom(e.to_string()))?;
+ }
+
// Move each crate to the new location
for cached_index in cached_indices {
let cached_crate = cached_index
From 3a60b0fd5d4cb26086d858ce51d83ec731e43476 Mon Sep 17 00:00:00 2001
From: George Tsiamasiotis <gtsiam@windowslive.com>
Date: Thu, 12 Dec 2024 17:56:16 +0200
Subject: [PATCH 4/4] read version information from KELLNR_VERSION
Let's just say that it's a slightly more sane than source sed on ci.
---
.github/workflows/ci.yaml | 3 ---
README.md | 4 ++--
crates/web_ui/src/ui.rs | 8 ++++----
3 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 9c5913d2..491e570c 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -80,9 +80,6 @@ jobs:
echo "KELLNR_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV
echo $KELLNR_VERSION
- - name: Replace Version in web_ui/ui
- run: sed -i 's/0.0.0-debug/'"$KELLNR_VERSION"'/' crates/web_ui/src/ui.rs
-
- name: Build Release {{ matrix.target }}
run: just target=${{ matrix.target }} ci-release
diff --git a/README.md b/README.md
index 0b36703b..a46b8e0b 100644
--- a/README.md
+++ b/README.md
@@ -99,9 +99,9 @@ nix build
#### Build options
-The following environment variables can be set at compile time to tell kellnr where it can find some
-relevant files.
+The following environment variables can be set at compile time:
+- `KELLNR_VERSION`: The version of kellnr currently being compiled (default: `0.0.0-unknown`).
- `KELLNR_CONFIG_DIR`: The configuration directory (default: `./config`, `../config`, or `../../config`).
- `KELLNR_STATIC_DIR`: The static html directory (default: `./static`).
diff --git a/crates/web_ui/src/ui.rs b/crates/web_ui/src/ui.rs
index 02340f22..11ed206c 100644
--- a/crates/web_ui/src/ui.rs
+++ b/crates/web_ui/src/ui.rs
@@ -31,9 +31,9 @@ pub struct KellnrVersion {
pub async fn kellnr_version() -> Json<KellnrVersion> {
Json(KellnrVersion {
- // Replaced automatically by the version from the build job,
- // if a new release is built.
- version: "0.0.0-debug".to_string(),
+ version: option_env!("KELLNR_VERSION")
+ .unwrap_or("0.0.0-unknown")
+ .to_string(),
})
}
@@ -909,7 +909,7 @@ mod tests {
let result_msg = r.into_body().collect().await.unwrap().to_bytes();
let result_version = serde_json::from_slice::<KellnrVersion>(&result_msg).unwrap();
- assert_eq!("0.0.0-debug", result_version.version);
+ assert_eq!("0.0.0-unknown", result_version.version);
}
#[tokio::test]