@@ -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