Skip to content

Commit

Permalink
Merge pull request #902 from Victoremepunto/configure-go-version-make…
Browse files Browse the repository at this point in the history
…file

Allow configurable go version for Makefile
  • Loading branch information
psav authored Dec 18, 2023
2 parents 9ffeb6d + 553fb32 commit 02384b8
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
IMAGE_TAG_BASE ?= quay.io/cloudservices/clowder
CLOWDER_BUILD_TAG ?= $(shell git rev-parse --short=8 HEAD)

GO_CMD ?= go

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26
Expand All @@ -31,18 +32,18 @@ endif
GOJSONSCHEMA_BIN := $(shell which gojsonschema 2> /dev/null)
ifndef GOJSONSCHEMA_BIN
$(info gojsonschema binary not found. Installing...)
$(shell go install github.com/atombender/go-jsonschema/cmd/[email protected])
$(shell $(GO_CMD) install github.com/atombender/go-jsonschema/cmd/[email protected])
$(info Ensure that $$GOPATH/bin is in your PATH.)
endif


KUTTL_TEST ?= ""

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
ifeq (,$(shell $(GO_CMD) env GOBIN))
GOBIN=$(shell $(GO_CMD) env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
GOBIN=$(shell $(GO_CMD) env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
Expand Down Expand Up @@ -94,13 +95,13 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

fmt: ## Run go fmt against code.
go fmt ./...
$(GO_CMD) fmt ./...

vet: ## Run go vet against code.
go vet ./...
$(GO_CMD) vet ./...

test: update-version manifests envtest generate fmt vet
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" CLOWDER_CONFIG_PATH=$(PROJECT_DIR)/test_config.json go test ./... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" CLOWDER_CONFIG_PATH=$(PROJECT_DIR)/test_config.json $(GO_CMD) test ./... -coverprofile cover.out

vscode-debug: update-version manifests envtest generate fmt vet
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" code .
Expand All @@ -119,10 +120,10 @@ genconfig:
cd controllers/cloud.redhat.com/config && gojsonschema -p config -o types.go schema.json

build: update-version generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
$(GO_CMD) build -o bin/manager main.go

run: update-version manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
$(GO_CMD) run ./main.go

docker-build-and-push-base:
$(RUNTIME) build -f Dockerfile.base . -t $(BASE_IMG)
Expand All @@ -134,7 +135,7 @@ docker-build: update-version

# Build the docker image
docker-build-no-test-quick: update-version
CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -o bin/manager-cgo main.go
CGO_ENABLED=0 GOOS=linux GO111MODULE=on $(GO_CMD) build -o bin/manager-cgo main.go
$(RUNTIME) build -f build/Dockerfile-local . -t ${IMG}

# Build the docker image
Expand Down Expand Up @@ -200,9 +201,9 @@ define go-install-tool
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
$(GO_CMD) mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
GOBIN=$(PROJECT_DIR)/bin $(GO_CMD) install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef

0 comments on commit 02384b8

Please sign in to comment.