From 8dfa18c9ef27d1f9db57bc99047d794c88ffe3e6 Mon Sep 17 00:00:00 2001 From: orblazer Date: Fri, 5 Jul 2024 18:43:23 +0200 Subject: [PATCH 1/4] Remove rel folder from repo --- .gitignore | 1 + .../systemd/system/nftables-exporter.service | 19 ------------------- 2 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 rel/etc/systemd/system/nftables-exporter.service diff --git a/.gitignore b/.gitignore index 39fe8d4..7ce6106 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ vendor bin +rel nftables-exporter.tgz nft.json rules.json 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 From cad774d6ca44c55daa25072aebf1df8082a6b4a4 Mon Sep 17 00:00:00 2001 From: orblazer Date: Fri, 5 Jul 2024 18:44:03 +0200 Subject: [PATCH 2/4] Build for amd64 and arm64 arch fix #18 --- .github/workflows/build.yaml | 2 +- .gitignore | 2 +- Makefile | 70 ++++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7726cf2..a1f6398 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -66,5 +66,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 7ce6106..ae1f842 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ vendor bin rel -nftables-exporter.tgz +nftables-exporter*.tgz nft.json rules.json diff --git a/Makefile b/Makefile index a1467b2..b7e2dbb 100644 --- a/Makefile +++ b/Makefile @@ -6,35 +6,69 @@ VERSION := $(or ${GITHUB_TAG_NAME},$(shell git describe --tags --exact-match 2> GOFILES=$(wildcard *.go) GONAME=$(shell basename "$(PWD)") - -all: - go build \ - -trimpath \ - -tags netgo \ - -ldflags "-X 'github.com/metal-stack/v.Version=$(VERSION)' \ +GO_BUILDINFO= -X 'github.com/metal-stack/v.Version=$(VERSION)' \ -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 + -X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)' - -run: all +run: + $(MAKE) app-local go run $(GOFILES) --config=$(shell pwd)/nftables_exporter.yaml clean: @echo "Cleaning" go clean -.PHONY: release -release: all +## +# Build +## +app-local: + go build \ + -trimpath \ + -tags netgo \ + -ldflags "$(GO_BUILDINFO)" \ + -o bin/$(GONAME)-dev $(GOFILES) + strip bin/$(GONAME)-dev +app-local-goos-goarch: + GOOS=$(GOOS) GOARCH=$(GOARCH) go build \ + -trimpath \ + -tags netgo \ + -ldflags "$(GO_BUILDINFO)" \ + -o bin/$(GONAME)-$(GOOS)-$(GOARCH) $(GOFILES) + strip bin/$(GONAME)-$(GOOS)-$(GOARCH) + sha256sum bin/$(GONAME)-$(GOOS)-$(GOARCH) > bin/$(GONAME)-$(GOOS)-$(GOARCH).sha256 + +build: \ + build-linux-amd64 \ + build-linux-arm64 + +build-linux-amd64: + GOOS=linux GOARCH=amd64 $(MAKE) app-local-goos-goarch +build-linux-arm64: + GOOS=linux GOARCH=arm64 $(MAKE) app-local-goos-goarch + +## +# Release +## + +.PHONY: release-goos-goarch release +release: \ + release-linux-amd64 \ + release-linux-arm64 + +release-linux-amd64: + GOOS=linux GOARCH=amd64 $(MAKE) release-goos-goarch +release-linux-arm64: + GOOS=linux GOARCH=arm64 $(MAKE) release-goos-goarch + +release-goos-goarch: build-$(GOOS)-$(GOARCH) 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 .. \ - && cd - + && 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 - From 4215d6d5ff670bf298e202aa9c30cda3d9eef4c8 Mon Sep 17 00:00:00 2001 From: orblazer Date: Fri, 19 Jul 2024 22:30:22 +0200 Subject: [PATCH 3/4] Simplify makefile --- Makefile | 66 +++++++++++++++++--------------------------------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/Makefile b/Makefile index b7e2dbb..d3d3fdf 100644 --- a/Makefile +++ b/Makefile @@ -6,69 +6,43 @@ VERSION := $(or ${GITHUB_TAG_NAME},$(shell git describe --tags --exact-match 2> GOFILES=$(wildcard *.go) GONAME=$(shell basename "$(PWD)") -GO_BUILDINFO= -X 'github.com/metal-stack/v.Version=$(VERSION)' \ +GOOS := linux +GOARCH := amd64 +BINARY := $(GONAME)-$(GOOS)-$(GOARCH) + +build: + go build \ + -trimpath \ + -tags netgo \ + -ldflags "-X 'github.com/metal-stack/v.Version=$(VERSION)' \ -X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \ -X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \ - -X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)' + -X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'" \ + -o bin/$(BINARY) $(GOFILES) + strip bin/$(BINARY) + sha256sum bin/$(BINARY) > bin/$(BINARY).sha256 run: - $(MAKE) app-local + $(MAKE) build BINARY=$(GONAME)-dev go run $(GOFILES) --config=$(shell pwd)/nftables_exporter.yaml clean: @echo "Cleaning" go clean -## -# Build -## -app-local: - go build \ - -trimpath \ - -tags netgo \ - -ldflags "$(GO_BUILDINFO)" \ - -o bin/$(GONAME)-dev $(GOFILES) - strip bin/$(GONAME)-dev -app-local-goos-goarch: - GOOS=$(GOOS) GOARCH=$(GOARCH) go build \ - -trimpath \ - -tags netgo \ - -ldflags "$(GO_BUILDINFO)" \ - -o bin/$(GONAME)-$(GOOS)-$(GOARCH) $(GOFILES) - strip bin/$(GONAME)-$(GOOS)-$(GOARCH) - sha256sum bin/$(GONAME)-$(GOOS)-$(GOARCH) > bin/$(GONAME)-$(GOOS)-$(GOARCH).sha256 - -build: \ - build-linux-amd64 \ - build-linux-arm64 - -build-linux-amd64: - GOOS=linux GOARCH=amd64 $(MAKE) app-local-goos-goarch -build-linux-arm64: - GOOS=linux GOARCH=arm64 $(MAKE) app-local-goos-goarch - ## # Release ## -.PHONY: release-goos-goarch release -release: \ - release-linux-amd64 \ - release-linux-arm64 - -release-linux-amd64: - GOOS=linux GOARCH=amd64 $(MAKE) release-goos-goarch -release-linux-arm64: - GOOS=linux GOARCH=arm64 $(MAKE) release-goos-goarch - -release-goos-goarch: build-$(GOOS)-$(GOARCH) +.PHONY: release +release: build rm -rf rel rm -f nftables-exporter.tgz mkdir -p rel/usr/bin rel/etc/systemd/system cp bin/nftables-exporter-$(GOOS)-$(GOARCH) rel/usr/bin/nftables-exporter cp systemd/nftables-exporter.service rel/etc/systemd/system cd rel \ - && 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 - + && 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 - From f51e5d4b4c7452198940af14b8b1972af0742ebb Mon Sep 17 00:00:00 2001 From: orblazer Date: Fri, 19 Jul 2024 22:37:22 +0200 Subject: [PATCH 4/4] Support new makefile syntax --- .github/workflows/build.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a1f6398..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: |