From 9cbd862269a9ca5129b062ac06c87bd13d34b222 Mon Sep 17 00:00:00 2001 From: Debian Date: Tue, 2 Sep 2025 14:20:29 +0000 Subject: [PATCH] feat(sdk_relay): Dockerfile runtime deps + RPC user/pass fallback via env --- Dockerfile | 9 ++++++--- src/daemon.rs | 33 ++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index bb61346..333a1b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.75-alpine AS builder +FROM rust:1.83-alpine AS builder WORKDIR /app # Dépendances de build @@ -19,13 +19,16 @@ WORKDIR /home/bitcoin RUN adduser -D relay && \ mkdir -p /home/bitcoin/.4nk && chown -R relay:relay /home/bitcoin +# Certificats et fuseaux (logs lisibles) minimal +RUN apk add --no-cache ca-certificates tzdata && update-ca-certificates + # Copier le binaire COPY --from=builder /app/target/release/sdk_relay /usr/local/bin/sdk_relay EXPOSE 8090 8091 USER relay +ENV RUST_LOG=info + # Le service lit la conf depuis "/home/bitcoin/.conf" (montée par docker-compose) CMD ["/usr/local/bin/sdk_relay"] - - diff --git a/src/daemon.rs b/src/daemon.rs index 4fda18d..6062fff 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -107,20 +107,27 @@ fn rpc_connect(rpcwallet: Option, network: Network, mut rpc_url: String, .url(&rpc_url)? .timeout(Duration::from_secs(30)); - let cookie_path = match cookie_path { - Some(path) => path, - None => { - // Fallback to default path - let home = env::var("HOME")?; - let mut default_path = PathBuf::from_str(&home)?; - default_path.push(".bitcoin"); - default_path.push(network.to_core_arg()); - default_path.push(".cookie"); - default_path - } - }; + // Prefer explicit user/pass via environment variables if provided + let rpc_user_env = env::var("RELAY_RPC_USER").ok(); + let rpc_pass_env = env::var("RELAY_RPC_PASSWORD").ok(); - let daemon_auth = SensitiveAuth(Auth::CookieFile(cookie_path)); + let daemon_auth = if let (Some(u), Some(p)) = (rpc_user_env, rpc_pass_env) { + SensitiveAuth(Auth::UserPass(u, p)) + } else { + let cookie_path = match cookie_path { + Some(path) => path, + None => { + // Fallback to default path + let home = env::var("HOME")?; + let mut default_path = PathBuf::from_str(&home)?; + default_path.push(".bitcoin"); + default_path.push(network.to_core_arg()); + default_path.push(".cookie"); + default_path + } + }; + SensitiveAuth(Auth::CookieFile(cookie_path)) + }; let builder = match daemon_auth.get_auth() { Auth::None => builder, Auth::UserPass(user, pass) => builder.auth(user, Some(pass)),