Skip to content

Commit

Permalink
Merge pull request #34 from ZozoZoeLi/master
Browse files Browse the repository at this point in the history
add --ssh option
  • Loading branch information
xtremerui authored Jun 21, 2021
2 parents e8322b2 + 25097e0 commit 35fd63a
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ Next, any of the following optional parameters may be specified:
* `$DOCKERFILE` (default `$CONTEXT/Dockerfile`): the path to the `Dockerfile`
to build.

* `$BUILDKIT_SSH` your ssh key location that is mounted in your `Dockerfile`. This is
generally used for pulling dependencies from private repositories.

For Example. In your `Dockerfile`, you can mount a key as
```
RUN --mount=type=ssh,id=github_ssh_key pip install -U -r ./hats/requirements-test.txt
```
Then in your Concourse YAML configuration:
```
params:
BUILDKIT_SSH: github_ssh_key=<PATH-TO-YOUR-KEY>
```
Read more about ssh mount [here](https://docs.docker.com/develop/develop-images/build_enhancements/).
* `$BUILD_ARG_*`: params prefixed with `BUILD_ARG_` will be provided as build
args. For example `BUILD_ARG_foo=bar`, will set the `foo` build arg as `bar`.
Expand Down
6 changes: 6 additions & 0 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ func Build(buildkitd *Buildkitd, outputsDir string, req Request) (Response, erro
)
}

if cfg.BuildkitSSH != "" {
buildctlArgs = append(buildctlArgs,
"--ssh", cfg.BuildkitSSH,
)
}

builds = append(builds, buildctlArgs)
targets = append(targets, "")

Expand Down
8 changes: 8 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ func (s *TaskSuite) TestTarget() {
s.NoError(err)
}

func (s *TaskSuite) TestBuildkitSSH() {
s.req.Config.ContextDir = "testdata/buildkit-ssh"
s.req.Config.BuildkitSSH = "my_ssh_key=./id_rsa_test"

_, err := s.build()
s.NoError(err)
}

func (s *TaskSuite) TestTargetFile() {
s.req.Config.ContextDir = "testdata/target"
s.req.Config.TargetFile = "testdata/target/target_file"
Expand Down
5 changes: 5 additions & 0 deletions testdata/buildkit-ssh/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# syntax = docker/dockerfile:1.0-experimental
FROM alpine

# shows secret from custom secret location:
RUN --mount=type=secret,id=my_ssh_key cat ./id_rsa_test
49 changes: 49 additions & 0 deletions testdata/buildkit-ssh/id_rsa_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAgEArNG0wYPOc/emyQKvfX6aPIyTqB8xTA7qaHrEQI5ljLrE7FdF702z
sQijG+0i4R9X5TGf/kLLmmQBXHKnfgfIGzh1/zKHRc+s9fM+fcgrTQD5Ybsj0U+rRMKtoQ
ypJSqGYfTAbhXYxCEOpjUTphtheuxhuDtoSpt2mcE75U78EyzsBM2oEorvLZWv8G70FiOA
9rw/RMGzxtsp9pBDPhgbMPnQXB9euILq7VjtuS8kqnlqgYpsgISGt+W90okIcbEf5Cr+c/
J0WUoGnMqy8b4WXU0dJsxsSY2rVitXuykIBm6WJfKcKeF6fdZv9Yh7qr5yzKhzuPtgvCS1
UFD752ZUsTa+XIFF+XD3ZpnatLDlDdDqYHIQjMkYeI9DWXmIzI4GmqY1PMAylZAcoFc2el
R0084QigStcUQbHaFXXg7yUJuz/A/WKxlpkcMZ+3sjbScEV3Y26HdS1LyqOI8hgQL11jm0
rApxQTln4NkS5UdrfZ7tlXi7lTeLZJUjiuOs63UsUd++z/a1k8o8rYuC+2cmRjlco+qUlD
ShA1IvzGDSLLVr9Im+ZRDtrbL+6PaXbzqX1wwsow/XwgsHDIO8O57TvCM0akEzHsRUw+5B
lJhXURQOko8i2Acs+yc1DgGWugXwFokE6+i66v6X0iFGrei0C3yKqVIBisav9TYlveYi6B
EAAAdYY2LAYGNiwGAAAAAH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+FJWW593EigjfCsCxyovsCu7eCVDTNqj58GmVO5
jwpX7AcTJ9sbck1cajPJJJonOa9qNf2UQDgoB7SJ+9Zw+aNaLFfFBsCHOouuUFrDjTDf1M
j8FJpV33Qt2VCbPMZwkwFgtQhhMSJbrUv1wZhDfW7WMKRBV1QOeGX+GlW30GnSobxlFKUS
mDMYAtsRHa/4+w/itOQgQT6e2nPYlwofMbrZxReaAUMAvt6RwZyoUJ9+gStuQ7gLYvG4Nt
ou1ZzGDYavhTRsywAMfkQ9CN9fSqieafDTcqcBi2XcCx7IrbDCLYJZA3zB6HFzgGvF/plG
gy40fbJ6LUkAAAAcem9lbGlAWm9lcy1NYWNCb29rLVByby5sb2NhbAECAwQFBgc=
-----END OPENSSH PRIVATE KEY-----
1 change: 1 addition & 0 deletions testdata/buildkit-ssh/id_rsa_test.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCs0bTBg85z96bJAq99fpo8jJOoHzFMDupoesRAjmWMusTsV0XvTbOxCKMb7SLhH1flMZ/+QsuaZAFccqd+B8gbOHX/ModFz6z18z59yCtNAPlhuyPRT6tEwq2hDKklKoZh9MBuFdjEIQ6mNROmG2F67GG4O2hKm3aZwTvlTvwTLOwEzagSiu8tla/wbvQWI4D2vD9EwbPG2yn2kEM+GBsw+dBcH164gurtWO25LySqeWqBimyAhIa35b3SiQhxsR/kKv5z8nRZSgacyrLxvhZdTR0mzGxJjatWK1e7KQgGbpYl8pwp4Xp91m/1iHuqvnLMqHO4+2C8JLVQUPvnZlSxNr5cgUX5cPdmmdq0sOUN0OpgchCMyRh4j0NZeYjMjgaapjU8wDKVkBygVzZ6VHTTzhCKBK1xRBsdoVdeDvJQm7P8D9YrGWmRwxn7eyNtJwRXdjbod1LUvKo4jyGBAvXWObSsCnFBOWfg2RLlR2t9nu2VeLuVN4tklSOK46zrdSxR377P9rWTyjyti4L7ZyZGOVyj6pSUNKEDUi/MYNIstWv0ib5lEO2tsv7o9pdvOpfXDCyjD9fCCwcMg7w7ntO8IzRqQTMexFTD7kGUmFdRFA6SjyLYByz7JzUOAZa6BfAWiQTr6Lrq/pfSIUat6LQLfIqpUgGKxq/1NiW95iLoEQ== [email protected]
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Config struct {

ContextDir string `json:"context" envconfig:"CONTEXT,optional"`
DockerfilePath string `json:"dockerfile,omitempty" envconfig:"DOCKERFILE,optional"`
BuildkitSSH string `json:"buildkit_ssh" envconfig:"optional"`

Target string `json:"target" envconfig:"optional"`
TargetFile string `json:"target_file" envconfig:"optional"`
Expand Down

0 comments on commit 35fd63a

Please sign in to comment.