2018-09-04 22:12:44 -04:00
|
|
|
package config
|
|
|
|
|
2019-09-24 13:53:39 -04:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
2019-10-02 20:09:50 -04:00
|
|
|
"fmt"
|
|
|
|
"sort"
|
2019-09-24 13:53:39 -04:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
)
|
2018-09-04 22:12:44 -04:00
|
|
|
|
|
|
|
// BuilderGCRule represents a GC rule for buildkit cache
|
|
|
|
type BuilderGCRule struct {
|
2019-09-24 13:53:39 -04:00
|
|
|
All bool `json:",omitempty"`
|
|
|
|
Filter BuilderGCFilter `json:",omitempty"`
|
|
|
|
KeepStorage string `json:",omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-10-21 15:34:05 -04:00
|
|
|
// BuilderGCFilter contains garbage-collection filter rules for a BuildKit builder
|
2019-09-24 13:53:39 -04:00
|
|
|
type BuilderGCFilter filters.Args
|
|
|
|
|
2019-10-21 15:34:05 -04:00
|
|
|
// MarshalJSON returns a JSON byte representation of the BuilderGCFilter
|
2019-10-02 20:09:50 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-10-21 15:34:05 -04:00
|
|
|
// UnmarshalJSON fills the BuilderGCFilter values structure from JSON input
|
2019-09-24 13:53:39 -04:00
|
|
|
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
|
2018-09-04 22:12:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// BuilderGCConfig contains GC config for a buildkit builder
|
|
|
|
type BuilderGCConfig struct {
|
|
|
|
Enabled bool `json:",omitempty"`
|
|
|
|
Policy []BuilderGCRule `json:",omitempty"`
|
|
|
|
DefaultKeepStorage string `json:",omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-04-26 02:04:34 -04:00
|
|
|
// BuilderEntitlements contains settings to enable/disable entitlements
|
|
|
|
type BuilderEntitlements struct {
|
|
|
|
NetworkHost *bool `json:"network-host,omitempty"`
|
|
|
|
SecurityInsecure *bool `json:"security-insecure,omitempty"`
|
|
|
|
}
|
|
|
|
|
2018-09-04 22:12:44 -04:00
|
|
|
// BuilderConfig contains config for the builder
|
|
|
|
type BuilderConfig struct {
|
2019-04-26 02:04:34 -04:00
|
|
|
GC BuilderGCConfig `json:",omitempty"`
|
|
|
|
Entitlements BuilderEntitlements `json:",omitempty"`
|
2018-09-04 22:12:44 -04:00
|
|
|
}
|