-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Packaging of journalbeat #8702
Packaging of journalbeat #8702
Changes from 14 commits
d355ef8
bccfee3
9197714
f606389
6068254
d717e15
9924045
27ae222
2a4ef65
8d2181f
49126c0
a6892e3
4c936c9
88fcfc9
fcb2fd9
6072520
329428d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,20 +22,47 @@ package main | |
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/magefile/mage/mg" | ||
"github.com/magefile/mage/sh" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/beats/dev-tools/mage" | ||
) | ||
|
||
func init() { | ||
mage.BeatDescription = "Journalbeat ships systemd journal entries to Elasticsearch or Logstash." | ||
|
||
// TODO filter platforms | ||
mage.Platforms = mage.Platforms.Filter("linux !linux/ppc64 !linux/mips64") | ||
} | ||
|
||
var ( | ||
deps = map[string]func() error{ | ||
"linux/386": installLinux386, | ||
"linux/amd64": installLinuxAMD64, | ||
"linux/arm64": installLinuxARM64, | ||
"linux/armv5": installLinuxARMLe, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Actually, can you just make everything after "Linux" all-caps for each function. Most everything there is an acronym so with Go's naming conventions I think they should all be in caps. Plus there's a mix of "Le" and "le" which is inconsistent. |
||
"linux/armv6": installLinuxARMLe, | ||
"linux/armv7": installLinuxARMHf, | ||
"linux/mips": installLinuxMIPS, | ||
"linux/mipsle": installLinuxMIPSle, | ||
"linux/mips64le": installLinuxMIPS64le, | ||
"linux/ppc64le": installLinuxPPC64le, | ||
"linux/s390x": installLinuxs390x, | ||
|
||
// No deb packages | ||
//"linux/ppc64": installLinuxPpc64, | ||
//"linux/mips64": installLinuxMips64, | ||
} | ||
) | ||
|
||
const ( | ||
libsystemdDevPkgNameCurrent = "libsystemd-dev" | ||
libsystemdDevPkgNameDebian8 = "libsystemd-journal-dev" | ||
) | ||
|
||
// Build builds the Beat binary. | ||
func Build() error { | ||
return mage.Build(mage.DefaultBuildArgs()) | ||
|
@@ -44,27 +71,109 @@ func Build() error { | |
// GolangCrossBuild build the Beat binary inside of the golang-builder. | ||
// Do not use directly, use crossBuild instead. | ||
func GolangCrossBuild() error { | ||
if d, ok := deps[mage.Platform.Name]; ok { | ||
mg.Deps(d) | ||
} | ||
return mage.GolangCrossBuild(mage.DefaultGolangCrossBuildArgs()) | ||
} | ||
|
||
func installLinuxAMD64() error { | ||
return installDependencies(libsystemdDevPkgNameDebian8, "") | ||
} | ||
|
||
func installLinuxARM64() error { | ||
return installDependencies(libsystemdDevPkgNameCurrent+":arm64", "arm64") | ||
} | ||
|
||
func installLinuxARMHf() error { | ||
return installDependencies(libsystemdDevPkgNameCurrent+":armhf", "armhf") | ||
} | ||
|
||
func installLinuxARMLe() error { | ||
return installDependencies(libsystemdDevPkgNameCurrent+":armel", "armel") | ||
} | ||
|
||
func installLinux386() error { | ||
return installDependencies(libsystemdDevPkgNameDebian8+":i386", "i386") | ||
} | ||
|
||
func installLinuxMIPS() error { | ||
return installDependencies(libsystemdDevPkgNameCurrent+":mips", "mips") | ||
} | ||
|
||
func installLinuxMIPS64le() error { | ||
return installDependencies(libsystemdDevPkgNameCurrent+":mips64el", "mips64el") | ||
} | ||
|
||
func installLinuxMIPSle() error { | ||
return installDependencies(libsystemdDevPkgNameCurrent+":mipsel", "mipsel") | ||
} | ||
|
||
func installLinuxPPC64le() error { | ||
return installDependencies(libsystemdDevPkgNameCurrent+":ppc64el", "ppc64el") | ||
} | ||
|
||
func installLinuxs390x() error { | ||
return installDependencies(libsystemdDevPkgNameCurrent+":s390x", "s390x") | ||
} | ||
|
||
func installDependencies(pkg, arch string) error { | ||
if arch != "" { | ||
err := sh.Run("dpkg", "--add-architecture", arch) | ||
if err != nil { | ||
return errors.Wrap(err, "error while adding architecture") | ||
} | ||
} | ||
|
||
if err := sh.Run("apt-get", "update"); err != nil { | ||
return err | ||
} | ||
|
||
return sh.Run("apt-get", "install", "-y", "--no-install-recommends", pkg) | ||
} | ||
|
||
// BuildGoDaemon builds the go-daemon binary (use crossBuildGoDaemon). | ||
func BuildGoDaemon() error { | ||
return mage.BuildGoDaemon() | ||
} | ||
|
||
// CrossBuild cross-builds the beat for all target platforms. | ||
func CrossBuild() error { | ||
return mage.CrossBuild() | ||
return mage.CrossBuild(mage.ImageSelector(selectImage)) | ||
} | ||
|
||
func selectImage(platform string) (string, error) { | ||
tagSuffix := "main" | ||
|
||
switch { | ||
case strings.HasPrefix(platform, "linux/arm"): | ||
tagSuffix = "arm" | ||
case strings.HasPrefix(platform, "linux/mips"): | ||
tagSuffix = "mips" | ||
case strings.HasPrefix(platform, "linux/ppc"): | ||
tagSuffix = "ppc" | ||
case platform == "linux/s390x": | ||
tagSuffix = "s390x" | ||
case strings.HasPrefix(platform, "linux"): | ||
tagSuffix = "main-debian8" | ||
} | ||
|
||
goVersion, err := mage.GoVersion() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return mage.BeatsCrossBuildImage + ":" + goVersion + "-" + tagSuffix, nil | ||
} | ||
|
||
// CrossBuildXPack cross-builds the beat with XPack for all target platforms. | ||
func CrossBuildXPack() error { | ||
return mage.CrossBuildXPack() | ||
return mage.CrossBuildXPack(mage.ImageSelector(selectImage)) | ||
} | ||
|
||
// CrossBuildGoDaemon cross-builds the go-daemon binary using Docker. | ||
func CrossBuildGoDaemon() error { | ||
return mage.CrossBuildGoDaemon() | ||
return mage.CrossBuildGoDaemon(mage.ImageSelector(selectImage)) | ||
} | ||
|
||
// Clean cleans all generated files and build artifacts. | ||
|
@@ -80,6 +189,7 @@ func Package() { | |
defer func() { fmt.Println("package ran for", time.Since(start)) }() | ||
|
||
mage.UseElasticBeatPackaging() | ||
|
||
mg.Deps(Update) | ||
mg.Deps(CrossBuild, CrossBuildXPack, CrossBuildGoDaemon) | ||
mg.SerialDeps(mage.Package, TestPackages) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,9 +106,11 @@ ${BEAT_NAME}.test: $(GOFILES_ALL) | |
.PHONY: crosscompile | ||
crosscompile: ## @build Cross-compile beat for the OS'es specified in GOX_OS variable. The binaries are placed in the build/bin directory. | ||
crosscompile: $(GOFILES) | ||
ifneq ($(shell [[ $(BEAT_NAME) == journalbeat ]] && echo true ),true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this? How about removing the thing that's invoking crosscompile for journalbeat (I assume this can just be dropped from the travis config). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
go get github.com/mitchellh/gox | ||
mkdir -p ${BUILD_DIR}/bin | ||
gox -output="${BUILD_DIR}/bin/{{.Dir}}-{{.OS}}-{{.Arch}}" -os="$(strip $(GOX_OS))" -osarch="$(strip $(GOX_OSARCH))" ${GOX_FLAGS} | ||
endif | ||
|
||
.PHONY: check | ||
check: check-headers python-env prepare-tests ## @build Checks project and source code if everything is according to standard | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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. | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/elastic/beats/journalbeat/cmd" | ||
xpackcmd "github.com/elastic/beats/x-pack/libbeat/cmd" | ||
) | ||
|
||
// RootCmd to handle beats cli | ||
var RootCmd = cmd.RootCmd | ||
|
||
func init() { | ||
xpackcmd.AddXPack(RootCmd, cmd.Name) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍