🛰️ export from upstream (1f28d45)

This commit is contained in:
Gabor Koerber
2026-05-30 02:20:06 +02:00
parent 077ccabd53
commit c946b492fb
2 changed files with 38 additions and 1 deletions
+29 -1
View File
@@ -38,7 +38,7 @@ pub struct BollardBackend {
impl BollardBackend { impl BollardBackend {
pub fn try_new() -> super::Result<Self> { pub fn try_new() -> super::Result<Self> {
let docker = Docker::connect_with_local_defaults().map_err(|e| { let docker = Self::connect_docker().map_err(|e| {
DockerError::SpawnFailed(std::io::Error::new( DockerError::SpawnFailed(std::io::Error::new(
std::io::ErrorKind::ConnectionRefused, std::io::ErrorKind::ConnectionRefused,
format!( format!(
@@ -52,6 +52,34 @@ impl BollardBackend {
runtime_info: tokio::sync::OnceCell::new(), runtime_info: tokio::sync::OnceCell::new(),
}) })
} }
fn connect_docker() -> std::result::Result<Docker, bollard::errors::Error> {
if std::env::var("DOCKER_HOST").is_ok() {
return Docker::connect_with_local_defaults();
}
if let Some(socket) = Self::socket_from_docker_context() {
eprintln!("sandcage: using docker socket from context → {socket}");
return Docker::connect_with_socket(&socket, 120, bollard::API_DEFAULT_VERSION);
}
Docker::connect_with_local_defaults()
}
fn socket_from_docker_context() -> Option<String> {
let output = std::process::Command::new("docker")
.args(["context", "inspect", "--format", "{{.Endpoints.docker.Host}}"])
.output()
.ok()?;
if !output.status.success() {
return None;
}
let host = String::from_utf8(output.stdout).ok()?.trim().to_string();
let path = host.strip_prefix("unix://")?;
if std::path::Path::new(path).exists() {
Some(path.to_string())
} else {
None
}
}
} }
#[async_trait] #[async_trait]
+9
View File
@@ -5,7 +5,10 @@ set -e
CLAUDE_BIN="$HOME/.local/bin/claude" CLAUDE_BIN="$HOME/.local/bin/claude"
if [ ! -x "$CLAUDE_BIN" ]; then if [ ! -x "$CLAUDE_BIN" ]; then
echo "sandcage: installing Claude Code..." >&2 echo "sandcage: installing Claude Code..." >&2
WORKDIR="$(pwd)"
cd "$HOME"
curl -fsSL https://claude.ai/install.sh | bash >&2 curl -fsSL https://claude.ai/install.sh | bash >&2
cd "$WORKDIR"
fi fi
exec "$CLAUDE_BIN" "$@" exec "$CLAUDE_BIN" "$@"
"#; "#;
@@ -15,6 +18,8 @@ set -e
CODEX_BIN="$HOME/.local/bin/codex" CODEX_BIN="$HOME/.local/bin/codex"
if [ ! -x "$CODEX_BIN" ]; then if [ ! -x "$CODEX_BIN" ]; then
echo "sandcage: installing Codex..." >&2 echo "sandcage: installing Codex..." >&2
WORKDIR="$(pwd)"
cd "$HOME"
arch=$(uname -m) arch=$(uname -m)
case "$arch" in case "$arch" in
x86_64) target="x86_64-unknown-linux-musl" ;; x86_64) target="x86_64-unknown-linux-musl" ;;
@@ -25,6 +30,7 @@ if [ ! -x "$CODEX_BIN" ]; then
curl -fsSL "https://github.com/openai/codex/releases/latest/download/codex-${target}.tar.gz" \ curl -fsSL "https://github.com/openai/codex/releases/latest/download/codex-${target}.tar.gz" \
| tar xz -C "$HOME/.local/bin" | tar xz -C "$HOME/.local/bin"
mv "$HOME/.local/bin/codex-${target}" "$CODEX_BIN" mv "$HOME/.local/bin/codex-${target}" "$CODEX_BIN"
cd "$WORKDIR"
fi fi
exec "$CODEX_BIN" "$@" exec "$CODEX_BIN" "$@"
"#; "#;
@@ -34,7 +40,10 @@ set -e
GEMINI_BIN="$HOME/.local/bin/gemini" GEMINI_BIN="$HOME/.local/bin/gemini"
if [ ! -x "$GEMINI_BIN" ]; then if [ ! -x "$GEMINI_BIN" ]; then
echo "sandcage: installing Gemini CLI..." >&2 echo "sandcage: installing Gemini CLI..." >&2
WORKDIR="$(pwd)"
cd "$HOME"
npm install -g @anthropic-ai/gemini-cli >&2 npm install -g @anthropic-ai/gemini-cli >&2
cd "$WORKDIR"
fi fi
exec "$GEMINI_BIN" "$@" exec "$GEMINI_BIN" "$@"
"#; "#;