Skip to content

Commit

Permalink
Add docker-compose for Lockbox
Browse files Browse the repository at this point in the history
  • Loading branch information
ssantos21 committed Dec 16, 2024
1 parent 634293b commit 60011f5
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
72 changes: 72 additions & 0 deletions docker-compose-lockbox.yml
Original file line number Diff line number Diff line change
@@ -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:
1 change: 1 addition & 0 deletions server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Settings.toml
2 changes: 2 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
14 changes: 9 additions & 5 deletions server/src/server_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> = 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<Enclave> {
Expand All @@ -136,7 +136,7 @@ impl ServerConfig {
return serde_json::from_str::<Vec<Enclave>>(&env_enclaves.unwrap()).unwrap();
}

settings.get::<Vec<Enclave>>(key).unwrap()
settings.as_ref().unwrap().get::<Vec<Enclave>>(key).unwrap()
};

let get_env_or_config_nostr_info = |key: &str, env_var: &str| -> Option<NostrInfo> {
Expand All @@ -150,7 +150,11 @@ impl ServerConfig {
return Some(res)
}

let res = settings.get::<NostrInfo>(key);
if settings.as_ref().is_none() {
return None
}

let res = settings.as_ref().unwrap().get::<NostrInfo>(key);

if res.is_ok() {
return Some(res.unwrap())
Expand Down

0 comments on commit 60011f5

Please sign in to comment.