-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dockerfile: add support for RUN --mount=type=ssh
* Needs to be compiled with `dfrunmount dfssh` * Implemented options: * `type`(required): needs to be `ssh` * `target`(optional): the socket path in the container * `id`(optional): id Test script: #!/bin/bash set -exu -o pipefail REF=localhost:5000/dfssh:latest ssh-add -l sudo buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=frontend/dockerfile/cmd/dockerfile-frontend \ --frontend-opt "build-arg:BUILDTAGS=dfrunmount dfssh" \ --exporter=image --exporter-opt name=$REF --exporter-opt push=true mkdir -p /tmp/foo cd /tmp/foo cat << EOF > Dockerfile # syntax=$REF FROM alpine RUN apk add --no-cache openssh-client RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan gitlab.com >> ~/.ssh/known_hosts RUN --mount=type=ssh ssh [email protected] # "Welcome to GitLab, @GITLAB_USERNAME_ASSOCIATED_WITH_SSHKEY" should be printed here EOF sudo buildctl build --ssh default=$SSH_AUTH_SOCK --progress=plain --frontend=dockerfile.v0 --local context=. --local dockerfile=. Signed-off-by: Akihiro Suda <[email protected]>
- Loading branch information
1 parent
cc8d59e
commit fa92eff
Showing
8 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// +build dfrunmount,!dfssh | ||
|
||
package dockerfile2llb | ||
|
||
import ( | ||
"github.com/moby/buildkit/client/llb" | ||
"github.com/moby/buildkit/frontend/dockerfile/instructions" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func dispatchSSH(m *instructions.Mount) (llb.RunOption, error) { | ||
return nil, errors.Errorf("ssh mounts not allowed") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// +build dfssh dfextall | ||
|
||
package dockerfile2llb | ||
|
||
import ( | ||
"github.com/moby/buildkit/client/llb" | ||
"github.com/moby/buildkit/frontend/dockerfile/instructions" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func dispatchSSH(m *instructions.Mount) (llb.RunOption, error) { | ||
if m.Source != "" { | ||
return nil, errors.Errorf("ssh does not support source") | ||
} | ||
opts := []llb.SSHOption{llb.SSHID(m.CacheID)} | ||
|
||
if m.Target != "" { | ||
// TODO(AkihiroSuda): support specifying permission bits | ||
opts = append(opts, llb.SSHSocketTarget(m.Target)) | ||
} | ||
|
||
if !m.Required { | ||
opts = append(opts, llb.SSHOptional) | ||
} | ||
|
||
return llb.AddSSHSocket(opts...), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build !dfssh,!dfextall | ||
|
||
package instructions | ||
|
||
func isSSHMountsSupported() bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build dfssh dfextall | ||
|
||
package instructions | ||
|
||
func isSSHMountsSupported() bool { | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters