github.com/rumpl/bof@v23.0.0-rc.2+incompatible/daemon/config/builder.go (about) 1 package config 2 3 import ( 4 "encoding/json" 5 "sort" 6 "strings" 7 8 "github.com/docker/docker/api/types/filters" 9 ) 10 11 // BuilderGCRule represents a GC rule for buildkit cache 12 type BuilderGCRule struct { 13 All bool `json:",omitempty"` 14 Filter BuilderGCFilter `json:",omitempty"` 15 KeepStorage string `json:",omitempty"` 16 } 17 18 // BuilderGCFilter contains garbage-collection filter rules for a BuildKit builder 19 type BuilderGCFilter filters.Args 20 21 // MarshalJSON returns a JSON byte representation of the BuilderGCFilter 22 func (x *BuilderGCFilter) MarshalJSON() ([]byte, error) { 23 f := filters.Args(*x) 24 keys := f.Keys() 25 sort.Strings(keys) 26 arr := make([]string, 0, len(keys)) 27 for _, k := range keys { 28 values := f.Get(k) 29 for _, v := range values { 30 arr = append(arr, k+"="+v) 31 } 32 } 33 return json.Marshal(arr) 34 } 35 36 // UnmarshalJSON fills the BuilderGCFilter values structure from JSON input 37 func (x *BuilderGCFilter) UnmarshalJSON(data []byte) error { 38 var arr []string 39 f := filters.NewArgs() 40 if err := json.Unmarshal(data, &arr); err != nil { 41 // backwards compat for deprecated buggy form 42 err := json.Unmarshal(data, &f) 43 *x = BuilderGCFilter(f) 44 return err 45 } 46 for _, s := range arr { 47 name, value, _ := strings.Cut(s, "=") 48 name = strings.ToLower(strings.TrimSpace(name)) 49 value = strings.TrimSpace(value) 50 f.Add(name, value) 51 } 52 *x = BuilderGCFilter(f) 53 return nil 54 } 55 56 // BuilderGCConfig contains GC config for a buildkit builder 57 type BuilderGCConfig struct { 58 Enabled bool `json:",omitempty"` 59 Policy []BuilderGCRule `json:",omitempty"` 60 DefaultKeepStorage string `json:",omitempty"` 61 } 62 63 // BuilderEntitlements contains settings to enable/disable entitlements 64 type BuilderEntitlements struct { 65 NetworkHost *bool `json:"network-host,omitempty"` 66 SecurityInsecure *bool `json:"security-insecure,omitempty"` 67 } 68 69 // BuilderConfig contains config for the builder 70 type BuilderConfig struct { 71 GC BuilderGCConfig `json:",omitempty"` 72 Entitlements BuilderEntitlements `json:",omitempty"` 73 }