-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathtarget.go
More file actions
140 lines (114 loc) · 4.66 KB
/
target.go
File metadata and controls
140 lines (114 loc) · 4.66 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package dalec
import (
goerrors "errors"
"github.com/moby/buildkit/frontend/dockerfile/shell"
"github.com/pkg/errors"
)
const (
// PreBuiltPkgSuffix is what is expected to be appended to a targetKey when it's
// meant to be a target distro specific package (e.g. mariner2-pkg, azlinux3-pkg,
// windowscross-pkg, bookworm-pkg, etc.). When this is provided and used to buildkit
// and container, it will take precedence over GenericPkg.
PreBuiltPkgSuffix = "-pkg"
// If not a target specific package, but we want to indicate the use of a
// prebuilt package, we use GenericPkg to indicate that it's not target specific.
GenericPkg = "pkg"
)
// Target defines a distro-specific build target.
// This is used in [Spec] to specify the build target for a distro.
type Target struct {
// Dependencies are the different dependencies that need to be specified in the package.
Dependencies *PackageDependencies `yaml:"dependencies,omitempty" json:"dependencies,omitempty"`
// Image is the image configuration when the target output is a container image.
Image *ImageConfig `yaml:"image,omitempty" json:"image,omitempty"`
// Frontend is the frontend configuration to use for the target.
// This is used to forward the build to a different, dalec-compatible frontend.
// This can be useful when testing out new distros or using a different version of the frontend for a given distro.
Frontend *Frontend `yaml:"frontend,omitempty" json:"frontend,omitempty"`
// Tests are the list of tests to run which are specific to the target.
// Tests are appended to the list of tests in the main [Spec]
Tests []*TestSpec `yaml:"tests,omitempty" json:"tests,omitempty"`
// PackageConfig is the configuration to use for artifact targets, such as
// rpms, debs, or zip files containing Windows binaries
PackageConfig *PackageConfig `yaml:"package_config,omitempty" json:"package_config,omitempty"`
// Artifacts describes all of the artifact configurations to include for this specific target.
Artifacts *Artifacts `yaml:"artifacts,omitempty" json:"artifacts,omitempty"`
// Provides is the list of packages that this target provides.
Provides PackageDependencyList `yaml:"provides,omitempty" json:"provides,omitempty"`
// Replaces is the list of packages that this target replaces/obsoletes.
Replaces PackageDependencyList `yaml:"replaces,omitempty" json:"replaces,omitempty"`
// Conflicts is the list of packages that this target conflicts with.
Conflicts PackageDependencyList `yaml:"conflicts,omitempty" json:"conflicts,omitempty"`
}
func (t *Target) validate() error {
var errs []error
if err := t.Dependencies.validate(); err != nil {
errs = append(errs, errors.Wrap(err, "dependencies"))
}
if err := t.Image.validate(); err != nil {
errs = append(errs, errors.Wrap(err, "image"))
}
for _, test := range t.Tests {
if err := test.validate(); err != nil {
errs = append(errs, errors.Wrapf(err, "test %s", test.Name))
}
}
if err := t.Image.validate(); err != nil {
errs = append(errs, errors.Wrap(err, "postinstall"))
}
return goerrors.Join(errs...)
}
func (t *Target) processBuildArgs(lex *shell.Lex, args map[string]string, allowArg func(string) bool) error {
var errs []error
for _, tt := range t.Tests {
if err := tt.processBuildArgs(lex, args, allowArg); err != nil {
errs = append(errs, err)
}
}
if t.PackageConfig != nil {
if err := t.PackageConfig.processBuildArgs(lex, args, allowArg); err != nil {
errs = append(errs, errors.Wrap(err, "package config"))
}
}
if err := t.Image.processBuildArgs(lex, args, allowArg); err != nil {
errs = append(errs, errors.Wrap(err, "package config"))
}
if err := t.Dependencies.processBuildArgs(lex, args, allowArg); err != nil {
errs = append(errs, errors.Wrap(err, "dependencies"))
}
for k, v := range t.Provides {
for i, ver := range v.Version {
updated, err := expandArgs(lex, ver, args, allowArg)
if err != nil {
errs = append(errs, errors.Wrapf(err, "provides %s version %d", k, i))
continue
}
t.Provides[k].Version[i] = updated
}
}
for k, v := range t.Replaces {
for i, ver := range v.Version {
updated, err := expandArgs(lex, ver, args, allowArg)
if err != nil {
errs = append(errs, errors.Wrapf(err, "replaces %s version %d", k, i))
continue
}
t.Replaces[k].Version[i] = updated
}
}
for k, v := range t.Conflicts {
for i, ver := range v.Version {
updated, err := expandArgs(lex, ver, args, allowArg)
if err != nil {
errs = append(errs, errors.Wrapf(err, "conflicts %s version %d", k, i))
continue
}
t.Conflicts[k].Version[i] = updated
}
}
return goerrors.Join(errs...)
}
func (t *Target) fillDefaults() {
t.Dependencies.fillDefaults()
t.Image.fillDefaults()
}