@@ -1209,6 +1209,196 @@ func getIndAgentGlobExpr(versionedFlatPath string, packageVersion string) string
1209
1209
return globExpr
1210
1210
}
1211
1211
1212
+ func fileHelperNoManifest (versionedFlatPath string , versionedDropPath string , packageVersion string ) map [string ]string {
1213
+ log .Printf (">>>>>>>>>> XXX versionedFlatPath: [%s]" , versionedFlatPath )
1214
+ globExpr := filepath .Join (versionedFlatPath , fmt .Sprintf ("*%s*" , packageVersion ))
1215
+ //globExpr := getIndAgentGlobExpr(versionedFlatPath, packageVersion)
1216
+ if mg .Verbose () {
1217
+ log .Printf ("Finding files to copy with %s" , globExpr )
1218
+ }
1219
+ files , err := filepath .Glob (globExpr )
1220
+ if err != nil {
1221
+ panic (err )
1222
+ }
1223
+ if mg .Verbose () {
1224
+ log .Printf (" XXX Validating checksums for %+v" , files )
1225
+ log .Printf ("--- XXX Copying into %s: %v" , versionedDropPath , files )
1226
+ }
1227
+
1228
+ checksums := make (map [string ]string )
1229
+ for _ , f := range files {
1230
+ options := copy.Options {
1231
+ OnSymlink : func (_ string ) copy.SymlinkAction {
1232
+ return copy .Shallow
1233
+ },
1234
+ Sync : true ,
1235
+ }
1236
+ if mg .Verbose () {
1237
+ log .Printf ("> XXX prepare to copy %s into %s " , f , versionedDropPath )
1238
+ }
1239
+
1240
+ info , err := os .Stat (f )
1241
+ if err != nil {
1242
+ panic (err )
1243
+ }
1244
+ if info .IsDir () {
1245
+ log .Printf (">>> XXX DIR!! [%s]" , f )
1246
+ } else {
1247
+ log .Printf (">>> XXX File! [%s]" , f )
1248
+ }
1249
+
1250
+ err = copy .Copy (f , versionedDropPath , options )
1251
+ if err != nil {
1252
+ panic (err )
1253
+ }
1254
+
1255
+ // copy spec file for match
1256
+ specName := filepath .Base (f )
1257
+ log .Printf (">>>> XXX specName: [%s]" , specName )
1258
+ idx := strings .Index (specName , "-" + packageVersion )
1259
+ if idx != - 1 {
1260
+ specName = specName [:idx ]
1261
+ log .Printf (">>>> XXX specName[:idx] [%s]" , specName )
1262
+ }
1263
+ log .Printf (">>>> XXX specName final: [%s]" , specName )
1264
+
1265
+ checksum , err := copyComponentSpecs (specName , versionedDropPath )
1266
+ if err != nil {
1267
+ panic (err )
1268
+ }
1269
+
1270
+ checksums [specName + specSuffix ] = checksum
1271
+ }
1272
+
1273
+ return checksums
1274
+ }
1275
+
1276
+ func getComponentVersion (componentName string , requiredPackage string , componentProject tools.Project , agentComponents map [string ]string ) string {
1277
+ var componentVersion string
1278
+ for pkgName , _ := range componentProject .Packages {
1279
+ log .Printf (">>>>>>>>>>> XXX getComponentVersion Package: %s <<<<" , pkgName )
1280
+ pkgPrefix := agentComponents [componentName ]
1281
+ firstSplit := strings .Split (pkgName , pkgPrefix + "-" )
1282
+ if len (firstSplit ) < 2 {
1283
+ continue
1284
+ }
1285
+ secondHalf := firstSplit [1 ]
1286
+ if len (secondHalf ) < 2 {
1287
+ continue
1288
+ }
1289
+ if strings .Contains (secondHalf , requiredPackage ) {
1290
+ log .Printf (">>>>>>>>>>> XXX Second Half: %s <<<<" , secondHalf )
1291
+ if strings .Contains (secondHalf , "docker-image" ) {
1292
+ continue
1293
+ }
1294
+ if strings .Contains (secondHalf , "oss-" ) {
1295
+ continue
1296
+ }
1297
+ componentVersion = strings .Split (secondHalf , "-" + requiredPackage )[0 ]
1298
+ log .Printf (">>>>>>>>>>> XXX Got Version: %s <<<<" , componentVersion )
1299
+ break
1300
+ }
1301
+ }
1302
+
1303
+ return componentVersion
1304
+ }
1305
+
1306
+ func fileHelperWithManifest (requiredPackage string , versionedFlatPath string , versionedDropPath string , manifestResponse tools.Build ) map [string ]string {
1307
+
1308
+ agentComponents := map [string ]string {
1309
+ "apm-server" : "apm-server" ,
1310
+ "beats" : "metricbeat" ,
1311
+ "cloud-defend" : "cloud-defend" ,
1312
+ "cloudbeat" : "cloudbeat" ,
1313
+ //"elastic-agent-core": "elastic-agent-core",
1314
+ "endpoint-dev" : "endpoint-security" ,
1315
+ "fleet-server" : "fleet-server" ,
1316
+ "prodfiler" : "pf-elastic-collector" ,
1317
+ }
1318
+ /*
1319
+ externalBinaries := map[string]string{
1320
+ "agentbeat": "beats",
1321
+ "cloudbeat": "cloudbeat", // only supporting linux/amd64 or linux/arm64
1322
+ "cloud-defend": "cloud-defend",
1323
+ "apm-server": "apm-server", // not supported on darwin/aarch64
1324
+ "endpoint-security": "endpoint-dev",
1325
+ "fleet-server": "fleet-server",
1326
+ "pf-elastic-collector": "prodfiler",
1327
+ "pf-elastic-symbolizer": "prodfiler",
1328
+ "pf-host-agent": "prodfiler",
1329
+ }
1330
+ */
1331
+
1332
+ checksums := make (map [string ]string )
1333
+
1334
+ projects := manifestResponse .Projects
1335
+ //log.Printf(">>>>>>>>> XXX projects: [%s]", projects)
1336
+ log .Printf (">>>>>>>> XXX in filehelperWithManifest" )
1337
+
1338
+ for componentName , _ := range projects {
1339
+ if _ , ok := agentComponents [componentName ]; ! ok {
1340
+ //log.Printf(">>>>>> XXX Ignoring component [%s]", componentName)
1341
+ continue
1342
+ }
1343
+
1344
+ log .Printf (">>>>>>>>> XXX Found componentName [%s]" , componentName )
1345
+
1346
+ log .Printf (">>>>> XXX Checking for requiredPackage: [%s]" , requiredPackage )
1347
+ for pkgName , _ := range projects [componentName ].Packages {
1348
+ log .Printf (">>>>>>>> XXX Found pkgName: [%s]" , pkgName )
1349
+ if strings .Contains (pkgName , requiredPackage ) {
1350
+ log .Printf (">>>>>>> XXX Pkg [%s] matches requiredPackage [%s]" , pkgName , requiredPackage )
1351
+
1352
+ componentVersion := getComponentVersion (componentName , requiredPackage , projects [componentName ], agentComponents )
1353
+ log .Printf (">>>>>>> XXX [%s] [%s] version is [%s]" , componentName , requiredPackage , componentVersion )
1354
+
1355
+ fullPath := filepath .Join (versionedFlatPath , pkgName )
1356
+ log .Printf (">>>>>> XXX fullPath [%s]" , fullPath )
1357
+
1358
+ var dirToCopy string
1359
+ if strings .HasSuffix (fullPath , ".tar.gz" ) {
1360
+ dirToCopy = fullPath [:strings .LastIndex (fullPath , ".tar.gz" )]
1361
+ } else if strings .HasSuffix (fullPath , ".zip" ) {
1362
+ dirToCopy = fullPath [:strings .LastIndex (fullPath , ".zip" )]
1363
+ } else {
1364
+ dirToCopy = fullPath
1365
+ }
1366
+ log .Printf (">>>>>> XXX dirToCopy [%s]" , dirToCopy )
1367
+
1368
+ options := copy.Options {
1369
+ OnSymlink : func (_ string ) copy.SymlinkAction {
1370
+ return copy .Shallow
1371
+ },
1372
+ Sync : true ,
1373
+ }
1374
+ log .Printf ("> XXX ManURL prepare to copy %s into %s " , dirToCopy , versionedDropPath )
1375
+
1376
+ //log.Printf(">>>>> SLEEPING")
1377
+ //time.Sleep(60 * time.Second)
1378
+ //log.Printf(">>>>> DONE SLEEPING")
1379
+
1380
+ info , err := os .Stat (dirToCopy )
1381
+ if err != nil {
1382
+ panic (err )
1383
+ }
1384
+ if info .IsDir () {
1385
+ log .Printf (">>> XXX DIR!! [%s]" , dirToCopy )
1386
+ } else {
1387
+ log .Printf (">>> XXX File! [%s]" , dirToCopy )
1388
+ }
1389
+
1390
+ err = copy .Copy (dirToCopy , versionedDropPath , options )
1391
+ if err != nil {
1392
+ panic (err )
1393
+ }
1394
+
1395
+ }
1396
+ }
1397
+ }
1398
+
1399
+ return checksums
1400
+ }
1401
+
1212
1402
// flattenDependencies will extract all the required packages collected in archivePath and dropPath in flatPath and
1213
1403
// regenerate checksums
1214
1404
func flattenDependencies (requiredPackages []string , packageVersion , archivePath , dropPath , flatPath string , manifestResponse tools.Build ) {
@@ -1237,6 +1427,8 @@ func flattenDependencies(requiredPackages []string, packageVersion, archivePath,
1237
1427
if mg .Verbose () {
1238
1428
log .Printf ("--- Extracting into the flat dir: %v" , matches )
1239
1429
}
1430
+ log .Printf ("--- XXX Extracting into the flat dir: %v" , matches )
1431
+
1240
1432
for _ , m := range matches {
1241
1433
stat , err := os .Stat (m )
1242
1434
if os .IsNotExist (err ) {
@@ -1252,59 +1444,28 @@ func flattenDependencies(requiredPackages []string, packageVersion, archivePath,
1252
1444
if mg .Verbose () {
1253
1445
log .Printf (">>> Extracting %s to %s" , m , versionedFlatPath )
1254
1446
}
1447
+ log .Printf (">>> XXX Extracting %s to %s" , m , versionedFlatPath )
1448
+
1255
1449
if err := devtools .Extract (m , versionedFlatPath ); err != nil {
1256
1450
panic (err )
1257
1451
}
1258
1452
}
1259
1453
1260
- //globExpr := filepath.Join(versionedFlatPath, fmt.Sprintf("*%s*", packageVersion))
1261
- globExpr := getIndAgentGlobExpr (versionedFlatPath , packageVersion )
1262
- if mg .Verbose () {
1263
- log .Printf ("Finding files to copy with %s" , globExpr )
1264
- }
1265
- files , err := filepath .Glob (globExpr )
1266
- if err != nil {
1267
- panic (err )
1268
- }
1269
- if mg .Verbose () {
1270
- log .Printf ("Validating checksums for %+v" , files )
1271
- log .Printf ("--- Copying into %s: %v" , versionedDropPath , files )
1272
- }
1273
1454
checksums := make (map [string ]string )
1274
- for _ , f := range files {
1275
- options := copy.Options {
1276
- OnSymlink : func (_ string ) copy.SymlinkAction {
1277
- return copy .Shallow
1278
- },
1279
- Sync : true ,
1280
- }
1281
- if mg .Verbose () {
1282
- log .Printf ("> prepare to copy %s " , f )
1283
- }
1284
- err = copy .Copy (f , versionedDropPath , options )
1285
- if err != nil {
1286
- panic (err )
1287
- }
1288
-
1289
- // copy spec file for match
1290
- specName := filepath .Base (f )
1291
- idx := strings .Index (specName , "-" + packageVersion )
1292
- if idx != - 1 {
1293
- specName = specName [:idx ]
1294
- }
1295
-
1296
- checksum , err := copyComponentSpecs (specName , versionedDropPath )
1297
- if err != nil {
1298
- panic (err )
1299
- }
1300
-
1301
- checksums [specName + specSuffix ] = checksum
1455
+ if devtools .PackagingFromManifest {
1456
+ checksums = fileHelperWithManifest (rp , versionedFlatPath , versionedDropPath , manifestResponse )
1457
+ } else {
1458
+ checksums = fileHelperNoManifest (versionedFlatPath , versionedDropPath , packageVersion )
1302
1459
}
1303
1460
1304
1461
if err := appendComponentChecksums (versionedDropPath , checksums ); err != nil {
1305
1462
panic (err )
1306
1463
}
1307
1464
}
1465
+
1466
+ log .Printf (">>>> XXX Sleeping...." )
1467
+ //time.Sleep(60 * time.Second)
1468
+ log .Printf (">>>> XXX Done Sleeping...." )
1308
1469
}
1309
1470
1310
1471
// simple struct to deserialize branch information.
0 commit comments