24
24
SHELL:=/usr/bin/env bash
25
25
.DEFAULT_GOAL:=help
26
26
27
+ #
28
+ # Go.
29
+ #
30
+ GO_VERSION ?= 1.22.5
31
+
27
32
# Use GOPROXY environment variable if set
28
33
GOPROXY := $(shell go env GOPROXY)
29
34
ifeq ($(GOPROXY),)
@@ -34,6 +39,13 @@ export GOPROXY
34
39
# Active module mode, as we use go modules to manage dependencies
35
40
export GO111MODULE=on
36
41
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
+
37
49
# Tools.
38
50
TOOLS_DIR := hack/tools
39
51
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
@@ -123,6 +135,48 @@ modules: ## Runs go mod to ensure modules are up to date.
123
135
cd $(ENVTEST_DIR); go mod tidy
124
136
cd $(SCRATCH_ENV_DIR); go mod tidy
125
137
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
+
126
180
## --------------------------------------
127
181
## Cleanup / Verification
128
182
## --------------------------------------
@@ -136,6 +190,10 @@ clean: ## Cleanup.
136
190
clean-bin: ## Remove all generated binaries.
137
191
rm -rf hack/tools/bin
138
192
193
+ .PHONY: clean-release
194
+ clean-release: ## Remove the release folder
195
+ rm -rf $(RELEASE_DIR)
196
+
139
197
.PHONY: verify-modules
140
198
verify-modules: modules $(GO_MOD_CHECK) ## Verify go modules are up to date
141
199
@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)
149
207
.PHONY: apidiff
150
208
verify-apidiff: $(GO_APIDIFF) ## Check for API differences
151
209
$(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