2424SHELL: =/usr/bin/env bash
2525.DEFAULT_GOAL: =help
2626
27+ #
28+ # Go.
29+ #
30+ GO_VERSION ?= 1.22.5
31+
2732# Use GOPROXY environment variable if set
2833GOPROXY := $(shell go env GOPROXY)
2934ifeq ($(GOPROXY ) ,)
@@ -34,6 +39,13 @@ export GOPROXY
3439# Active module mode, as we use go modules to manage dependencies
3540export GO111MODULE =on
3641
42+ # Hosts running SELinux need :z added to volume mounts
43+ SELINUX_ENABLED := $(shell cat /sys/fs/selinux/enforce 2> /dev/null || echo 0)
44+
45+ ifeq ($(SELINUX_ENABLED ) ,1)
46+ DOCKER_VOL_OPTS? =:z
47+ endif
48+
3749# Tools.
3850TOOLS_DIR := hack/tools
3951TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR ) /bin)
@@ -123,6 +135,48 @@ modules: ## Runs go mod to ensure modules are up to date.
123135 cd $(ENVTEST_DIR ) ; go mod tidy
124136 cd $(SCRATCH_ENV_DIR ) ; go mod tidy
125137
138+ # # --------------------------------------
139+ # # Release
140+ # # --------------------------------------
141+
142+ RELEASE_DIR := tools/setup-envtest/out
143+
144+ .PHONY : $(RELEASE_DIR )
145+ $(RELEASE_DIR ) :
146+ mkdir -p $(RELEASE_DIR ) /
147+
148+ .PHONY : release
149+ release : clean-release $(RELEASE_DIR ) # # Build release.
150+ @if ! [ -z " $$ (git status --porcelain)" ]; then echo " Your local git repository contains uncommitted changes, use git clean before proceeding." ; exit 1; fi
151+
152+ # Build binaries first.
153+ $(MAKE) release-binaries
154+
155+ .PHONY : release-binaries
156+ release-binaries : # # Build release binaries.
157+ RELEASE_BINARY=setup-envtest-linux-amd64 GOOS=linux GOARCH=amd64 $(MAKE ) release-binary
158+ RELEASE_BINARY=setup-envtest-linux-arm64 GOOS=linux GOARCH=arm64 $(MAKE ) release-binary
159+ RELEASE_BINARY=setup-envtest-linux-ppc64le GOOS=linux GOARCH=ppc64le $(MAKE ) release-binary
160+ RELEASE_BINARY=setup-envtest-linux-s390x GOOS=linux GOARCH=s390x $(MAKE ) release-binary
161+ RELEASE_BINARY=setup-envtest-darwin-amd64 GOOS=darwin GOARCH=amd64 $(MAKE ) release-binary
162+ RELEASE_BINARY=setup-envtest-darwin-arm64 GOOS=darwin GOARCH=arm64 $(MAKE ) release-binary
163+ RELEASE_BINARY=setup-envtest-windows-amd64.exe GOOS=windows GOARCH=amd64 $(MAKE ) release-binary
164+
165+ .PHONY : release-binary
166+ release-binary : $(RELEASE_DIR )
167+ docker run \
168+ --rm \
169+ -e CGO_ENABLED=0 \
170+ -e GOOS=$(GOOS ) \
171+ -e GOARCH=$(GOARCH ) \
172+ -e GOCACHE=/tmp/ \
173+ --user $$(id -u ) :$$(id -g ) \
174+ -v " $$ (pwd):/workspace$( DOCKER_VOL_OPTS) " \
175+ -w /workspace/tools/setup-envtest \
176+ golang:$(GO_VERSION ) \
177+ go build -a -trimpath -ldflags " -extldflags '-static'" \
178+ -o ./out/$(RELEASE_BINARY ) ./
179+
126180# # --------------------------------------
127181# # Cleanup / Verification
128182# # --------------------------------------
@@ -136,6 +190,10 @@ clean: ## Cleanup.
136190clean-bin : # # Remove all generated binaries.
137191 rm -rf hack/tools/bin
138192
193+ .PHONY : clean-release
194+ clean-release : # # Remove the release folder
195+ rm -rf $(RELEASE_DIR )
196+
139197.PHONY : verify-modules
140198verify-modules : modules $(GO_MOD_CHECK ) # # Verify go modules are up to date
141199 @if ! (git diff --quiet HEAD -- go.sum go.mod $( TOOLS_DIR) /go.mod $( TOOLS_DIR) /go.sum $( ENVTEST_DIR) /go.mod $( ENVTEST_DIR) /go.sum $( SCRATCH_ENV_DIR) /go.sum); then \
@@ -149,3 +207,12 @@ APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
149207.PHONY : apidiff
150208verify-apidiff : $(GO_APIDIFF ) # # Check for API differences
151209 $(GO_APIDIFF ) $(APIDIFF_OLD_COMMIT ) --print-compatible
210+
211+ # # --------------------------------------
212+ # # Helpers
213+ # # --------------------------------------
214+
215+ # #@ helpers:
216+
217+ go-version : # # Print the go version we use to compile our binaries and images
218+ @echo $(GO_VERSION )
0 commit comments