@@ -176,18 +176,7 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
176
176
}
177
177
}
178
178
179
- // tmpSecrets stores secret set by environment variables, so we don't have to "pollute" bake process's environment
180
- tmpSecrets , err := os .MkdirTemp ("" , "secrets" )
181
- if err != nil {
182
- return nil , err
183
- }
184
- defer func () {
185
- rerr := os .RemoveAll (tmpSecrets )
186
- if rerr != nil {
187
- logrus .Warnf ("Failed to removed temporary secrets directory %s: %s" , tmpSecrets , rerr .Error ())
188
- }
189
- }()
190
-
179
+ var secretsEnv []string
191
180
for serviceName , service := range project .Services {
192
181
if service .Build == nil {
193
182
continue
@@ -244,10 +233,12 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
244
233
245
234
target := targets [serviceName ]
246
235
247
- secrets , err := toBakeSecrets (project , build .Secrets , tmpSecrets )
236
+ secrets , env , err := toBakeSecrets (project , build .Secrets )
248
237
if err != nil {
249
238
return nil , err
250
239
}
240
+ secretsEnv = append (secretsEnv , env ... )
241
+
251
242
cfg .Targets [target ] = bakeTarget {
252
243
Context : build .Context ,
253
244
Contexts : additionalContexts (build .AdditionalContexts , targets ),
@@ -357,6 +348,7 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
357
348
return nil , err
358
349
}
359
350
cmd .Env = append (cmd .Env , endpoint ... )
351
+ cmd .Env = append (cmd .Env , secretsEnv ... )
360
352
defer cleanup ()
361
353
362
354
cmd .Stdout = s .stdout ()
@@ -471,8 +463,9 @@ func toBakeSSH(ssh types.SSHConfig) []string {
471
463
return s
472
464
}
473
465
474
- func toBakeSecrets (project * types.Project , secrets []types.ServiceSecretConfig , tmpSecrets string ) ([]string , error ) {
466
+ func toBakeSecrets (project * types.Project , secrets []types.ServiceSecretConfig ) ([] string , []string , error ) {
475
467
var s []string
468
+ var env []string
476
469
for _ , ref := range secrets {
477
470
def := project .Secrets [ref .Source ]
478
471
target := ref .Target
@@ -481,17 +474,14 @@ func toBakeSecrets(project *types.Project, secrets []types.ServiceSecretConfig,
481
474
}
482
475
switch {
483
476
case def .Environment != "" :
484
- sf := filepath .Join (tmpSecrets , def .Environment )
485
- err := os .WriteFile (sf , []byte (project .Environment [def .Environment ]), 0o600 )
486
- if err != nil {
487
- return nil , err
488
- }
489
- s = append (s , fmt .Sprintf ("id=%s,type=file,src=%s" , target , sf ))
477
+ sec := project .Environment [def .Environment ]
478
+ env = append (env , fmt .Sprintf ("%s=%s" , target , sec ))
479
+ s = append (s , fmt .Sprintf ("id=%s,type=env,env=%s" , target , def .Environment ))
490
480
case def .File != "" :
491
481
s = append (s , fmt .Sprintf ("id=%s,type=file,src=%s" , target , def .File ))
492
482
}
493
483
}
494
- return s , nil
484
+ return s , env , nil
495
485
}
496
486
497
487
func toBakeAttest (build types.BuildConfig ) []string {
0 commit comments