@@ -15,6 +15,7 @@ import (
15
15
"github.com/otiai10/copy"
16
16
17
17
"github.com/elastic/elastic-agent/dev-tools/mage/manifest"
18
+ "github.com/elastic/elastic-agent/dev-tools/packaging"
18
19
)
19
20
20
21
const ComponentSpecFileSuffix = ".spec.yml"
@@ -94,157 +95,76 @@ func ChecksumsWithoutManifest(versionedFlatPath string, versionedDropPath string
94
95
}
95
96
96
97
// This is a helper function for flattenDependencies that's used when building from a manifest
97
- func ChecksumsWithManifest (requiredPackage string , versionedFlatPath string , versionedDropPath string , manifestResponse * manifest.Build ) map [string ]string {
98
+ func ChecksumsWithManifest (platform , dependenciesVersion string , versionedFlatPath string , versionedDropPath string , manifestResponse * manifest.Build ) map [string ]string {
98
99
checksums := make (map [string ]string )
99
100
if manifestResponse == nil {
100
101
return checksums
101
102
}
102
103
103
- // Iterate over the component projects in the manifest
104
- projects := manifestResponse .Projects
105
- for componentName := range projects {
106
- // Iterate over the individual package files within each component project
107
- for pkgName := range projects [componentName ].Packages {
108
- // Only care about packages that match the required package constraint (os/arch)
109
- if strings .Contains (pkgName , requiredPackage ) {
110
- // Iterate over the external binaries that we care about for packaging agent
111
- for _ , spec := range manifest .ExpectedBinaries {
112
- // If the individual package doesn't match the expected prefix, then continue
113
- // FIXME temporarily skip fips packages until elastic-agent FIPS is in place
114
- if ! strings .HasPrefix (pkgName , spec .BinaryName ) || strings .Contains (pkgName , "-fips-" ) {
115
- if mg .Verbose () {
116
- log .Printf (">>>>>>> Package [%s] skipped" , pkgName )
117
- }
118
- continue
119
- }
120
-
121
- if mg .Verbose () {
122
- log .Printf (">>>>>>> Package [%s] matches requiredPackage [%s]" , pkgName , requiredPackage )
123
- }
124
-
125
- // Get the version from the component based on the version in the package name
126
- // This is useful in the case where it's an Independent Agent Release, where
127
- // the opted-in projects will be one patch version ahead of the rest of the
128
- // opted-out/previously-released projects
129
- componentVersion := getComponentVersion (componentName , requiredPackage , projects [componentName ])
130
- if mg .Verbose () {
131
- log .Printf (">>>>>>> Component [%s]/[%s] version is [%s]" , componentName , requiredPackage , componentVersion )
132
- }
133
-
134
- // Combine the package name w/ the versioned flat path
135
- fullPath := filepath .Join (versionedFlatPath , pkgName )
136
-
137
- // Eliminate the file extensions to get the proper directory
138
- // name that we need to copy
139
- var dirToCopy string
140
- if strings .HasSuffix (fullPath , ".tar.gz" ) {
141
- dirToCopy = fullPath [:strings .LastIndex (fullPath , ".tar.gz" )]
142
- } else if strings .HasSuffix (fullPath , ".zip" ) {
143
- dirToCopy = fullPath [:strings .LastIndex (fullPath , ".zip" )]
144
- } else {
145
- dirToCopy = fullPath
146
- }
147
- if mg .Verbose () {
148
- log .Printf (">>>>>>> Calculated directory to copy: [%s]" , dirToCopy )
149
- }
150
-
151
- // Set copy options
152
- options := copy.Options {
153
- OnSymlink : func (_ string ) copy.SymlinkAction {
154
- return copy .Shallow
155
- },
156
- Sync : true ,
157
- }
158
- if mg .Verbose () {
159
- log .Printf ("> prepare to copy %s into %s " , dirToCopy , versionedDropPath )
160
- }
161
-
162
- // Do the copy
163
- err := copy .Copy (dirToCopy , versionedDropPath , options )
164
- if err != nil {
165
- panic (err )
166
- }
167
-
168
- // copy spec file for match
169
- specName := filepath .Base (dirToCopy )
170
- idx := strings .Index (specName , "-" + componentVersion )
171
- if idx != - 1 {
172
- specName = specName [:idx ]
173
- }
174
- if mg .Verbose () {
175
- log .Printf (">>>> Looking to copy spec file: [%s]" , specName )
176
- }
177
-
178
- checksum , err := CopyComponentSpecs (specName , versionedDropPath )
179
- if err != nil {
180
- panic (err )
181
- }
182
-
183
- checksums [specName + ComponentSpecFileSuffix ] = checksum
184
- }
104
+ // Iterate over the external binaries that we care about for packaging agent
105
+ for _ , spec := range packaging .ExpectedBinaries {
106
+
107
+ if spec .PythonWheel {
108
+ if mg .Verbose () {
109
+ log .Printf (">>>>>>> Component %s/%s is a Python wheel, skipping" , spec .ProjectName , spec .BinaryName )
185
110
}
111
+ continue
186
112
}
187
- }
188
113
189
- return checksums
190
- }
114
+ if ! spec .SupportsPlatform (platform ) {
115
+ log .Printf (">>>>>>> Component %s/%s does not support platform %s, skipping" , spec .ProjectName , spec .BinaryName , platform )
116
+ continue
117
+ }
191
118
192
- // This function is used when building with a Manifest. In that manifest, it's possible
193
- // for projects in an Independent Agent Release to have different versions since the opted-in
194
- // ones will be one patch version higher than the opted-out/previously released projects.
195
- // This function tries to find the versions from the package name
196
- func getComponentVersion (componentName string , requiredPackage string , componentProject manifest.Project ) string {
197
- var componentVersion string
198
- var foundIt bool
199
- // Iterate over all the packages in the component project
200
- for pkgName := range componentProject .Packages {
201
- // Only care about the external binaries that we want to package
202
- for _ , spec := range manifest .ExpectedBinaries {
203
- // If the given component name doesn't match the external binary component, skip
204
- // FIXME temporarily skip fips packages until elastic-agent FIPS is in place
205
- if componentName != spec .ProjectName || strings .Contains (pkgName , "-fips-" ) {
206
- continue
119
+ manifestPackage , err := manifest .ResolveManifestPackage (manifestResponse .Projects [spec .ProjectName ], spec , dependenciesVersion , platform )
120
+ if err != nil {
121
+ if mg .Verbose () {
122
+ log .Printf (">>>>>>> Error resolving package for [%s/%s]" , spec .BinaryName , platform )
207
123
}
124
+ continue
125
+ }
208
126
209
- // Split the package name on the binary name prefix plus a dash
210
- firstSplit := strings .Split (pkgName , spec .BinaryName + "-" )
211
- if len (firstSplit ) < 2 {
212
- continue
213
- }
127
+ // Combine the package name w/ the versioned flat path
128
+ fullPath := filepath .Join (versionedFlatPath , manifestPackage .Name )
129
+
130
+ // Eliminate the file extensions to get the proper directory
131
+ // name that we need to copy
132
+ var dirToCopy string
133
+ if strings .HasSuffix (fullPath , ".tar.gz" ) {
134
+ dirToCopy = fullPath [:strings .LastIndex (fullPath , ".tar.gz" )]
135
+ } else if strings .HasSuffix (fullPath , ".zip" ) {
136
+ dirToCopy = fullPath [:strings .LastIndex (fullPath , ".zip" )]
137
+ } else {
138
+ dirToCopy = fullPath
139
+ }
140
+ if mg .Verbose () {
141
+ log .Printf (">>>>>>> Calculated directory to copy: [%s]" , dirToCopy )
142
+ }
214
143
215
- // Get the second part of the first split
216
- secondHalf := firstSplit [1 ]
217
- if len (secondHalf ) < 2 {
218
- continue
219
- }
144
+ // Set copy options
145
+ options := copy.Options {
146
+ OnSymlink : func (_ string ) copy.SymlinkAction {
147
+ return copy .Shallow
148
+ },
149
+ Sync : true ,
150
+ }
151
+ if mg .Verbose () {
152
+ log .Printf ("> prepare to copy %s into %s " , dirToCopy , versionedDropPath )
153
+ }
220
154
221
- // Make sure the second half matches the required package
222
- if strings .Contains (secondHalf , requiredPackage ) {
223
- // ignore packages with names where this splitting doesn't results in proper version
224
- if strings .Contains (secondHalf , "docker-image" ) {
225
- continue
226
- }
227
- if strings .Contains (secondHalf , "oss-" ) {
228
- continue
229
- }
230
-
231
- // The component version should be the first entry after splitting w/ the requiredPackage
232
- componentVersion = strings .Split (secondHalf , "-" + requiredPackage )[0 ]
233
- foundIt = true
234
- // break out of inner loop
235
- break
236
- }
155
+ // Do the copy
156
+ err = copy .Copy (dirToCopy , versionedDropPath , options )
157
+ if err != nil {
158
+ panic (err )
237
159
}
238
- if foundIt {
239
- // break out of outer loop
240
- break
160
+
161
+ checksum , err := CopyComponentSpecs (spec .BinaryName , versionedDropPath )
162
+ if err != nil {
163
+ panic (err )
241
164
}
242
- }
243
165
244
- if componentVersion == "" {
245
- errMsg := fmt .Sprintf ("Unable to determine component version for [%s]" , componentName )
246
- panic (errMsg )
166
+ checksums [spec .BinaryName + ComponentSpecFileSuffix ] = checksum
247
167
}
248
168
249
- return componentVersion
169
+ return checksums
250
170
}
0 commit comments