Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cave"
version = "0.1.5"
version = "0.1.6"
authors = ["Simvia <basile.marchand@simvia.tech>"]
edition = "2021"
description = "CLI for managing code_aster versions"
Expand Down
41 changes: 40 additions & 1 deletion src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use crate::telemetry::{send_execution_data, ExecutionData};
use log::debug;
use std::env;

#[cfg(unix)]
use std::os::unix::fs::MetadataExt;

// TODO : uncomment to have registry option
// use regex::Regex;
// use crate::config::Registry;
Expand Down Expand Up @@ -221,12 +224,18 @@ pub fn docker_aster(version: &str, export_file: &Option<String>, args: &Vec<Stri
let volume_arg = format!("{}:/home/user/data", current_dir.display());
let image = format!("simvia/code_aster:{}", version);
let export = export_file.clone().unwrap_or_default();
let docker_command = format!("run_aster {} {}", args.join(" "), export);
let docker_command = format!("source /opt/activate.sh && run_aster {} {}", args.join(" "), export);

// Get the current user's UID and GID to avoid permission issues
let (uid, gid) = get_uid_gid();
let user_arg = format!("{}:{}", uid, gid);

let mut child = Command::new("docker")
.arg("run")
.arg("--rm")
.arg("-it")
.arg("--user")
.arg(&user_arg)
.arg("-v")
.arg(&volume_arg)
.arg("-w")
Expand Down Expand Up @@ -296,6 +305,36 @@ pub fn docker_aster(version: &str, export_file: &Option<String>, args: &Vec<Stri
}


/// Returns the current user's UID and GID.
/// On Unix systems, gets the actual UID/GID.
/// On Windows, returns (1000, 1000) as default.
fn get_uid_gid() -> (u32, u32) {
#[cfg(unix)]
{
// Try to get UID/GID from the current directory's metadata
if let Ok(metadata) = std::env::current_dir().and_then(|p| std::fs::metadata(p)) {
(metadata.uid(), metadata.gid())
} else {
// Fallback to environment or default
let uid = std::env::var("UID")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(1000);
let gid = std::env::var("GID")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(1000);
(uid, gid)
}
}

#[cfg(not(unix))]
{
// On Windows, return default values
(1000, 1000)
}
}

pub fn image_id(version: &str) -> Result<String, CaveError> {
let reference = format!("simvia/code_aster:{}", version);

Expand Down
Loading