Skip to content

Commit

Permalink
Build for amd64 and arm64 arch
Browse files Browse the repository at this point in the history
fix #18
  • Loading branch information
orblazer committed Jul 5, 2024
1 parent 8dfa18c commit cad774d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
files: |
bin/nftables-exporter*
nftables-exporter.tgz
nftables-exporter*.tgz
if: ${{ github.event_name == 'release' }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
vendor
bin
rel
nftables-exporter.tgz
nftables-exporter*.tgz
nft.json
rules.json

Expand Down
70 changes: 52 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 -

0 comments on commit cad774d

Please sign in to comment.