Skip to content

Commit

Permalink
addressing PR comments and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhyrock committed Jun 20, 2024
1 parent 619512d commit 9afa054
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
24 changes: 12 additions & 12 deletions dev-tools/mage/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ var errorNotAllowedManifestURL = errors.New("the provided ManifestURL is not all

var AllowedManifestHosts = []string{"snapshots.elastic.co", "staging.elastic.co"}

var ComponentSpec = map[string][]string{
"apm-server": {"apm-server"},
"beats": {"agentbeat"},
"cloud-defend": {"cloud-defend"},
"cloudbeat": {"cloudbeat"},
"elastic-agent-shipper": {"elastic-agent-shipper"},
"endpoint-dev": {"endpoint-security"},
"fleet-server": {"fleet-server"},
"prodfiler": {"pf-elastic-collector", "pf-elastic-symbolizer", "pf-host-agent"},
}

// DownloadManifest is going to download the given manifest file and return the ManifestResponse
func DownloadManifest(manifest string) (tools.Build, error) {
manifestUrl, urlError := url.Parse(manifest)
Expand Down Expand Up @@ -143,17 +154,6 @@ func resolveManifestPackage(project tools.Project, pkg string, reqPackage string
// DownloadComponentsFromManifest is going to download a set of components from the given manifest into the destination
// dropPath folder in order to later use that folder for packaging
func DownloadComponentsFromManifest(manifest string, platforms []string, platformPackages map[string]string, dropPath string) error {
componentSpec := map[string][]string{
"apm-server": {"apm-server"},
"beats": {"agentbeat"},
"cloud-defend": {"cloud-defend"},
"cloudbeat": {"cloudbeat"},
"elastic-agent-shipper": {"elastic-agent-shipper"},
"endpoint-dev": {"endpoint-security"},
"fleet-server": {"fleet-server"},
"prodfiler": {"pf-elastic-collector", "pf-elastic-symbolizer", "pf-host-agent"},
}

manifestResponse, err := DownloadManifest(manifest)
if err != nil {
return fmt.Errorf("failed to download remote manifest file %w", err)
Expand All @@ -171,7 +171,7 @@ func DownloadComponentsFromManifest(manifest string, platforms []string, platfor
majorMinorPatchVersion := parsedManifestVersion.VersionWithPrerelease()

errGrp, downloadsCtx := errgroup.WithContext(context.Background())
for component, pkgs := range componentSpec {
for component, pkgs := range ComponentSpec {
for _, platform := range platforms {
targetPath := filepath.Join(dropPath)
err := os.MkdirAll(targetPath, 0755)
Expand Down
8 changes: 8 additions & 0 deletions dev-tools/mage/target/common/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import (
devtools "github.com/elastic/elastic-agent/dev-tools/mage"
)

var PlatformPackages = map[string]string{
"darwin/amd64": "darwin-x86_64.tar.gz",
"darwin/arm64": "darwin-aarch64.tar.gz",
"linux/amd64": "linux-x86_64.tar.gz",
"linux/arm64": "linux-arm64.tar.gz",
"windows/amd64": "windows-x86_64.zip",
}

// PackageSystemTests packages the python system tests results
func PackageSystemTests() error {
excludes := []string{".ci", ".git", ".github", "vendor", "dev-tools"}
Expand Down
24 changes: 4 additions & 20 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,20 +536,12 @@ func DownloadManifest() error {
return errAtLeastOnePlatform
}

platformPackages := map[string]string{
"darwin/amd64": "darwin-x86_64.tar.gz",
"darwin/arm64": "darwin-aarch64.tar.gz",
"linux/amd64": "linux-x86_64.tar.gz",
"linux/arm64": "linux-arm64.tar.gz",
"windows/amd64": "windows-x86_64.zip",
}

var requiredPackages []string
for _, p := range platforms {
requiredPackages = append(requiredPackages, platformPackages[p])
requiredPackages = append(requiredPackages, common.PlatformPackages[p])
}

if e := manifest.DownloadComponentsFromManifest(devtools.ManifestURL, platforms, platformPackages, dropPath); e != nil {
if e := manifest.DownloadComponentsFromManifest(devtools.ManifestURL, platforms, common.PlatformPackages, dropPath); e != nil {
return fmt.Errorf("failed to download the manifest file, %w", e)
}
log.Printf(">> Completed downloading packages from manifest into drop-in %s", dropPath)
Expand Down Expand Up @@ -983,22 +975,14 @@ func runAgent(env map[string]string) error {
return sh.Run("docker", dockerCmdArgs...)
}

var platformPackages = map[string]string{
"darwin/amd64": "darwin-x86_64.tar.gz",
"darwin/arm64": "darwin-aarch64.tar.gz",
"linux/amd64": "linux-x86_64.tar.gz",
"linux/arm64": "linux-arm64.tar.gz",
"windows/amd64": "windows-x86_64.zip",
}

func packageAgent(platforms []string, dependenciesVersion string, agentPackaging, agentBinaryTarget mg.Fn) {
fmt.Println("--- Package Elastic-Agent")
var manifestResponse tools.Build
var err error

requiredPackages := []string{}
for _, p := range platforms {
requiredPackages = append(requiredPackages, platformPackages[p])
requiredPackages = append(requiredPackages, common.PlatformPackages[p])
}
if mg.Verbose() {
log.Printf("--- Packaging dependenciesVersion[%s], %+v \n", dependenciesVersion, requiredPackages)
Expand Down Expand Up @@ -1097,7 +1081,7 @@ func collectPackageDependencies(platforms []string, packageVersion string, requi
completedDownloads := &atomic.Int32{}
for binary, project := range externalBinaries {
for _, platform := range platforms {
reqPackage := platformPackages[platform]
reqPackage := common.PlatformPackages[platform]
targetPath := filepath.Join(archivePath, reqPackage)
os.MkdirAll(targetPath, 0755)
newVersion, packageName := getPackageName(binary, packageVersion, reqPackage)
Expand Down

0 comments on commit 9afa054

Please sign in to comment.