@@ -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