include default ssh socket when given an ssh-based git url

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
pull/581/head
Alex Couture-Beil 4 years ago
parent 98d337af21
commit eec843a325

@ -534,7 +534,11 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
}
bo.Session = append(bo.Session, secrets)
ssh, err := build.ParseSSHSpecs(t.SSH)
sshSpecs := t.SSH
if len(sshSpecs) == 0 && build.IsGitSSH(contextPath) {
sshSpecs = []string{"default"}
}
ssh, err := build.ParseSSHSpecs(sshSpecs)
if err != nil {
return nil, err
}

@ -5,6 +5,7 @@ import (
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/session/sshforward/sshprovider"
"github.com/moby/buildkit/util/gitutil"
)
func ParseSSHSpecs(sl []string) (session.Attachable, error) {
@ -29,3 +30,9 @@ func parseSSH(value string) (*sshprovider.AgentConfig, error) {
}
return &cfg, nil
}
// IsGitSSH returns true if the given repo URL is accessed over ssh
func IsGitSSH(url string) bool {
_, gitProtocol := gitutil.ParseProtocol(url)
return gitProtocol == gitutil.SSHProtocol
}

@ -124,7 +124,11 @@ func runBuild(dockerCli command.Cli, in buildOptions) error {
}
opts.Session = append(opts.Session, secrets)
ssh, err := build.ParseSSHSpecs(in.ssh)
sshSpecs := in.ssh
if len(sshSpecs) == 0 && build.IsGitSSH(in.contextPath) {
sshSpecs = []string{"default"}
}
ssh, err := build.ParseSSHSpecs(sshSpecs)
if err != nil {
return err
}

Loading…
Cancel
Save