Skip to content

Commit

Permalink
fix bake support for secret target
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Jan 27, 2025
1 parent 707f3d1 commit c87bddd
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions pkg/compose/build_bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,20 @@ type bakeGroup struct {
}

type bakeTarget struct {
Context string `json:"context,omitempty"`
Dockerfile string `json:"dockerfile,omitempty"`
Args map[string]string `json:"args,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Tags []string `json:"tags,omitempty"`
CacheFrom []string `json:"cache-from,omitempty"`
CacheTo []string `json:"cache-to,omitempty"`
Secrets []string `json:"secret,omitempty"`
SSH []string `json:"ssh,omitempty"`
Platforms []string `json:"platforms,omitempty"`
Target string `json:"target,omitempty"`
Pull bool `json:"pull,omitempty"`
NoCache bool `json:"no-cache,omitempty"`
Context string `json:"context,omitempty"`
Dockerfile string `json:"dockerfile,omitempty"`
Args map[string]string `json:"args,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Tags []string `json:"tags,omitempty"`
CacheFrom []string `json:"cache-from,omitempty"`
CacheTo []string `json:"cache-to,omitempty"`
Secrets []string `json:"secret,omitempty"`
SSH []string `json:"ssh,omitempty"`
Platforms []string `json:"platforms,omitempty"`
Target string `json:"target,omitempty"`
Pull bool `json:"pull,omitempty"`
NoCache bool `json:"no-cache,omitempty"`
Entitlements []string `json:"entitlements,omitempty"`
}

type bakeMetadata map[string]buildStatus
Expand Down Expand Up @@ -155,12 +156,13 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project

CacheFrom: build.CacheFrom,
// CacheTo: TODO
Platforms: build.Platforms,
Target: build.Target,
Secrets: toBakeSecrets(project, build.Secrets),
SSH: toBakeSSH(append(build.SSH, options.SSHs...)),
Pull: options.Pull,
NoCache: options.NoCache,
Platforms: build.Platforms,
Target: build.Target,
Secrets: toBakeSecrets(project, build.Secrets),
SSH: toBakeSSH(append(build.SSH, options.SSHs...)),
Pull: options.Pull,
NoCache: options.NoCache,
Entitlements: build.Entitlements,
}
group.Targets = append(group.Targets, image)
}
Expand Down Expand Up @@ -229,7 +231,7 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project

err = eg.Wait()
if err != nil {
return nil, err
return nil, WrapCategorisedComposeError(err, BuildFailure)
}

b, err = os.ReadFile(metadata.Name())
Expand Down Expand Up @@ -263,11 +265,15 @@ func toBakeSecrets(project *types.Project, secrets []types.ServiceSecretConfig)
var s []string
for _, ref := range secrets {
def := project.Secrets[ref.Source]
target := ref.Target
if target == "" {
target = ref.Source
}
switch {
case def.Environment != "":
s = append(s, fmt.Sprintf("id=%s,type=env,env=%s", ref.Source, def.Environment))
s = append(s, fmt.Sprintf("id=%s,type=env,env=%s", target, def.Environment))
case def.File != "":
s = append(s, fmt.Sprintf("id=%s,type=file,src=%s", ref.Source, def.File))
s = append(s, fmt.Sprintf("id=%s,type=file,src=%s", target, def.File))
}
}
return s
Expand Down

0 comments on commit c87bddd

Please sign in to comment.