Skip to content

Commit 1ad805c

Browse files
authored
Refactor Makefile (#538)
* Update go-install-tool function * Remove hardcoded ENVTEST_K8S_VERSION * Add CONTAINER_TOOL env variable
1 parent 600a91b commit 1ad805c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

Makefile

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
BIN_NAME = "cloud-provider-ironcore"
22
IMG ?= controller:latest
33

4-
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5-
ENVTEST_K8S_VERSION = 1.32
6-
4+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
75
ifeq (,$(shell go env GOBIN))
86
GOBIN=$(shell go env GOPATH)/bin
97
else
108
GOBIN=$(shell go env GOBIN)
119
endif
1210

11+
# CONTAINER_TOOL defines the container tool to be used for building images.
12+
# Be aware that the target commands are only tested with Docker which is
13+
# scaffolded by default. However, you might want to replace it to use other
14+
# tools. (i.e. podman)
15+
CONTAINER_TOOL ?= docker
16+
17+
# Setting SHELL to bash allows bash commands to be executed by recipes.
18+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1319
SHELL = /usr/bin/env bash -o pipefail
1420
.SHELLFLAGS = -ec
1521

@@ -62,14 +68,14 @@ vet: ## Run go vet against code.
6268
test: fmt vet envtest ## Run tests.
6369
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
6470

65-
.PHONY: docker-build
6671
# Build the docker image
67-
docker-build:
68-
docker build . -t $(IMG)
72+
.PHONY: docker-build
73+
docker-build: ## Build docker image with the manager.
74+
$(CONTAINER_TOOL) build -t ${IMG} .
6975

7076
.PHONY: docker-push
71-
docker-push:
72-
docker push $(IMG)
77+
docker-push: ## Push docker image with the manager.
78+
$(CONTAINER_TOOL) push ${IMG}
7379

7480
.PHONY: clean-local-bin
7581
clean-local-bin:
@@ -130,13 +136,13 @@ $(GOLANGCI_LINT): $(LOCALBIN)
130136
# $2 - package url which can be installed
131137
# $3 - specific version of package
132138
define go-install-tool
133-
@[ -f "$(1)-$(3)" ] || { \
139+
@[ -f "$(1)-$(3)" ] && [ "$$(readlink -- "$(1)" 2>/dev/null)" = "$(1)-$(3)" ] || { \
134140
set -e; \
135141
package=$(2)@$(3) ;\
136142
echo "Downloading $${package}" ;\
137-
rm -f $(1) || true ;\
143+
rm -f $(1) ;\
138144
GOBIN=$(LOCALBIN) go install $${package} ;\
139145
mv $(1) $(1)-$(3) ;\
140146
} ;\
141-
ln -sf $(1)-$(3) $(1)
147+
ln -sf $$(realpath $(1)-$(3)) $(1)
142148
endef

0 commit comments

Comments
 (0)