diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7726cf2..e780756 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -19,6 +19,14 @@ jobs: name: Build runs-on: ubuntu-latest + strategy: + matrix: + os: + - linux + arch: + - amd64 + - arm64 + steps: - name: Checkout uses: actions/checkout@v4 @@ -52,7 +60,7 @@ jobs: - name: Build project run: | - make release + make release GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} - name: Upload image tarballs to GCS run: | @@ -66,5 +74,5 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} files: | bin/nftables-exporter* - nftables-exporter.tgz + nftables-exporter*.tgz if: ${{ github.event_name == 'release' }} diff --git a/.gitignore b/.gitignore index 39fe8d4..ae1f842 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ vendor bin -nftables-exporter.tgz +rel +nftables-exporter*.tgz nft.json rules.json diff --git a/Makefile b/Makefile index a1467b2..d3d3fdf 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,11 @@ VERSION := $(or ${GITHUB_TAG_NAME},$(shell git describe --tags --exact-match 2> GOFILES=$(wildcard *.go) GONAME=$(shell basename "$(PWD)") +GOOS := linux +GOARCH := amd64 +BINARY := $(GONAME)-$(GOOS)-$(GOARCH) -all: +build: go build \ -trimpath \ -tags netgo \ @@ -15,26 +18,31 @@ all: -X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \ -X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \ -X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'" \ - -o bin/$(GONAME) $(GOFILES) - strip bin/$(GONAME) - sha256sum bin/$(GONAME) > bin/$(GONAME).sha256 + -o bin/$(BINARY) $(GOFILES) + strip bin/$(BINARY) + sha256sum bin/$(BINARY) > bin/$(BINARY).sha256 - -run: all +run: + $(MAKE) build BINARY=$(GONAME)-dev go run $(GOFILES) --config=$(shell pwd)/nftables_exporter.yaml clean: @echo "Cleaning" go clean +## +# Release +## + .PHONY: release -release: all +release: build rm -rf rel rm -f nftables-exporter.tgz mkdir -p rel/usr/bin rel/etc/systemd/system - cp bin/nftables-exporter rel/usr/bin + cp bin/nftables-exporter-$(GOOS)-$(GOARCH) rel/usr/bin/nftables-exporter cp systemd/nftables-exporter.service rel/etc/systemd/system cd rel \ - && tar -cvzf nftables-exporter.tgz usr/bin/nftables-exporter etc/systemd/system/nftables-exporter.service \ - && mv nftables-exporter.tgz .. \ + && tar --transform="flags=r;s|-$(GOOS)-$(GOARCH)||" -cvzf nftables-exporter-$(GOOS)-$(GOARCH).tgz \ + usr/bin/nftables-exporter etc/systemd/system/nftables-exporter.service \ + && mv nftables-exporter-$(GOOS)-$(GOARCH).tgz .. \ && cd - diff --git a/rel/etc/systemd/system/nftables-exporter.service b/rel/etc/systemd/system/nftables-exporter.service deleted file mode 100644 index 3957e76..0000000 --- a/rel/etc/systemd/system/nftables-exporter.service +++ /dev/null @@ -1,19 +0,0 @@ -[Unit] -Description=nftables exporter service -After=network-online.target - -[Service] -Type=simple -PIDFile=/run/nftables_exporter.pid -ExecStart=/usr/bin/nftables-exporter -User=root -Group=root -SyslogIdentifier=nftables-exporter -Restart=on-failure -RemainAfterExit=no -RestartSec=100ms -StandardOutput=journal -StandardError=journal - -[Install] -WantedBy=multi-user.target