From c60afbb25ba0fda069aaed02b752f01188ea633d Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 16 Sep 2024 16:30:04 -0700 Subject: [PATCH] bake: fix linking to targets with entitlements When linked target requires entitlement, same entitlement is also needed by the caller. Otherwise, the request will fail when the build is processed. Signed-off-by: Tonis Tiigi --- bake/bake.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bake/bake.go b/bake/bake.go index 3a50f7b4..079ab0d2 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -7,6 +7,7 @@ import ( "path" "path/filepath" "regexp" + "slices" "sort" "strconv" "strings" @@ -502,6 +503,14 @@ func (c Config) loadLinks(name string, t *Target, m map[string]*Target, o map[st if err := c.loadLinks(target, t2, m, o, visited); err != nil { return err } + + // entitlements are inherited from linked targets + for _, ent := range t2.Entitlements { + if !slices.Contains(t.Entitlements, ent) { + t.Entitlements = append(t.Entitlements, ent) + } + } + if len(t.Platforms) > 1 && len(t2.Platforms) > 1 { if !sliceEqual(t.Platforms, t2.Platforms) { return errors.Errorf("target %s can't be used by %s because it is defined for different platforms %v and %v", target, name, t2.Platforms, t.Platforms)