Skip to content

Commit cc51ff5

Browse files
committed
chore: asked claude to make this to work on linux.
1 parent 9cc5de2 commit cc51ff5

File tree

6 files changed

+181
-111
lines changed

6 files changed

+181
-111
lines changed

caribic/Cargo.lock

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

caribic/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ lazy_static = "1.5.0"
1717
serde = { version = "1.0.209", features = ["derive"] }
1818
serde_json = "1.0"
1919
regex = "1.5"
20-
chrono = "0.4"
20+
chrono = "0.4"
21+
22+
[target.'cfg(unix)'.dependencies]
23+
nix = { version = "0.29", features = ["user"] }

caribic/src/start.rs

Lines changed: 117 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::setup::{
66
};
77
use crate::utils::{
88
copy_dir_all, download_file, execute_script, execute_script_with_progress,
9-
extract_tendermint_client_id, extract_tendermint_connection_id, get_cardano_state, unzip_file,
9+
extract_tendermint_client_id, extract_tendermint_connection_id, get_cardano_state, get_user_ids, unzip_file,
1010
wait_for_health_check, wait_until_file_exists, CardanoQuery, IndicatorMessage,
1111
};
1212
use crate::{
@@ -26,6 +26,15 @@ use std::process::Command;
2626
use std::time::Duration;
2727
use std::u64;
2828

29+
/// Get environment variables for Docker Compose, including UID/GID on Unix systems
30+
fn get_docker_env_vars() -> Vec<(&'static str, String)> {
31+
let (uid, gid) = get_user_ids();
32+
vec![
33+
("UID", uid),
34+
("GID", gid),
35+
]
36+
}
37+
2938
pub fn start_relayer(
3039
relayer_path: &Path,
3140
relayer_env_template_path: &Path,
@@ -66,11 +75,18 @@ pub fn start_relayer(
6675

6776
execute_script(relayer_path, "docker", Vec::from(["compose", "stop"]), None)?;
6877

69-
execute_script_with_progress(
78+
// Note: execute_script_with_progress doesn't support environment variables
79+
// Using regular execute_script for relayer with UID/GID support
80+
let docker_env = get_docker_env_vars();
81+
let docker_env_refs: Vec<(&str, &str)> = docker_env.iter()
82+
.map(|(k, v)| (*k, v.as_str()))
83+
.collect();
84+
85+
execute_script(
7086
relayer_path,
71-
"docker",
87+
"docker",
7288
Vec::from(["compose", "up", "-d", "--build"]),
73-
"⚡ Starting relayer...",
89+
Some(docker_env_refs),
7490
)?;
7591

7692
Ok(())
@@ -197,11 +213,15 @@ pub async fn start_local_cardano_network(
197213

198214
if config::get_config().cardano.services.db_sync {
199215
prepare_db_sync_and_gateway(cardano_dir.as_path(), clean)?;
216+
let docker_env = get_docker_env_vars();
217+
let docker_env_refs: Vec<(&str, &str)> = docker_env.iter()
218+
.map(|(k, v)| (*k, v.as_str()))
219+
.collect();
200220
execute_script(
201221
&cardano_dir,
202222
"docker",
203223
vec!["compose", "up", "-d", "cardano-db-sync"],
204-
None,
224+
Some(docker_env_refs),
205225
)?;
206226
}
207227

@@ -365,11 +385,17 @@ pub async fn start_cosmos_sidechain_from_repository(
365385

366386
pub async fn start_cosmos_sidechain(cosmos_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
367387
execute_script(cosmos_dir, "docker", Vec::from(["compose", "stop"]), None)?;
388+
389+
let docker_env = get_docker_env_vars();
390+
let docker_env_refs: Vec<(&str, &str)> = docker_env.iter()
391+
.map(|(k, v)| (*k, v.as_str()))
392+
.collect();
393+
368394
execute_script(
369395
cosmos_dir,
370396
"docker",
371397
Vec::from(["compose", "up", "-d", "--build"]),
372-
None,
398+
Some(docker_env_refs),
373399
)?;
374400

375401
let optional_progress_bar = match logger::get_verbosity() {
@@ -428,9 +454,14 @@ pub fn start_local_cardano_services(cardano_dir: &Path) -> Result<(), Box<dyn st
428454
script_stop_args.append(&mut services.clone());
429455
execute_script(cardano_dir, "docker", script_stop_args, None)?;
430456

457+
let docker_env = get_docker_env_vars();
458+
let docker_env_refs: Vec<(&str, &str)> = docker_env.iter()
459+
.map(|(k, v)| (*k, v.as_str()))
460+
.collect();
461+
431462
let mut script_start_args = vec!["compose", "up", "-d"];
432463
script_start_args.append(&mut services);
433-
execute_script(cardano_dir, "docker", script_start_args, None)?;
464+
execute_script(cardano_dir, "docker", script_start_args, Some(docker_env_refs))?;
434465
Ok(())
435466
}
436467

@@ -920,37 +951,45 @@ pub async fn start_mithril(project_root_dir: &Path) -> Result<u64, Box<dyn std::
920951
),
921952
&optional_progress_bar,
922953
);
954+
let docker_env = get_docker_env_vars();
955+
let mut mithril_env = vec![
956+
(
957+
"MITHRIL_AGGREGATOR_IMAGE",
958+
mithril_config.aggregator_image.as_str(),
959+
),
960+
("MITHRIL_CLIENT_IMAGE", mithril_config.client_image.as_str()),
961+
("MITHRIL_SIGNER_IMAGE", mithril_config.signer_image.as_str()),
962+
(
963+
"CARDANO_NODE_VERSION",
964+
mithril_config.cardano_node_version.as_str(),
965+
),
966+
(
967+
"CHAIN_OBSERVER_TYPE",
968+
mithril_config.chain_observer_type.as_str(),
969+
),
970+
("CARDANO_NODE_DIR", mithril_config.cardano_node_dir.as_str()),
971+
("MITHRIL_DATA_DIR", mithril_data_dir.to_str().unwrap()),
972+
(
973+
"GENESIS_VERIFICATION_KEY",
974+
mithril_config.genesis_verification_key.as_str(),
975+
),
976+
(
977+
"GENESIS_SECRET_KEY",
978+
mithril_config.genesis_secret_key.as_str(),
979+
),
980+
("MITHRIL_SIGNER_IMAGE", mithril_config.signer_image.as_str()),
981+
];
982+
983+
// Add UID/GID to environment
984+
for (key, value) in &docker_env {
985+
mithril_env.push((key, value.as_str()));
986+
}
987+
923988
execute_script(
924989
&mithril_script_dir,
925990
"docker",
926991
vec!["compose", "rm", "-f"],
927-
Some(vec![
928-
(
929-
"MITHRIL_AGGREGATOR_IMAGE",
930-
mithril_config.aggregator_image.as_str(),
931-
),
932-
("MITHRIL_CLIENT_IMAGE", mithril_config.client_image.as_str()),
933-
("MITHRIL_SIGNER_IMAGE", mithril_config.signer_image.as_str()),
934-
(
935-
"CARDANO_NODE_VERSION",
936-
mithril_config.cardano_node_version.as_str(),
937-
),
938-
(
939-
"CHAIN_OBSERVER_TYPE",
940-
mithril_config.chain_observer_type.as_str(),
941-
),
942-
("CARDANO_NODE_DIR", mithril_config.cardano_node_dir.as_str()),
943-
("MITHRIL_DATA_DIR", mithril_data_dir.to_str().unwrap()),
944-
(
945-
"GENESIS_VERIFICATION_KEY",
946-
mithril_config.genesis_verification_key.as_str(),
947-
),
948-
(
949-
"GENESIS_SECRET_KEY",
950-
mithril_config.genesis_secret_key.as_str(),
951-
),
952-
("MITHRIL_SIGNER_IMAGE", mithril_config.signer_image.as_str()),
953-
]),
992+
Some(mithril_env.clone()),
954993
)
955994
.map_err(|error| format!("Failed to bring down mithril services: {}", error))?;
956995

@@ -976,33 +1015,7 @@ pub async fn start_mithril(project_root_dir: &Path) -> Result<u64, Box<dyn std::
9761015
"-d",
9771016
"--no-build",
9781017
],
979-
Some(vec![
980-
(
981-
"MITHRIL_AGGREGATOR_IMAGE",
982-
mithril_config.aggregator_image.as_str(),
983-
),
984-
("MITHRIL_CLIENT_IMAGE", mithril_config.client_image.as_str()),
985-
("MITHRIL_SIGNER_IMAGE", mithril_config.signer_image.as_str()),
986-
(
987-
"CARDANO_NODE_VERSION",
988-
mithril_config.cardano_node_version.as_str(),
989-
),
990-
(
991-
"CHAIN_OBSERVER_TYPE",
992-
mithril_config.chain_observer_type.as_str(),
993-
),
994-
("CARDANO_NODE_DIR", mithril_config.cardano_node_dir.as_str()),
995-
("MITHRIL_DATA_DIR", mithril_data_dir.to_str().unwrap()),
996-
(
997-
"GENESIS_VERIFICATION_KEY",
998-
mithril_config.genesis_verification_key.as_str(),
999-
),
1000-
(
1001-
"GENESIS_SECRET_KEY",
1002-
mithril_config.genesis_secret_key.as_str(),
1003-
),
1004-
("MITHRIL_SIGNER_IMAGE", mithril_config.signer_image.as_str()),
1005-
]),
1018+
Some(mithril_env.clone()),
10061019
)
10071020
.map_err(|error| {
10081021
format!(
@@ -1081,6 +1094,41 @@ pub fn wait_and_start_mithril_genesis(
10811094

10821095
let mithril_config = config::get_config().mithril;
10831096

1097+
// Reuse the same environment variables with UID/GID
1098+
let docker_env = get_docker_env_vars();
1099+
let mut mithril_genesis_env = vec![
1100+
(
1101+
"MITHRIL_AGGREGATOR_IMAGE",
1102+
mithril_config.aggregator_image.as_str(),
1103+
),
1104+
("MITHRIL_CLIENT_IMAGE", mithril_config.client_image.as_str()),
1105+
("MITHRIL_SIGNER_IMAGE", mithril_config.signer_image.as_str()),
1106+
(
1107+
"CARDANO_NODE_VERSION",
1108+
mithril_config.cardano_node_version.as_str(),
1109+
),
1110+
(
1111+
"CHAIN_OBSERVER_TYPE",
1112+
mithril_config.chain_observer_type.as_str(),
1113+
),
1114+
("CARDANO_NODE_DIR", mithril_config.cardano_node_dir.as_str()),
1115+
("MITHRIL_DATA_DIR", mithril_data_dir.to_str().unwrap()),
1116+
(
1117+
"GENESIS_VERIFICATION_KEY",
1118+
mithril_config.genesis_verification_key.as_str(),
1119+
),
1120+
(
1121+
"GENESIS_SECRET_KEY",
1122+
mithril_config.genesis_secret_key.as_str(),
1123+
),
1124+
("MITHRIL_SIGNER_IMAGE", mithril_config.signer_image.as_str()),
1125+
];
1126+
1127+
// Add UID/GID to environment
1128+
for (key, value) in &docker_env {
1129+
mithril_genesis_env.push((key, value.as_str()));
1130+
}
1131+
10841132
execute_script(
10851133
&mithril_script_dir,
10861134
"docker",
@@ -1094,33 +1142,7 @@ pub fn wait_and_start_mithril_genesis(
10941142
"--rm",
10951143
"mithril-aggregator-genesis",
10961144
],
1097-
Some(vec![
1098-
(
1099-
"MITHRIL_AGGREGATOR_IMAGE",
1100-
mithril_config.aggregator_image.as_str(),
1101-
),
1102-
("MITHRIL_CLIENT_IMAGE", mithril_config.client_image.as_str()),
1103-
("MITHRIL_SIGNER_IMAGE", mithril_config.signer_image.as_str()),
1104-
(
1105-
"CARDANO_NODE_VERSION",
1106-
mithril_config.cardano_node_version.as_str(),
1107-
),
1108-
(
1109-
"CHAIN_OBSERVER_TYPE",
1110-
mithril_config.chain_observer_type.as_str(),
1111-
),
1112-
("CARDANO_NODE_DIR", mithril_config.cardano_node_dir.as_str()),
1113-
("MITHRIL_DATA_DIR", mithril_data_dir.to_str().unwrap()),
1114-
(
1115-
"GENESIS_VERIFICATION_KEY",
1116-
mithril_config.genesis_verification_key.as_str(),
1117-
),
1118-
(
1119-
"GENESIS_SECRET_KEY",
1120-
mithril_config.genesis_secret_key.as_str(),
1121-
),
1122-
("MITHRIL_SIGNER_IMAGE", mithril_config.signer_image.as_str()),
1123-
]),
1145+
Some(mithril_genesis_env),
11241146
)?;
11251147

11261148
current_slot = get_cardano_state(project_root_dir, CardanoQuery::Slot)?;
@@ -1179,6 +1201,12 @@ pub fn start_gateway(gateway_dir: &Path, clean: bool) -> Result<(), Box<dyn std:
11791201
script_args.push("--build");
11801202
}
11811203
execute_script(&gateway_dir, "docker", Vec::from(["compose", "stop"]), None)?;
1182-
execute_script(&gateway_dir, "docker", script_args, None)?;
1204+
1205+
let docker_env = get_docker_env_vars();
1206+
let docker_env_refs: Vec<(&str, &str)> = docker_env.iter()
1207+
.map(|(k, v)| (*k, v.as_str()))
1208+
.collect();
1209+
1210+
execute_script(&gateway_dir, "docker", script_args, Some(docker_env_refs))?;
11831211
Ok(())
11841212
}

caribic/src/utils.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ use std::{error::Error, process::Output};
2323
use tokio::io::AsyncWriteExt;
2424
use zip::read::ZipArchive;
2525

26+
#[cfg(unix)]
27+
use nix::unistd::{Uid, Gid};
28+
2629
pub fn print_header() {
2730
println!(
2831
r#"
@@ -586,3 +589,20 @@ pub fn query_balance(project_root_path: &Path, address: &str) -> u64 {
586589
.map(|k| k["value"]["lovelace"].as_u64().unwrap())
587590
.sum()
588591
}
592+
593+
/// Get current user's UID and GID for Docker containers (Unix only)
594+
/// Returns (UID, GID) or default (1000, 1000) on non-Unix systems
595+
pub fn get_user_ids() -> (String, String) {
596+
#[cfg(unix)]
597+
{
598+
let uid = Uid::current().as_raw();
599+
let gid = Gid::current().as_raw();
600+
(uid.to_string(), gid.to_string())
601+
}
602+
603+
#[cfg(not(unix))]
604+
{
605+
// Default UID/GID for non-Unix systems (Windows)
606+
("1000".to_string(), "1000".to_string())
607+
}
608+
}

0 commit comments

Comments
 (0)