1
- # CONTAINER_TOOL defines the container tool to be used for building images.
2
- # Be aware that the target commands are only tested with Docker which is
3
- # scaffolded by default. However, you might want to replace it to use other
4
- # tools. (i.e. podman)
5
- CONTAINER_TOOL ?= docker
6
1
# Image URL to use all building/pushing image targets
7
2
IMG ?= nbv2-backend:latest
8
- # Backend default port
9
- PORT ?= 4000
10
3
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
11
- ENVTEST_K8S_VERSION = 1.29 .0
4
+ ENVTEST_K8S_VERSION = 1.31 .0
12
5
13
6
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
14
7
ifeq (,$(shell go env GOBIN) )
17
10
GOBIN =$(shell go env GOBIN)
18
11
endif
19
12
13
+ # Backend default port
14
+ PORT ?= 4000
15
+
16
+ # CONTAINER_TOOL defines the container tool to be used for building images.
17
+ # Be aware that the target commands are only tested with Docker which is
18
+ # scaffolded by default. However, you might want to replace it to use other
19
+ # tools. (i.e. podman)
20
+ CONTAINER_TOOL ?= docker
21
+
20
22
# Setting SHELL to bash allows bash commands to be executed by recipes.
21
23
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
22
24
SHELL = /usr/bin/env bash -o pipefail
@@ -27,6 +29,17 @@ all: build
27
29
28
30
# #@ General
29
31
32
+ # The help target prints out all targets with their descriptions organized
33
+ # beneath their categories. The categories are represented by '##@' and the
34
+ # target descriptions by '##'. The awk command is responsible for reading the
35
+ # entire set of makefiles included in this invocation, looking for lines of the
36
+ # file as xyz: ## something, and then pretty-format the target and help. Then,
37
+ # if there's a line with ##@ something, that gets pretty-printed as a category.
38
+ # More info on the usage of ANSI control characters for terminal formatting:
39
+ # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
40
+ # More info on the awk command:
41
+ # http://linuxcommand.org/lc3_adv_awk.php
42
+
30
43
.PHONY : help
31
44
help : # # Display this help.
32
45
@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 )
@@ -43,11 +56,10 @@ vet: ## Run go vet against code.
43
56
44
57
.PHONY : test
45
58
test : fmt vet envtest # # Run tests.
46
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " \
47
- go test ./... -coverprofile cover.out
59
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test ./... -coverprofile cover.out
48
60
49
61
.PHONY : lint
50
- lint : golangci-lint # # Run golangci-lint linter & yamllint
62
+ lint : golangci-lint # # Run golangci-lint linter
51
63
$(GOLANGCI_LINT ) run
52
64
53
65
.PHONY : lint-fix
@@ -57,13 +69,16 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
57
69
# #@ Build
58
70
59
71
.PHONY : build
60
- build : fmt vet envtest # # Build backend binary.
72
+ build : fmt vet # # Build backend binary.
61
73
go build -o bin/backend cmd/main.go
62
74
63
75
.PHONY : run
64
76
run : fmt vet # # Run a backend from your host.
65
- go run ./cmd/main.go --port=$(PORT )
77
+ go run ./cmd/main.go --port=$(PORT )
66
78
79
+ # If you wish to build the manager image targeting other platforms you can use the --platform flag.
80
+ # (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
81
+ # More info: https://docs.docker.com/develop/develop-images/build_enhancements/
67
82
.PHONY : docker-build
68
83
docker-build : # # Build docker image with the backend.
69
84
$(CONTAINER_TOOL ) build -t ${IMG} .
@@ -72,6 +87,23 @@ docker-build: ## Build docker image with the backend.
72
87
docker-push : # # Push docker image with the backend.
73
88
$(CONTAINER_TOOL ) push ${IMG}
74
89
90
+ # PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
91
+ # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
92
+ # - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
93
+ # - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
94
+ # - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
95
+ # To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
96
+ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
97
+ .PHONY : docker-buildx
98
+ docker-buildx : # # Build and push docker image for the manager for cross-platform support
99
+ # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
100
+ sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
101
+ - $(CONTAINER_TOOL ) buildx create --name project-v3-builder
102
+ $(CONTAINER_TOOL ) buildx use project-v3-builder
103
+ - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
104
+ - $(CONTAINER_TOOL ) buildx rm project-v3-builder
105
+ rm Dockerfile.cross
106
+
75
107
# #@ Dependencies
76
108
77
109
# # Location to install dependencies to
@@ -81,13 +113,12 @@ $(LOCALBIN):
81
113
82
114
# # Tool Binaries
83
115
KUBECTL ?= kubectl
84
- ENVTEST ?= $(LOCALBIN ) /setup-envtest- $( ENVTEST_VERSION )
85
- GOLANGCI_LINT ? = $(LOCALBIN ) /golangci-lint- $( GOLANGCI_LINT_VERSION )
116
+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
117
+ GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
86
118
87
119
# # Tool Versions
88
- KUSTOMIZE_VERSION ?= v5.3.0
89
- ENVTEST_VERSION ?= release-0.17
90
- GOLANGCI_LINT_VERSION ?= v1.57.2
120
+ ENVTEST_VERSION ?= release-0.19
121
+ GOLANGCI_LINT_VERSION ?= v1.61.0
91
122
92
123
.PHONY : envtest
93
124
envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
@@ -97,19 +128,20 @@ $(ENVTEST): $(LOCALBIN)
97
128
.PHONY : golangci-lint
98
129
golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
99
130
$(GOLANGCI_LINT ) : $(LOCALBIN )
100
- $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
101
-
131
+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
102
132
103
133
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
104
- # $1 - target path with name of binary (ideally with version)
134
+ # $1 - target path with name of binary
105
135
# $2 - package url which can be installed
106
136
# $3 - specific version of package
107
137
define go-install-tool
108
- @[ -f $(1 ) ] || { \
138
+ @[ -f " $(1 ) - $( 3 ) " ] || { \
109
139
set -e; \
110
140
package=$(2 ) @$(3 ) ;\
111
141
echo "Downloading $${package}" ;\
142
+ rm -f $(1 ) || true ;\
112
143
GOBIN=$(LOCALBIN ) go install $${package} ;\
113
- mv "$$(echo "$(1 ) " | sed "s/-$(3 ) $$//" ) " $(1 ) ;\
114
- }
144
+ mv $(1 ) $(1 ) -$(3 ) ;\
145
+ } ;\
146
+ ln -sf $(1 ) -$(3 ) $(1 )
115
147
endef
0 commit comments