Skip to content

Commit c758c3e

Browse files
authored
Merge pull request #3050 from alexcb/enable-ssh-when-accessing-git-url
Enable ssh forwarding when building a remote target
2 parents e3dfc24 + af1bb80 commit c758c3e

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

cli/command/image/build_buildkit.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/moby/buildkit/session/secrets/secretsprovider"
3232
"github.com/moby/buildkit/session/sshforward/sshprovider"
3333
"github.com/moby/buildkit/util/appcontext"
34+
"github.com/moby/buildkit/util/gitutil"
3435
"github.com/moby/buildkit/util/progress/progressui"
3536
"github.com/moby/buildkit/util/progress/progresswriter"
3637
"github.com/pkg/errors"
@@ -186,10 +187,15 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
186187
}
187188
s.Allow(sp)
188189
}
189-
if len(options.ssh) > 0 {
190-
sshp, err := parseSSHSpecs(options.ssh)
190+
191+
sshSpecs := options.ssh
192+
if len(sshSpecs) == 0 && isGitSSH(remote) {
193+
sshSpecs = []string{"default"}
194+
}
195+
if len(sshSpecs) > 0 {
196+
sshp, err := parseSSHSpecs(sshSpecs)
191197
if err != nil {
192-
return errors.Wrapf(err, "could not parse ssh: %v", options.ssh)
198+
return errors.Wrapf(err, "could not parse ssh: %v", sshSpecs)
193199
}
194200
s.Allow(sshp)
195201
}
@@ -512,3 +518,8 @@ func parseSSH(value string) *sshprovider.AgentConfig {
512518
}
513519
return &cfg
514520
}
521+
522+
func isGitSSH(url string) bool {
523+
_, gitProtocol := gitutil.ParseProtocol(url)
524+
return gitProtocol == gitutil.SSHProtocol
525+
}

0 commit comments

Comments
 (0)