Skip to content

Commit

Permalink
Merge pull request #7 from vrince/cross-compile
Browse files Browse the repository at this point in the history
Cross compile arm 32 bits and removed the docker qemu build
  • Loading branch information
vrince committed Apr 26, 2024
2 parents 7dbe54a + 93b215e commit afa1902
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 47 deletions.
31 changes: 9 additions & 22 deletions .github/workflows/beats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,29 @@ jobs:

strategy:
matrix:
arch: [armv6, armv7]
beat: [filebeat, metricbeat, packetbeat, heartbeat]
distro: [buster]
go: [1.17.5]
arch: [armv7]
beat: [filebeat, metricbeat, heartbeat]

runs-on: ubuntu-latest
container:
image: golang:1.20.11

name: ${{ matrix.beat }} ${{ matrix.arch }}

steps:
- uses: actions/checkout@v2

- name: Set tag
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
run: echo "git_tag=:${GITHUB_REF#refs/*/}" >> $GITHUB_STATE

- uses: uraimo/run-on-arch-action@v2.1.1
name: Build beat (on arch)
- name: Build beat
id: build-beat
with:
arch: ${{ matrix.arch }}
distro: ${{ matrix.distro }}

githubToken: ${{ github.token }}

install: |
apt-get update -q -y
apt-get install -q -y wget jq curl git build-essential libsystemd-dev
run: |
./install-go.sh ${{ matrix.go }} armv6l
./build.sh ${{ matrix.beat }} ${{ steps.vars.outputs.tag }}
run: ./build.sh ${{ matrix.beat }} ${{ matrix.arch }} $git_tag

- uses: actions/upload-artifact@v2
if: startsWith(github.ref, 'refs/tags/')
with:
name: ${{ matrix.beat }}-${{ matrix.arch }}-${{ matrix.distro }}
name: ${{ matrix.beat }}-${{ matrix.arch }}
path: ${{ matrix.beat }}-*.tar.gz

- name: Release
Expand Down
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![](https://badgen.net/github/release/vrince/arm-beats)
[![CI](https://github.com/vrince/arm-beats/actions/workflows/beats.yml/badge.svg)](https://github.com/vrince/arm-beats/actions/workflows/beats.yml)

Automated Elastic `filebeat`, `metricbeat`, `heartbeat` & `packagebeat` builds for **linux/armv7 & linux/armv6 32bits**.
Automated Elastic `filebeat`, `metricbeat`, `heartbeat` & `packagebeat` builds for **linux/armv7 32bits**.

## Goal

Expand All @@ -16,9 +16,9 @@ Currently elasticsearch team do not provide any **arm 32bits** (armv7 / armv6) b
## Run `filebeat` on a raspberry pi

```bash
wget https://github.com/vrince/arm-beats/releases/download/v8.3.3/filebeat-8.3.3-linux-armv7l.tar.gz
tar -xf filebeat-8.3.3-linux-armv7l.tar.gz
cd filebeat-8.3.3-linux-armv7l
wget https://github.com/vrince/arm-beats/releases/download/v8.11.4/filebeat-8.11.4-linux-armv7l.tar.gz
tar -xf filebeat-8.11.4-linux-armv7l.tar.gz
cd filebeat-8.11.4-linux-armv7l
file ./filebeat
```

Expand All @@ -33,9 +33,9 @@ For more information about how to configure `filebeat` --> [documentation](https
## Run `metricbeat` on raspberry pi

```bash
wget https://github.com/vrince/arm-beats/releases/download/v8.3.3/metricbeat-8.3.3-linux-armv7l.tar.gz
tar -xf metricbeat-8.3.3-linux-armv7l.tar.gz
cd metricbeat-8.3.3-linux-armv7l
wget https://github.com/vrince/arm-beats/releases/download/v8.11.4/metricbeat-8.11.4-linux-armv7l.tar.gz
tar -xf metricbeat-8.11.4-linux-armv7l.tar.gz
cd metricbeat-8.11.4-linux-armv7l
file ./metricbeat
```

Expand All @@ -51,8 +51,6 @@ For more information about how to configure `metricbeat` --> [documentation](htt

[![CI](https://github.com/vrince/arm-beats/actions/workflows/beats.yml/badge.svg)](https://github.com/vrince/arm-beats/actions/workflows/beats.yml)

This automation script uses emulated (`qemu`) multi-arch capability of docker. Performance is really not that great, so we only perform `go get` to build necessary binary file. Finally we patch official elasticsearch (arm64) beat package swapping the main binary.

## Reference

* Elastic beat : https://www.elastic.co/beats/
Expand Down
40 changes: 25 additions & 15 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

#set -e
BEAT="${1:-filebeat}"
TAG="${2}"
ARCH="${2:-armv7l}"
BRANCH="${3}"

if [[ -z ${TAG} || ${TAG} == "master" ]] ; then
TAG="v7.16.2"
echo "Using default tag(${TAG})"
TAG=$(git describe --tags --exact-match 2> /dev/null)

if [[ -z ${TAG} ]] ; then
BRANCH="master"
echo "Using default branch(${BRANCH})"
fi

VERSION="${TAG:1}"
ARCH=$(uname -m)
VERSION="${BRANCH:1}"
SRC=$(pwd)

echo "Setup"
Expand All @@ -19,33 +21,41 @@ unset GOROOT
export GOPATH=$(pwd)/go/project
export PATH="/usr/local/go/bin:${GOPATH}/bin:${PATH}"
mkdir -p "${GOPATH}"

go version
go tool dist list | grep linux

if [[ ! -d beats ]] ; then
echo "Cloning elastic/beats git tag(${TAG})"
git clone --quiet --single-branch --branch="${TAG}" --depth=1 "https://github.com/elastic/beats.git"
echo "Cloning elastic/beats git branch(${BRANCH})"
git clone --quiet --single-branch --branch="${BRANCH}" --depth=1 "https://github.com/elastic/beats.git"
cd "${SRC}/beats"
git checkout --quiet --detach "${TAG}"
git checkout --quiet --detach "${BRANCH}"
git describe --tags
fi

set -e

echo "Building(${BEAT})"

rm -rf "${GOPATH}/bin"
cd "${SRC}/beats/${BEAT}"
go get -v -a ./...
env GOOS=linux GOARCH=arm go install -v -a ./...

if [[ -z ${TAG} ]] ; then
ls -al ${GOPATH}/bin/linux_arm/${BEAT}
exit 0
fi

echo "Patching package"
echo "Patching package version(${VERSION})"

SRC_ARCHIVE="${BEAT}-${VERSION}-linux-arm64"
DEST_ARCHIVE="${BEAT}-${VERSION}-linux-${ARCH}"

echo "${SRC_ARCHIVE} --> ${DEST_ARCHIVE}"

cd "${SRC}"
wget -q -N "https://artifacts.elastic.co/downloads/beats/${BEAT}/${SRC_ARCHIVE}.tar.gz"
wget "https://artifacts.elastic.co/downloads/beats/${BEAT}/${SRC_ARCHIVE}.tar.gz"
tar -xf "${SRC_ARCHIVE}.tar.gz"
mv "${SRC_ARCHIVE}" "${DEST_ARCHIVE}"
cp -f "${GOPATH}/bin/${BEAT}" "${DEST_ARCHIVE}/${BEAT}"
tar -czf "${DEST_ARCHIVE}.tar.gz" "${DEST_ARCHIVE}"
rm "${SRC_ARCHIVE}.tar.gz"
cp -f "${GOPATH}/bin/linux_arm/${BEAT}" "${DEST_ARCHIVE}/${BEAT}"
tar -czf "${DEST_ARCHIVE}.tar.gz" "${DEST_ARCHIVE}"
2 changes: 1 addition & 1 deletion install-go.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
GO_VERSION=${1:-1.17.5}
GO_VERSION=${1:-1.20.11}
GO_ARCH=${2:amd64}
FORCE=${3}

Expand Down

0 comments on commit afa1902

Please sign in to comment.