Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit ef9c945

Browse files
scsmithrnhooyr
authored andcommitted
Pass in SSH_AUTH_SOCK if it exists
Makes using git without a custom hat easier if the user's ssh agent is properly set up.
1 parent dca3e34 commit ef9c945

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

runner.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,16 @@ func (r *runner) runContainer(image string) error {
9191
cmd = r.testCmd + "\n exit 1"
9292
}
9393

94+
var envs []string
95+
sshAuthSock, exists := os.LookupEnv("SSH_AUTH_SOCK")
96+
if exists {
97+
s := fmt.Sprintf("SSH_AUTH_SOCK=%s", sshAuthSock)
98+
envs = append(envs, s)
99+
}
100+
94101
containerConfig := &container.Config{
95102
Hostname: r.hostname,
103+
Env: envs,
96104
Cmd: strslice.StrSlice{
97105
"bash", "-c", cmd,
98106
},
@@ -159,6 +167,19 @@ func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, erro
159167
Target: "~/.vscode/extensions",
160168
})
161169

170+
// 'SSH_AUTH_SOCK' is provided by a running ssh-agent. Passing in the
171+
// socket to the container allows for using the user's existing setup for
172+
// ssh authentication instead of having to create a new keys or explicity
173+
// pass them in.
174+
sshAuthSock, exists := os.LookupEnv("SSH_AUTH_SOCK")
175+
if exists {
176+
mounts = append(mounts, mount.Mount{
177+
Type: "bind",
178+
Source: sshAuthSock,
179+
Target: sshAuthSock,
180+
})
181+
}
182+
162183
localGlobalStorageDir := filepath.Join(metaRoot(), r.cntName, "globalStorage")
163184
err := os.MkdirAll(localGlobalStorageDir, 0750)
164185
if err != nil {

0 commit comments

Comments
 (0)