webhook/Makefile
Ian Roberts f89b09bef6
fix: use CGO_ENABLED=0 for release builds (#705)
Ensure that release builds are built with cgo disabled.  This is usually the case for cross-compiled builds anyway, but adding this flag makes builds consistent regardless of what platform they are being built on.

In particular, without CGO_ENABLED=0, if you make the release builds on a linux/amd64 system then the linux/amd64 binary is dynamically linked against the system libc, meaning a binary built on a glibc-based system like Ubuntu will not work on a musl libc system like Alpine.  This is what appears to have happened for release 2.8.1.

But the same source code built on a different system (e.g. darwin/arm64) would cross-compile the linux/amd64 binary with cgo disabled, making a static binary that works on both glibc and musl systems.  This is what appears to have happened for release 2.8.2.

Setting CGO_ENABLED=0 in the Makefile will make the behaviour consistent for future releases, producing static binaries for the linux builds in all cases, whatever the build platform.
2024-10-27 17:27:31 +01:00

44 lines
1.2 KiB
Makefile

OS = darwin freebsd linux openbsd
ARCHS = 386 arm amd64 arm64
.DEFAULT_GOAL := help
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}'
all: build release release-windows
build: deps ## Build the project
go build
release: clean deps ## Generate releases for unix systems
@for arch in $(ARCHS);\
do \
for os in $(OS);\
do \
echo "Building $$os-$$arch"; \
mkdir -p build/webhook-$$os-$$arch/; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -o build/webhook-$$os-$$arch/webhook; \
tar cz -C build -f build/webhook-$$os-$$arch.tar.gz webhook-$$os-$$arch; \
done \
done
release-windows: clean deps ## Generate release for windows
@for arch in $(ARCHS);\
do \
echo "Building windows-$$arch"; \
mkdir -p build/webhook-windows-$$arch/; \
GOOS=windows GOARCH=$$arch go build -o build/webhook-windows-$$arch/webhook.exe; \
tar cz -C build -f build/webhook-windows-$$arch.tar.gz webhook-windows-$$arch; \
done
test: deps ## Execute tests
go test ./...
deps: ## Install dependencies using go get
go get -d -v -t ./...
clean: ## Remove building artifacts
rm -rf build
rm -f webhook