Skip to content

Commit 289d6af

Browse files
committed
Merge remote-tracking branch 'origin' into fix-docker-ignore-2
2 parents 6d243ea + bd53321 commit 289d6af

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

pkg/build/build.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/moby/buildkit/client"
3131
"github.com/moby/buildkit/cmd/buildctl/build"
3232
"github.com/moby/buildkit/session"
33+
"github.com/moby/buildkit/session/secrets/secretsprovider"
3334
"github.com/sirupsen/logrus"
3435
"github.com/tonistiigi/go-csvvalue"
3536
"google.golang.org/grpc"
@@ -128,6 +129,7 @@ func Build(ctx context.Context, opts *BOpts) error {
128129
CacheExports: cacheExports,
129130
Session: []session.Attachable{
130131
opts.FSSync,
132+
secretsprovider.FromMap(opts.Secrets),
131133
},
132134
FrontendAttrs: map[string]string{},
133135
}

pkg/build/buildopts.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ const (
6060
KeyLabels = "labels"
6161
// ARG key=value pairs passed to the Dockerfile.
6262
KeyBuildArgs = "build-args"
63+
// RUN --mount=type=secret,... id:value pairs passed to the Dockerfile.
64+
KeySecrets = "secrets"
6365
// Cache import sources.
6466
KeyCacheIn = "cache-in"
6567
// Cache export destinations.
@@ -87,6 +89,7 @@ type BOpts struct {
8789
NoCache bool
8890
Target string
8991
BuildArgs map[string]string
92+
Secrets map[string][]byte
9093
CacheIn []string
9194
CacheOut []string
9295
Outputs []string
@@ -198,9 +201,34 @@ func NewBuildOpts(ctx context.Context, basePath string, contextMap map[string][]
198201
}
199202
return args
200203
}
204+
mapExtractB64 := func(key string) (map[string][]byte, error) {
205+
values, ok := contextMap[key]
206+
if !ok {
207+
return map[string][]byte{}, nil
208+
}
209+
args := map[string][]byte{}
210+
for _, label := range values {
211+
parts := strings.SplitN(label, "=", 2)
212+
switch len(parts) {
213+
case 1:
214+
args[parts[0]] = []byte{}
215+
case 2:
216+
dat, err := base64.StdEncoding.DecodeString(parts[1])
217+
if err != nil {
218+
return nil, err
219+
}
220+
args[parts[0]] = dat
221+
}
222+
}
223+
return args, nil
224+
}
201225

202226
labels := mapExtract(KeyLabels)
203227
buildArgs := mapExtract(KeyBuildArgs)
228+
secrets, err := mapExtractB64(KeySecrets)
229+
if err != nil {
230+
return nil, err
231+
}
204232
cacheIn := contextMap[KeyCacheIn]
205233
cacheOut := contextMap[KeyCacheOut]
206234
outputs := contextMap[KeyOutput]
@@ -292,6 +320,7 @@ func NewBuildOpts(ctx context.Context, basePath string, contextMap map[string][]
292320
Target: target,
293321
Labels: labels,
294322
BuildArgs: buildArgs,
323+
Secrets: secrets,
295324
CacheIn: cacheIn,
296325
CacheOut: cacheOut,
297326
Outputs: outputs,

0 commit comments

Comments
 (0)