forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Heartbeat] Add Magefile to X-Pack (elastic#20549)
This also restructures the main magefile to share code with the x-pack one (cherry picked from commit d036955)
- Loading branch information
Showing
4 changed files
with
181 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package mage | ||
|
||
import devtools "github.com/elastic/beats/v7/dev-tools/mage" | ||
|
||
const ( | ||
dirModuleGenerated = "build/package/module" | ||
dirModulesDGenerated = "build/package/modules.d" | ||
) | ||
|
||
// CustomizePackaging modifies the package specs to add the modules and | ||
// modules.d directory. You must declare a dependency on either | ||
// PrepareModulePackagingOSS or PrepareModulePackagingXPack. | ||
func CustomizePackaging() { | ||
monitorsDTarget := "monitors.d" | ||
unixMonitorsDir := "/etc/{{.BeatName}}/monitors.d" | ||
monitorsD := devtools.PackageFile{ | ||
Mode: 0644, | ||
Source: "monitors.d", | ||
} | ||
|
||
for _, args := range devtools.Packages { | ||
pkgType := args.Types[0] | ||
switch pkgType { | ||
case devtools.Docker: | ||
args.Spec.ExtraVar("linux_capabilities", "cap_net_raw=eip") | ||
args.Spec.Files[monitorsDTarget] = monitorsD | ||
case devtools.TarGz, devtools.Zip: | ||
args.Spec.Files[monitorsDTarget] = monitorsD | ||
case devtools.Deb, devtools.RPM, devtools.DMG: | ||
args.Spec.Files[unixMonitorsDir] = monitorsD | ||
} | ||
} | ||
} | ||
|
||
// Fields generates a fields.yml for the Beat. | ||
func Fields() error { | ||
return devtools.GenerateFieldsYAML("monitors/active") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
// +build mage | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/magefile/mage/mg" | ||
|
||
devtools "github.com/elastic/beats/v7/dev-tools/mage" | ||
"github.com/elastic/beats/v7/generator/common/beatgen" | ||
heartbeat "github.com/elastic/beats/v7/heartbeat/scripts/mage" | ||
|
||
// mage:import | ||
"github.com/elastic/beats/v7/dev-tools/mage/target/common" | ||
// mage:import | ||
"github.com/elastic/beats/v7/dev-tools/mage/target/unittest" | ||
// mage:import | ||
"github.com/elastic/beats/v7/dev-tools/mage/target/integtest" | ||
// mage:import | ||
_ "github.com/elastic/beats/v7/dev-tools/mage/target/test" | ||
) | ||
|
||
func init() { | ||
common.RegisterCheckDeps(Update) | ||
unittest.RegisterPythonTestDeps(Fields) | ||
integtest.RegisterPythonTestDeps(Fields) | ||
|
||
devtools.BeatDescription = "Ping remote services for availability and log " + | ||
"results to Elasticsearch or send to Logstash." | ||
devtools.BeatServiceName = "heartbeat-elastic" | ||
devtools.BeatLicense = "Elastic License" | ||
} | ||
|
||
// VendorUpdate updates elastic/beats/v7 in the vendor dir | ||
func VendorUpdate() error { | ||
return beatgen.VendorUpdate() | ||
} | ||
|
||
// Build builds the Beat binary. | ||
func Build() error { | ||
return devtools.Build(devtools.DefaultBuildArgs()) | ||
} | ||
|
||
// GolangCrossBuild build the Beat binary inside of the golang-builder. | ||
// Do not use directly, use crossBuild instead. | ||
func GolangCrossBuild() error { | ||
return devtools.GolangCrossBuild(devtools.DefaultGolangCrossBuildArgs()) | ||
} | ||
|
||
// BuildGoDaemon builds the go-daemon binary (use crossBuildGoDaemon). | ||
func BuildGoDaemon() error { | ||
return devtools.BuildGoDaemon() | ||
} | ||
|
||
// CrossBuild cross-builds the beat for all target platforms. | ||
func CrossBuild() error { | ||
return devtools.CrossBuild() | ||
} | ||
|
||
// CrossBuildXPack cross-builds the beat with XPack for all target platforms. | ||
func CrossBuildXPack() error { | ||
return devtools.CrossBuildXPack() | ||
} | ||
|
||
// CrossBuildGoDaemon cross-builds the go-daemon binary using Docker. | ||
func CrossBuildGoDaemon() error { | ||
return devtools.CrossBuildGoDaemon() | ||
} | ||
|
||
// Package packages the Beat for distribution. | ||
// Use SNAPSHOT=true to build snapshots. | ||
// Use PLATFORMS to control the target platforms. | ||
// Use VERSION_QUALIFIER to control the version qualifier. | ||
func Package() { | ||
start := time.Now() | ||
defer func() { fmt.Println("package ran for", time.Since(start)) }() | ||
|
||
devtools.UseElasticBeatPackaging() | ||
heartbeat.CustomizePackaging() | ||
|
||
mg.Deps(Update) | ||
mg.Deps(CrossBuild, CrossBuildXPack, CrossBuildGoDaemon) | ||
mg.SerialDeps(devtools.Package, TestPackages) | ||
} | ||
|
||
// TestPackages tests the generated packages (i.e. file modes, owners, groups). | ||
func TestPackages() error { | ||
return devtools.TestPackages(devtools.WithMonitorsD()) | ||
} | ||
|
||
func Fields() error { | ||
return heartbeat.Fields() | ||
} | ||
|
||
// Update updates the generated files (aka make update). | ||
func Update() { | ||
mg.SerialDeps(Fields, Config) | ||
} | ||
|
||
// Imports generates an include/list.go file containing | ||
// a import statement for each module and dataset. | ||
func Imports() error { | ||
options := devtools.DefaultIncludeListOptions() | ||
options.ModuleDirs = []string{"monitors"} | ||
options.Outfile = "monitors/defaults/default.go" | ||
options.Pkg = "defaults" | ||
return devtools.GenerateIncludeListGo(options) | ||
} | ||
|
||
// Config generates both the short/reference/docker configs. | ||
func Config() error { | ||
return devtools.Config(devtools.AllConfigTypes, heartbeat.ConfigFileParams(), ".") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters