Skip to content

Commit

Permalink
Enable ssh forwarding when building a remote target
Browse files Browse the repository at this point in the history
- this fixes moby/buildkit#2040 by enabling
ssh forwarding when a remote address is given on the command line, this
is a similar fix to docker/buildx#581

Signed-off-by: Alex Couture-Beil <[email protected]>
  • Loading branch information
alexcb committed Apr 21, 2021
1 parent 2e97bc2 commit c551a1e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cli/command/image/build_buildkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/moby/buildkit/session/secrets/secretsprovider"
"github.com/moby/buildkit/session/sshforward/sshprovider"
"github.com/moby/buildkit/util/appcontext"
"github.com/moby/buildkit/util/gitutil"
"github.com/moby/buildkit/util/progress/progressui"
"github.com/moby/buildkit/util/progress/progresswriter"
"github.com/pkg/errors"
Expand Down Expand Up @@ -186,10 +187,15 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
}
s.Allow(sp)
}
if len(options.ssh) > 0 {
sshp, err := parseSSHSpecs(options.ssh)

sshSpecs := options.ssh
if len(sshSpecs) == 0 && isGitSSH(remote) {
sshSpecs = []string{"default"}
}
if len(sshSpecs) > 0 {
sshp, err := parseSSHSpecs(sshSpecs)
if err != nil {
return errors.Wrapf(err, "could not parse ssh: %v", options.ssh)
return errors.Wrapf(err, "could not parse ssh: %v", sshSpecs)
}
s.Allow(sshp)
}
Expand Down Expand Up @@ -512,3 +518,8 @@ func parseSSH(value string) *sshprovider.AgentConfig {
}
return &cfg
}

func isGitSSH(url string) bool {
_, gitProtocol := gitutil.ParseProtocol(url)
return gitProtocol == gitutil.SSHProtocol
}

0 comments on commit c551a1e

Please sign in to comment.