generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b95b84
commit c2e9eba
Showing
9 changed files
with
152 additions
and
651 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,88 @@ | ||
# Image URL to use all building/pushing image targets | ||
IMG ?= controller:latest | ||
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. | ||
ENVTEST_K8S_VERSION = 1.25.0 | ||
|
||
# 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 | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
# Setting SHELL to bash allows bash commands to be executed by recipes. | ||
# Options are set to exit when a recipe line exits non-zero or a piped command fails. | ||
SHELL = /usr/bin/env bash -o pipefail | ||
.SHELLFLAGS = -ec | ||
IMG ?= pod-reloader:latest | ||
# K8s version used by envtest | ||
ENVTEST_K8S_VERSION = 1.30.3 | ||
|
||
# Set shell to bash | ||
SHELL = /usr/bin/env bash | ||
.SHELLFLAGS = -o pipefail -ec | ||
|
||
.PHONY: all | ||
all: build | ||
|
||
##@ General | ||
|
||
# The help target prints out all targets with their descriptions organized | ||
# beneath their categories. The categories are represented by '##@' and the | ||
# target descriptions by '##'. The awk commands is responsible for reading the | ||
# entire set of makefiles included in this invocation, looking for lines of the | ||
# file as xyz: ## something, and then pretty-format the target and help. Then, | ||
# if there's a line with ##@ something, that gets pretty-printed as a category. | ||
# More info on the usage of ANSI control characters for terminal formatting: | ||
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters | ||
# More info on the awk command: | ||
# http://linuxcommand.org/lc3_adv_awk.php | ||
|
||
.PHONY: help | ||
help: ## Display this help. | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
help: ## Display this help | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
||
##@ Development | ||
|
||
.PHONY: fmt | ||
fmt: ## Run go fmt against code. | ||
fmt: ## Run go fmt against code | ||
go fmt ./... | ||
|
||
.PHONY: vet | ||
vet: ## Run go vet against code. | ||
vet: ## Run go vet against code | ||
go vet ./... | ||
|
||
##@ Testing | ||
|
||
.PHONY: test | ||
test: fmt vet envtest ## Run tests. | ||
test: fmt vet envtest ## Run tests | ||
KUBEBUILDER_ASSETS="$(LOCALBIN)/k8s/current" go test ./... -coverprofile cover.out | ||
|
||
##@ Build | ||
|
||
.PHONY: build | ||
build: fmt vet ## Build manager binary. | ||
build: fmt vet ## Build manager binary | ||
go build -o bin/manager main.go | ||
|
||
.PHONY: run | ||
run: fmt vet ## Run a controller from your host. | ||
run: fmt vet ## Run a controller from your host | ||
go run ./main.go | ||
|
||
# If you wish built the manager image targeting other platforms you can use the --platform flag. | ||
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it. | ||
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ | ||
# Build docker image in current architecture and tag it as ${IMG} | ||
.PHONY: docker-build | ||
docker-build: test ## Build docker image with the manager. | ||
docker-build: ## Build docker image with the manager | ||
docker build -t ${IMG} . | ||
|
||
# Push docker image to the target specified in ${IMG} | ||
.PHONY: docker-push | ||
docker-push: ## Push docker image with the manager. | ||
docker-push: ## Push docker image with the manager | ||
docker push ${IMG} | ||
|
||
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple | ||
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: | ||
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/ | ||
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/ | ||
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail) | ||
# To properly provided solutions that supports more than one platform you should use this option. | ||
# Build and push docker image for all given platforms | ||
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le | ||
.PHONY: docker-buildx | ||
docker-buildx: test ## Build and push docker image for the manager for cross-platform support | ||
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile | ||
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross | ||
docker-buildx: ## Build and push docker image for the manager for cross-platform support | ||
- docker buildx create --name project-v3-builder | ||
docker buildx use project-v3-builder | ||
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross | ||
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} . | ||
- docker buildx rm project-v3-builder | ||
rm Dockerfile.cross | ||
|
||
|
||
##@ Build Dependencies | ||
|
||
## Location to install dependencies to | ||
LOCALBIN ?= $(shell pwd)/bin | ||
$(LOCALBIN): | ||
mkdir -p $(LOCALBIN) | ||
|
||
## Tool Binaries | ||
ENVTEST ?= $(LOCALBIN)/setup-envtest | ||
@mkdir -p $(LOCALBIN) | ||
|
||
.PHONY: setup-envtest | ||
setup-envtest: $(LOCALBIN) ## Install setup-envtest | ||
@go mod download sigs.k8s.io/controller-runtime/tools/setup-envtest && \ | ||
VERSION=$$(go list -m -f '{{.Version}}' sigs.k8s.io/controller-runtime/tools/setup-envtest) && \ | ||
if [ ! -L $(LOCALBIN)/setup-envtest ] || [ "$$(readlink $(LOCALBIN)/setup-envtest)" != "setup-envtest-$$VERSION" ]; then \ | ||
echo "Installing setup-envtest $$VERSION" && \ | ||
rm -f $(LOCALBIN)/setup-envtest && \ | ||
GOBIN=$(LOCALBIN) go install $$(go list -m -f '{{.Dir}}' sigs.k8s.io/controller-runtime/tools/setup-envtest) && \ | ||
mv $(LOCALBIN)/setup-envtest $(LOCALBIN)/setup-envtest-$$VERSION && \ | ||
ln -s setup-envtest-$$VERSION $(LOCALBIN)/setup-envtest; \ | ||
fi | ||
|
||
.PHONY: envtest | ||
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. | ||
$(ENVTEST): $(LOCALBIN) | ||
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest | ||
ENVTESTDIR=$$($(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path) ;\ | ||
chmod -R u+w $$ENVTESTDIR ;\ | ||
rm -f $(LOCALBIN)/k8s/current ;\ | ||
envtest: setup-envtest ## Install envtest binaries | ||
@ENVTESTDIR=$$($(LOCALBIN)/setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path) && \ | ||
chmod -R u+w $$ENVTESTDIR && \ | ||
rm -f $(LOCALBIN)/k8s/current && \ | ||
ln -s $$ENVTESTDIR $(LOCALBIN)/k8s/current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.