github.com/moby/docker@v26.1.3+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 bkconfig "github.com/moby/buildkit/cmd/buildkitd/config" 10 ) 11 12 // BuilderGCRule represents a GC rule for buildkit cache 13 type BuilderGCRule struct { 14 All bool `json:",omitempty"` 15 Filter BuilderGCFilter `json:",omitempty"` 16 KeepStorage string `json:",omitempty"` 17 } 18 19 // BuilderGCFilter contains garbage-collection filter rules for a BuildKit builder 20 type BuilderGCFilter filters.Args 21 22 // MarshalJSON returns a JSON byte representation of the BuilderGCFilter 23 func (x *BuilderGCFilter) MarshalJSON() ([]byte, error) { 24 f := filters.Args(*x) 25 keys := f.Keys() 26 sort.Strings(keys) 27 arr := make([]string, 0, len(keys)) 28 for _, k := range keys { 29 values := f.Get(k) 30 for _, v := range values { 31 arr = append(arr, k+"="+v) 32 } 33 } 34 return json.Marshal(arr) 35 } 36 37 // UnmarshalJSON fills the BuilderGCFilter values structure from JSON input 38 func (x *BuilderGCFilter) UnmarshalJSON(data []byte) error { 39 var arr []string 40 f := filters.NewArgs() 41 if err := json.Unmarshal(data, &arr); err != nil { 42 // backwards compat for deprecated buggy form 43 err := json.Unmarshal(data, &f) 44 *x = BuilderGCFilter(f) 45 return err 46 } 47 for _, s := range arr { 48 name, value, _ := strings.Cut(s, "=") 49 name = strings.ToLower(strings.TrimSpace(name)) 50 value = strings.TrimSpace(value) 51 f.Add(name, value) 52 } 53 *x = BuilderGCFilter(f) 54 return nil 55 } 56 57 // BuilderGCConfig contains GC config for a buildkit builder 58 type BuilderGCConfig struct { 59 Enabled bool `json:",omitempty"` 60 Policy []BuilderGCRule `json:",omitempty"` 61 DefaultKeepStorage string `json:",omitempty"` 62 } 63 64 // BuilderHistoryConfig contains history config for a buildkit builder 65 type BuilderHistoryConfig struct { 66 MaxAge bkconfig.Duration `json:",omitempty"` 67 MaxEntries int64 `json:",omitempty"` 68 } 69 70 // BuilderEntitlements contains settings to enable/disable entitlements 71 type BuilderEntitlements struct { 72 NetworkHost *bool `json:"network-host,omitempty"` 73 SecurityInsecure *bool `json:"security-insecure,omitempty"` 74 } 75 76 // BuilderConfig contains config for the builder 77 type BuilderConfig struct { 78 GC BuilderGCConfig `json:",omitempty"` 79 Entitlements BuilderEntitlements `json:",omitempty"` 80 History *BuilderHistoryConfig `json:",omitempty"` 81 }