Skip to content

Commit bacda1f

Browse files
committed
it seems to maybe work
1 parent 9b0a181 commit bacda1f

File tree

1 file changed

+84
-67
lines changed

1 file changed

+84
-67
lines changed

magefile.go

+84-67
Original file line numberDiff line numberDiff line change
@@ -1303,95 +1303,112 @@ func getComponentVersion(componentName string, requiredPackage string, component
13031303
return componentVersion
13041304
}
13051305

1306+
func fixCloudDefendDirPath(dirPath string, componentVersion string, expectedArch string, actualArch string) string {
1307+
fixedDirPath := dirPath
1308+
1309+
cloudDefendExpectedDirName := fmt.Sprintf("cloud-defend-%s-linux-%s", componentVersion, expectedArch)
1310+
cloudDefendActualDirName := fmt.Sprintf("cloud-defend-%s-%s", componentVersion, actualArch)
1311+
if strings.Contains(fixedDirPath, cloudDefendExpectedDirName) {
1312+
fixedDirPath = strings.ReplaceAll(fixedDirPath, cloudDefendExpectedDirName, cloudDefendActualDirName)
1313+
}
1314+
1315+
return fixedDirPath
1316+
}
1317+
13061318
func fileHelperWithManifest(requiredPackage string, versionedFlatPath string, versionedDropPath string, manifestResponse tools.Build) map[string]string {
13071319

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",
1320+
// Should move this elsewhere so there's only one location for it
1321+
externalBinaries := map[string]string{
1322+
"agentbeat": "beats",
1323+
"cloudbeat": "cloudbeat", // only supporting linux/amd64 or linux/arm64
1324+
"cloud-defend": "cloud-defend",
1325+
"apm-server": "apm-server", // not supported on darwin/aarch64
1326+
"endpoint-security": "endpoint-dev",
1327+
"fleet-server": "fleet-server",
1328+
"pf-elastic-collector": "prodfiler",
1329+
"pf-elastic-symbolizer": "prodfiler",
1330+
"pf-host-agent": "prodfiler",
13171331
}
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-
*/
13311332

13321333
checksums := make(map[string]string)
13331334

13341335
projects := manifestResponse.Projects
1335-
//log.Printf(">>>>>>>>> XXX projects: [%s]", projects)
13361336
log.Printf(">>>>>>>> XXX in filehelperWithManifest")
13371337

13381338
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)
13451339

13461340
log.Printf(">>>>> XXX Checking for requiredPackage: [%s]", requiredPackage)
13471341
for pkgName, _ := range projects[componentName].Packages {
13481342
log.Printf(">>>>>>>> XXX Found pkgName: [%s]", pkgName)
13491343
if strings.Contains(pkgName, requiredPackage) {
1350-
log.Printf(">>>>>>> XXX Pkg [%s] matches requiredPackage [%s]", pkgName, requiredPackage)
1344+
for filePrefix, _ := range externalBinaries {
1345+
if !strings.HasPrefix(pkgName, filePrefix) {
1346+
continue
1347+
}
1348+
log.Printf(">>>>>>> XXX Pkg [%s] matches requiredPackage [%s]", pkgName, requiredPackage)
13511349

1352-
componentVersion := getComponentVersion(componentName, requiredPackage, projects[componentName], agentComponents)
1353-
log.Printf(">>>>>>> XXX [%s] [%s] version is [%s]", componentName, requiredPackage, componentVersion)
1350+
componentVersion := getComponentVersion(componentName, requiredPackage, projects[componentName], agentComponents)
1351+
log.Printf(">>>>>>> XXX [%s] [%s] version is [%s]", componentName, requiredPackage, componentVersion)
13541352

1355-
fullPath := filepath.Join(versionedFlatPath, pkgName)
1356-
log.Printf(">>>>>> XXX fullPath [%s]", fullPath)
1353+
fullPath := filepath.Join(versionedFlatPath, pkgName)
1354+
log.Printf(">>>>>> XXX fullPath [%s]", fullPath)
13571355

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)
1356+
var dirToCopy string
1357+
if strings.HasSuffix(fullPath, ".tar.gz") {
1358+
dirToCopy = fullPath[:strings.LastIndex(fullPath, ".tar.gz")]
1359+
} else if strings.HasSuffix(fullPath, ".zip") {
1360+
dirToCopy = fullPath[:strings.LastIndex(fullPath, ".zip")]
1361+
} else {
1362+
dirToCopy = fullPath
1363+
}
13671364

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)
1365+
// cloud-defend path exception
1366+
// When untarred, cloud defend untars to:
1367+
// cloud-defend-8.14.0-arm64
1368+
// but the manifest (and most of this code) expects to be the same as
1369+
// the name in the manifest, which is:
1370+
// cloud-defend-8.14.0-linux-x86_64
1371+
// So we have to do a bit of a transformation here
1372+
if strings.Contains(dirToCopy, "cloud-defend") {
1373+
if strings.Contains(dirToCopy, "x86_64") {
1374+
dirToCopy = fixCloudDefendDirPath(dirToCopy, componentVersion, "x86_64", "amd64")
1375+
}
1376+
if strings.Contains(dirToCopy, "arm64") {
1377+
// Not actually replacing the arch, but removing the "linux"
1378+
dirToCopy = fixCloudDefendDirPath(dirToCopy, componentVersion, "arm64", "arm64")
1379+
}
1380+
}
13751381

1376-
//log.Printf(">>>>> SLEEPING")
1377-
//time.Sleep(60 * time.Second)
1378-
//log.Printf(">>>>> DONE SLEEPING")
1382+
log.Printf(">>>>>> XXX dirToCopy [%s]", dirToCopy)
13791383

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-
}
1384+
options := copy.Options{
1385+
OnSymlink: func(_ string) copy.SymlinkAction {
1386+
return copy.Shallow
1387+
},
1388+
Sync: true,
1389+
}
1390+
log.Printf("> XXX ManURL prepare to copy %s into %s ", dirToCopy, versionedDropPath)
13891391

1390-
err = copy.Copy(dirToCopy, versionedDropPath, options)
1391-
if err != nil {
1392-
panic(err)
1393-
}
1392+
info, err := os.Stat(dirToCopy)
1393+
if err != nil {
1394+
log.Printf(">>>>> SLEEPING")
1395+
time.Sleep(60 * time.Second)
1396+
log.Printf(">>>>> DONE SLEEPING")
13941397

1398+
panic(err)
1399+
}
1400+
if info.IsDir() {
1401+
log.Printf(">>> XXX DIR!! [%s]", dirToCopy)
1402+
} else {
1403+
log.Printf(">>> XXX File! [%s]", dirToCopy)
1404+
}
1405+
1406+
err = copy.Copy(dirToCopy, versionedDropPath, options)
1407+
if err != nil {
1408+
panic(err)
1409+
}
1410+
1411+
}
13951412
}
13961413
}
13971414
}
@@ -1464,7 +1481,7 @@ func flattenDependencies(requiredPackages []string, packageVersion, archivePath,
14641481
}
14651482

14661483
log.Printf(">>>> XXX Sleeping....")
1467-
//time.Sleep(60 * time.Second)
1484+
time.Sleep(60 * time.Second)
14681485
log.Printf(">>>> XXX Done Sleeping....")
14691486
}
14701487

0 commit comments

Comments
 (0)