forked from moby/buildkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
verifier: verify platforms of the build result
Check that the result returned from the frontend matches the user request conventions and show a warning if it doesn't. Signed-off-by: Tonis Tiigi <[email protected]>
- Loading branch information
1 parent
dd6acb2
commit acb1bed
Showing
5 changed files
with
364 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package verifier | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
|
||
"github.com/containerd/containerd/platforms" | ||
"github.com/moby/buildkit/solver/result" | ||
) | ||
|
||
const requestOptsKeys = "verifier.requestopts" | ||
|
||
const ( | ||
platformsKey = "platform" | ||
labelsPrefix = "label:" | ||
keyRequestID = "requestid" | ||
) | ||
|
||
type RequestOpts struct { | ||
Platforms []string | ||
Labels map[string]string | ||
Request string | ||
} | ||
|
||
func CaptureFrontendOpts[T comparable](m map[string]string, res *result.Result[T]) error { | ||
req := &RequestOpts{} | ||
if v, ok := m[platformsKey]; ok { | ||
req.Platforms = strings.Split(v, ",") | ||
} else { | ||
req.Platforms = []string{platforms.Format(platforms.Normalize(platforms.DefaultSpec()))} | ||
} | ||
|
||
req.Labels = map[string]string{} | ||
for k, v := range m { | ||
if strings.HasPrefix(k, labelsPrefix) { | ||
req.Labels[strings.TrimPrefix(k, labelsPrefix)] = v | ||
} | ||
} | ||
req.Request = m[keyRequestID] | ||
|
||
dt, err := json.Marshal(req) | ||
if err != nil { | ||
return err | ||
} | ||
res.AddMeta(requestOptsKeys, dt) | ||
return nil | ||
} | ||
|
||
func getRequestOpts[T comparable](res *result.Result[T]) (*RequestOpts, error) { | ||
dt, ok := res.Metadata[requestOptsKeys] | ||
if !ok { | ||
return nil, nil | ||
} | ||
req := &RequestOpts{} | ||
if err := json.Unmarshal(dt, req); err != nil { | ||
return nil, err | ||
} | ||
return req, nil | ||
} |
Oops, something went wrong.