fix collect image digests for service images built by bake
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
0403f0d76d
commit
9c998a934f
@ -124,6 +124,7 @@ type bakeMetadata map[string]buildStatus
|
|||||||
|
|
||||||
type buildStatus struct {
|
type buildStatus struct {
|
||||||
Digest string `json:"containerimage.digest"`
|
Digest string `json:"containerimage.digest"`
|
||||||
|
Image string `json:"image.name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) doBuildBake(ctx context.Context, project *types.Project, serviceToBeBuild types.Services, options api.BuildOptions) (map[string]string, error) { //nolint:gocyclo
|
func (s *composeService) doBuildBake(ctx context.Context, project *types.Project, serviceToBeBuild types.Services, options api.BuildOptions) (map[string]string, error) { //nolint:gocyclo
|
||||||
@ -142,9 +143,12 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
|
|||||||
Groups: map[string]bakeGroup{},
|
Groups: map[string]bakeGroup{},
|
||||||
Targets: map[string]bakeTarget{},
|
Targets: map[string]bakeTarget{},
|
||||||
}
|
}
|
||||||
var group bakeGroup
|
var (
|
||||||
var privileged bool
|
group bakeGroup
|
||||||
var read []string
|
privileged bool
|
||||||
|
read []string
|
||||||
|
expectedImages = make(map[string]string, len(serviceToBeBuild)) // service name -> expected image
|
||||||
|
)
|
||||||
|
|
||||||
for serviceName, service := range serviceToBeBuild {
|
for serviceName, service := range serviceToBeBuild {
|
||||||
if service.Build == nil {
|
if service.Build == nil {
|
||||||
@ -161,6 +165,7 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
|
|||||||
}
|
}
|
||||||
|
|
||||||
image := api.GetImageNameOrDefault(service, project.Name)
|
image := api.GetImageNameOrDefault(service, project.Name)
|
||||||
|
expectedImages[serviceName] = image
|
||||||
|
|
||||||
entitlements := build.Entitlements
|
entitlements := build.Entitlements
|
||||||
if slices.Contains(build.Entitlements, "security.insecure") {
|
if slices.Contains(build.Entitlements, "security.insecure") {
|
||||||
@ -324,8 +329,12 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
|
|||||||
|
|
||||||
cw := progress.ContextWriter(ctx)
|
cw := progress.ContextWriter(ctx)
|
||||||
results := map[string]string{}
|
results := map[string]string{}
|
||||||
for name, m := range md {
|
for service, name := range expectedImages {
|
||||||
results[name] = m.Digest
|
built, ok := md[service] // bake target == service name
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("build result not found in Bake metadata for service %s", service)
|
||||||
|
}
|
||||||
|
results[name] = built.Digest
|
||||||
cw.Event(progress.BuiltEvent(name))
|
cw.Event(progress.BuiltEvent(name))
|
||||||
}
|
}
|
||||||
return results, nil
|
return results, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user