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