diff --git a/.drone.yml b/.drone.yml index b71068d..36406ce 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,6 +26,7 @@ steps: - name: dockersock path: /var/run commands: + - ssh-add - cuddle x build_cuddle_image environment: DOCKER_BUILDKIT: 1 diff --git a/cuddle_cli/src/context.rs b/cuddle_cli/src/context.rs index de551da..550ba83 100644 --- a/cuddle_cli/src/context.rs +++ b/cuddle_cli/src/context.rs @@ -121,12 +121,16 @@ fn pull_parent_cuddle_into_local( ) -> anyhow::Result<()> { let mut rc = RemoteCallbacks::new(); rc.credentials(|_url, username_from_url, _allowed_types| { - git2::Cred::ssh_key( - username_from_url.unwrap(), - None, - Path::new(&format!("{}/.ssh/id_ed25519", env::var("HOME").unwrap())), - None, - ) + if "true".to_string() == std::env::var("CUDDLE_SSH_AGENT").ok().unwrap_or("".into()) { + git2::Cred::ssh_key_from_agent(username_from_url.unwrap()) + } else { + git2::Cred::ssh_key( + username_from_url.unwrap(), + None, + Path::new(&format!("{}/.ssh/id_ed25519", env::var("HOME").unwrap())), + None, + ) + } }); let mut fo = FetchOptions::new(); diff --git a/templates/build_cuddle_image.Dockerfile b/templates/build_cuddle_image.Dockerfile index 9a16835..dd93f3b 100644 --- a/templates/build_cuddle_image.Dockerfile +++ b/templates/build_cuddle_image.Dockerfile @@ -21,6 +21,7 @@ RUN cargo install --target x86_64-unknown-linux-musl --path cuddle_cli FROM docker:dind RUN apk add bash git +RUN eval `ssh-agent` COPY --from=1password/op:2 /usr/local/bin/op /usr/local/bin/op