Skip to content

Commit 77bf6c4

Browse files
committed
refactor multi arch build
1 parent 73f1f7e commit 77bf6c4

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

Makefile

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,91 @@ all: build
4343

4444
.PHONY: help
4545
help: ## Display this help.
46-
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
46+
@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)
47+
48+
##@ Development
49+
50+
.PHONY: manifests
51+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
52+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
53+
$(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=cmd/embedded/crds
54+
55+
.PHONY: generate
56+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
57+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
58+
59+
.PHONY: fmt
60+
fmt: ## Run go fmt against code.
61+
go fmt ./...
62+
63+
.PHONY: vet
64+
vet: ## Run go vet against code.
65+
go vet ./...
66+
67+
.PHONY: test
68+
test: manifests generate fmt vet envtest ## Run tests.
69+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
70+
71+
##@ Build
72+
73+
.PHONY: build
74+
build: manifests generate fmt vet ## Build manager binary.
75+
go build -o bin/manager cmd/main.go
76+
77+
.PHONY: run
78+
run: manifests generate fmt vet ## Run a controller from your host.
79+
go run ./cmd/main.go start
80+
81+
.PHONY: build-docker-binary
82+
build-docker-binary: manifests generate fmt vet ## Build manager binary.
83+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/manager-linux.amd64 cmd/main.go
84+
85+
86+
# If you wish built the manager image targeting other platforms you can use the --platform flag.
87+
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
88+
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
89+
.PHONY: docker-build
90+
docker-build: build-docker-binary test ## Build docker image with the manager.
91+
$(CONTAINER_TOOL) build -t ${IMG} .
92+
93+
.PHONY: docker-push
94+
docker-push: ## Push docker image with the manager.
95+
$(CONTAINER_TOOL) push ${IMG}
96+
97+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
98+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
99+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
100+
# - be using containerd image store with docker. More Info: https://docs.docker.com/engine/storage/containerd/
101+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
102+
PLATFORMS ?= linux/arm64,linux/amd64
103+
104+
.PHONY: docker-buildx
105+
docker-buildx: test
106+
$(CONTAINER_TOOL) buildx build --platform=$(PLATFORMS) --tag $(IMG) --load -f Dockerfile .
107+
108+
109+
##@ Deployment
110+
111+
ifndef ignore-not-found
112+
ignore-not-found = false
113+
endif
114+
115+
.PHONY: install
116+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
117+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
118+
119+
.PHONY: uninstall
120+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
121+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
122+
123+
.PHONY: deploy
124+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
125+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
126+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
127+
128+
.PHONY: undeploy
129+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
130+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
47131

48132
#----------------------------------------------------------------------------------------------
49133
##@ Build Dependencies

0 commit comments

Comments
 (0)