forked from kyma-project/test-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
104 lines (94 loc) · 3.82 KB
/
config.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"os"
adoPipelines "github.com/kyma-project/test-infra/pkg/azuredevops/pipelines"
"github.com/kyma-project/test-infra/pkg/sign"
"github.com/kyma-project/test-infra/pkg/tags"
"gopkg.in/yaml.v3"
)
type Config struct {
AdoConfig adoPipelines.Config `yaml:"ado-config,omitempty" json:"ado-config,omitempty"`
// Registry is URL where clean build should land.
Registry Registry `yaml:"registry" json:"registry"`
// DevRegistry is Registry URL where development/dirty images should land.
// If not set then the Registry field is used.
// This field is only valid when running in CI (CI env variable is set to `true`)
DevRegistry Registry `yaml:"dev-registry" json:"dev-registry"`
// Cache options that are directly related to kaniko flags
Cache CacheConfig `yaml:"cache" json:"cache"`
// TagTemplate is go-template field that defines the format of the $_TAG substitution.
// See tags.Tag struct for more information and available fields
TagTemplate tags.Tag `yaml:"tag-template" json:"tag-template"`
// LogFormat defines the format kaniko logs are projected.
// Supported formats are 'color', 'text' and 'json'. Default: 'color'
LogFormat string `yaml:"log-format" json:"log-format"`
// Set this option to strip timestamps out of the built image and make it Reproducible.
Reproducible bool `yaml:"reproducible" json:"reproducible"`
// SignConfig contains custom configuration of signers
// as well as org/repo mapping of enabled signers in specific repository
SignConfig SignConfig `yaml:"sign-config" json:"sign-config"`
}
type SignConfig struct {
// EnabledSigners contains org/repo mapping of enabled signers for each repository
// Use * to enable signer for all repositories
EnabledSigners map[string][]string `yaml:"enabled-signers" json:"enabled-signers"`
// Signers contains configuration for multiple signing backends, which can be used to sign resulting image
Signers []sign.SignerConfig `yaml:"signers" json:"signers"`
}
type CacheConfig struct {
// Enabled sets if kaniko cache is enabled or not
Enabled bool `yaml:"enabled" json:"enabled"`
// CacheRunLayers sets if kaniko should cache run layers
CacheRunLayers bool `yaml:"cache-run-layers" json:"cache-run-layers"`
// CacheCopyLayers sets if kaniko should cache copy layers
CacheCopyLayers bool `yaml:"cache-copy-layers" json:"cache-copy-layers"`
// Remote Docker directory used for cache
CacheRepo string `yaml:"cache-repo" json:"cache-repo"`
}
// ParseConfig parses yaml configuration into Config
func (c *Config) ParseConfig(f []byte) error {
return yaml.Unmarshal(f, c)
}
type Variants map[string]map[string]string
// GetVariants fetches variants from provided file.
// If variant flag is used, it fetches the requested variant.
func GetVariants(variant string, f string, fileGetter func(string) ([]byte, error)) (Variants, error) {
var v Variants
b, err := fileGetter(f)
if err != nil {
if !os.IsNotExist(err) {
return nil, err
}
// variant file not found, skipping
return nil, nil
}
if err := yaml.Unmarshal(b, &v); err != nil {
return nil, err
}
if variant != "" {
va, ok := v[variant]
if !ok {
return nil, fmt.Errorf("requested variant '%s', but it's not present in variants.yaml file", variant)
}
return Variants{variant: va}, nil
}
return v, nil
}
// Registry is a custom type that defines a destination registry provided by config.yaml
type Registry []string
// UnmarshalYAML provides functionality to unmarshal Registry field if it's a string or a list.
// This functionality ensures, that both use cases are supported and there are no breaking changes in the config
func (r *Registry) UnmarshalYAML(value *yaml.Node) error {
var reg string
if err := value.Decode(®); err == nil {
*r = append(*r, reg)
return nil
}
var regs []string
if err := value.Decode(®s); err != nil {
return err
}
*r = regs
return nil
}