From 60011f58b9e6b8f3e4b5aa79990742928118254c Mon Sep 17 00:00:00 2001 From: "S. Santos" Date: Mon, 16 Dec 2024 11:37:31 -0300 Subject: [PATCH] Add docker-compose for Lockbox --- docker-compose-lockbox.yml | 72 +++++++++++++++++++++++++++++++++++++ server/.dockerignore | 1 + server/Dockerfile | 2 ++ server/src/main.rs | 10 +++++- server/src/server_config.rs | 14 +++++--- 5 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 docker-compose-lockbox.yml create mode 100644 server/.dockerignore diff --git a/docker-compose-lockbox.yml b/docker-compose-lockbox.yml new file mode 100644 index 00000000..96455cc2 --- /dev/null +++ b/docker-compose-lockbox.yml @@ -0,0 +1,72 @@ +services: + + lockbox: + build: + context: lockbox + dockerfile: ./Dockerfile + depends_on: + - db_lockbox + environment: + - LOCKBOX_DATABASE_URL=postgres://postgres:postgres@db_lockbox:5432/enclave + - LOCKBOX_PORT=18080 + - KEY_MANAGER=filesystem + - SEED_FILEPATH=./seed + ports: + - "18080:18080" + + mercury-server: + build: + context: . + dockerfile: server/Dockerfile + depends_on: + - db_server + environment: + BITCOIN_NETWORK: regtest + LOCKHEIGHT_INIT: 1000 + LH_DECREMENT: 10 + DB_USER: postgres + DB_PASSWORD: postgres + DB_HOST: db_server + DB_PORT: 5432 + DB_NAME: mercury + BATCH_TIMEOUT: 20 + ENCLAVES: '[{"url": "http://lockbox:18080", "allow_deposit": true}]' + NOSTR_INFO: '{ + "relay_server": "wss://relay.damus.io/", + "relay_interval": 15, + "nostr_privkey": "nsec17e0nvplcze4k7q9nazrw0k3aracwhg6vmuareewjp83ta89njw5spjcgzs", + "server_url": "http://mercury_server.xyz", + "location": "UK", + "active": true, + "onchain_payments": false, + "ln_payments": true, + "fee": 0.0001, + "unit": "BTC" + }' + ports: + - "8000:8000" + + db_lockbox: + image: postgres:16.2 + environment: + POSTGRES_PASSWORD: postgres + POSTGRES_DB: enclave + ports: + - "5433:5432" + volumes: + - postgres_lockbox_data:/var/lib/postgresql/data + + db_server: + image: postgres:16.2 + environment: + POSTGRES_PASSWORD: postgres + POSTGRES_DB: mercury + ports: + - "5432:5432" + volumes: + - postgres_server_data:/var/lib/postgresql/data + + +volumes: + postgres_lockbox_data: + postgres_server_data: diff --git a/server/.dockerignore b/server/.dockerignore new file mode 100644 index 00000000..1aa2155b --- /dev/null +++ b/server/.dockerignore @@ -0,0 +1 @@ +Settings.toml \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile index 5f19ea49..077199d8 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -16,6 +16,8 @@ COPY ./Cargo.lock ./Cargo.lock # Copy the server source code COPY ./server ./server +# Remove Settings.toml file +RUN rm -f ./server/Settings.toml COPY ./lib ./lib COPY ./Rocket.toml ./server/Rocket.toml diff --git a/server/src/main.rs b/server/src/main.rs index 84a976af..c3ff0a93 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -111,6 +111,9 @@ async fn main() { if config.nostr_info.is_some() { let nostr_info = config.nostr_info.unwrap(); + /* println!("nostr_info: {:?}", nostr_info); */ + println!("Nostr info found. Starting NIP-100 broadcast"); + let interval_seconds = nostr_info.relay_interval as u64; tokio::spawn(async move { @@ -124,7 +127,12 @@ async fn main() { loop { ticker.tick().await; - broadcast_nip_100(&nostr_info, published_at, timelock).await.unwrap(); + let result = broadcast_nip_100(&nostr_info, published_at, timelock).await; + if let Err(e) = result { + println!("Error: {:?}", e); + } /* else { + println!("NIP-100 broadcasted"); + } */ } }); } else { diff --git a/server/src/server_config.rs b/server/src/server_config.rs index a91bdac4..eb9a82aa 100644 --- a/server/src/server_config.rs +++ b/server/src/server_config.rs @@ -116,14 +116,14 @@ impl ServerConfig { // Override with settings in file Rocket.toml if exists conf_rs.merge(File::with_name("Rocket").required(false)); - let settings = ConfigRs::builder() + let settings: Option = ConfigRs::builder() .add_source(File::with_name("Settings")) .build() - .unwrap(); + .ok(); // Function to fetch a setting from the environment or fallback to the config file let get_env_or_config = |key: &str, env_var: &str| -> String { - env::var(env_var).unwrap_or_else(|_| settings.get_string(key).unwrap()) + env::var(env_var).unwrap_or_else(|_| settings.as_ref().unwrap().get_string(key).unwrap()) }; let get_env_or_config_enclave = |key: &str, env_var: &str| -> Vec { @@ -136,7 +136,7 @@ impl ServerConfig { return serde_json::from_str::>(&env_enclaves.unwrap()).unwrap(); } - settings.get::>(key).unwrap() + settings.as_ref().unwrap().get::>(key).unwrap() }; let get_env_or_config_nostr_info = |key: &str, env_var: &str| -> Option { @@ -150,7 +150,11 @@ impl ServerConfig { return Some(res) } - let res = settings.get::(key); + if settings.as_ref().is_none() { + return None + } + + let res = settings.as_ref().unwrap().get::(key); if res.is_ok() { return Some(res.unwrap())