Skip to content

Commit

Permalink
buildinfo: filter out control args
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Feb 3, 2022
1 parent c9f9987 commit 1c9d13d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions util/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,16 @@ var knownAttrs = []string{
func filterAttrs(attrs map[string]string) map[string]string {
filtered := make(map[string]string)
for k, v := range attrs {
// Control args are filtered out
if isControlArg(k) {
continue
}
// Always include args and labels
if strings.HasPrefix(k, "build-arg:") || strings.HasPrefix(k, "label:") {
filtered[k] = v
continue
}
// Filter only for known attributes
for _, knownAttr := range knownAttrs {
if knownAttr == k {
filtered[k] = v
Expand All @@ -212,3 +218,23 @@ func filterAttrs(attrs map[string]string) map[string]string {
}
return filtered
}

var knownControlArgs = []string{
"BUILDKIT_CACHE_MOUNT_NS",
"BUILDKIT_CONTEXT_KEEP_GIT_DIR",
"BUILDKIT_INLINE_BUILDINFO_ATTRS",
"BUILDKIT_INLINE_CACHE",
"BUILDKIT_MULTI_PLATFORM",
"BUILDKIT_SANDBOX_HOSTNAME",
"BUILDKIT_SYNTAX",
}

// isControlArg checks if a build attributes is a control arg
func isControlArg(attrKey string) bool {
for _, k := range knownControlArgs {
if strings.HasPrefix(attrKey, "build-arg:"+k) {
return true
}
}
return false
}

0 comments on commit 1c9d13d

Please sign in to comment.