feat(homelab): start containerizing homelab binary

This commit is contained in:
2026-01-06 09:01:45 -08:00
parent b02a06faa7
commit dd904c151d
4 changed files with 21 additions and 13 deletions

View File

@@ -92,7 +92,7 @@ routes = [
service = "prometheus-stack-grafana",
port = 80,
private = true
},
}
]
[pihole]
@@ -109,4 +109,6 @@ extra_hosts = [
[router]
host = "192.168.15.1:22"
user = "luca"
key_path = "/home/luca/.ssh/id_ed25519"
lease_file = "/var/dhcpd/var/db/dhcpd.leases"

View File

@@ -5,7 +5,7 @@ metadata:
namespace: metallb-system
spec:
addresses:
- 192.168.27.12-192.168.27.30
- 192.168.27.12-192.168.27.40
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement

View File

@@ -5,8 +5,8 @@ mod lease_parser;
mod pihole;
mod transport;
use std::collections::HashSet;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::{collections::HashSet, env};
use anyhow::Context;
use clap::{CommandFactory, Parser};
@@ -58,6 +58,8 @@ pub struct PiHoleConfig {
#[derive(Serialize, Deserialize)]
pub struct RouterConfig {
host: String,
user: String,
key_path: PathBuf,
lease_file: String,
}
@@ -69,6 +71,10 @@ pub fn parse_config<T: AsRef<Path>>(path: T) -> anyhow::Result<Config> {
Ok(toml::from_slice::<Config>(&bytes)?)
}
fn env_or<S: Into<String>>(key: &str, fallback: S) -> String {
env::var(key).unwrap_or_else(|_| fallback.into())
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
@@ -79,7 +85,8 @@ async fn main() -> anyhow::Result<()> {
generate_routes(&config)?;
}
Some(Commands::SyncDNS {}) => {
let config = parse_config("./config.toml")?;
let config_path = env_or("CONFIG_PATH", "./config.toml");
let config = parse_config(config_path)?;
let pihole_config = config
.pihole
.context("pihole configuration is necessary for syncing dns")?;
@@ -96,7 +103,11 @@ async fn main() -> anyhow::Result<()> {
.to_string();
let leases = tokio::task::spawn_blocking(move || -> anyhow::Result<Vec<Lease>> {
let r = Router::new(SSHTransport::new(&router_config.host)?);
let r = Router::new(SSHTransport::new(
&router_config.host,
&router_config.user,
&router_config.key_path,
)?);
let leases = r
.dhcp_leases(&router_config.lease_file)?
.into_iter()

View File

@@ -9,7 +9,7 @@ pub struct SSHTransport {
}
impl SSHTransport {
pub fn new(host: &str) -> Result<Self> {
pub fn new(host: &str, user: &str, key_path: &Path) -> Result<Self> {
let stream = TcpStream::connect(host)?;
let mut s = Self {
@@ -17,12 +17,7 @@ impl SSHTransport {
};
s.session.set_tcp_stream(stream);
s.session.handshake()?;
s.session.userauth_pubkey_file(
"luca",
None,
Path::new("/home/luca/.ssh/id_ed25519"),
None,
)?;
s.session.userauth_pubkey_file(user, None, key_path, None)?;
Ok(s)
}
}