Compare commits

..

2 commits

Author SHA1 Message Date
a58024c192 fix: server_watcher don't use unwrap and use the external port quering the server 2026-01-13 13:32:26 +01:00
e67afc23df feat: don't rebuild dependencies(of the crate) if the hash changes
It used to rebuild all of the dependencies of the crate, because I
embed the hash in the program, and when commiting there is a new hash.
("revision" or "hash", it is just the git hash)

Now it only rebuilds the final crate, so there is caching again. :)
2026-01-12 13:57:05 +01:00
3 changed files with 24 additions and 9 deletions

View file

@ -41,12 +41,6 @@
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
COMMIT_HASH = builtins.substring 0 7 (
if self ? rev then self.rev else "NoDHash"
);
};
craneLibLLvmTools = craneLib.overrideToolchain
@ -64,6 +58,12 @@
# artifacts from above.
my-crate = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
COMMIT_HASH = builtins.substring 0 7 (
if self ? rev then self.rev else "NoDHash"
);
});
in
{

View file

@ -131,6 +131,7 @@ impl MinecraftAPI<Server> for McApi {
dep: deployment,
srv: service,
server_addr: addr.to_string(),
server_port: port.to_string(),
cache: self.cache.clone(),
});
}
@ -158,7 +159,16 @@ impl MinecraftAPI<Server> for McApi {
tracing::info!("starting watcher");
loop {
tokio::time::sleep(frequency).await;
let server = api.query_server(&addr, &port).await.unwrap();
let server = match api.query_server(&addr, &port).await {
Ok(x) => x,
Err(e) => {
tracing::error!(
err = format!("{}", e.context),
"could not query server"
);
return;
}
};
let status_json = match server.query_description().await {
Ok(x) => x,
Err(e) => {
@ -214,6 +224,7 @@ pub struct Server {
dep: Deployment,
srv: Service,
server_addr: String,
server_port: String,
cache: KubeCache,
}
impl fmt::Debug for Server {
@ -301,7 +312,7 @@ impl MinecraftServerHandle for Server {
}
fn get_internal_address(&self) -> Option<String> {
Some(format!("localhost:{}", self.get_port()?))
Some(format!("localhost:{}", self.get_internal_port()?))
}
fn get_addr(&self) -> Option<String> {
@ -350,11 +361,14 @@ impl MinecraftServerHandle for Server {
}
}
fn get_port(&self) -> Option<String> {
fn get_internal_port(&self) -> Option<String> {
let a = self.srv.clone().spec.unwrap().ports.unwrap();
let port = a.iter().find(|x| x.name.clone().unwrap() == "mc-router")?;
port.node_port.map(|x| x.to_string())
}
fn get_port(&self) -> Option<String> {
Some(self.server_port.clone())
}
fn get_motd(&self) -> Option<String> {
let all_container_motds = self

View file

@ -67,6 +67,7 @@ pub trait MinecraftServerHandle: Clone {
async fn stop(&self) -> Result<(), OpaqueError>;
async fn query_status(&self) -> Result<ServerDeploymentStatus, OpaqueError>;
fn get_internal_address(&self) -> Option<String>;
fn get_internal_port(&self) -> Option<String>;
fn get_addr(&self) -> Option<String>;
fn get_port(&self) -> Option<String>;
fn get_motd(&self) -> Option<String>;