sigs.k8s.io/external-dns@v0.14.1/Makefile (about) 1 # Copyright 2017 The Kubernetes Authors. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 # cover-html creates coverage report for whole project excluding vendor and opens result in the default browser 16 .PHONY: cover cover-html 17 .DEFAULT_GOAL := build 18 19 cover: 20 go get github.com/wadey/gocovmerge 21 $(eval PKGS := $(shell go list ./... | grep -v /vendor/)) 22 $(eval PKGS_DELIM := $(shell echo $(PKGS) | tr / -')) 23 go list -f '{{if or (len .TestGoFiles) (len .XTestGoFiles)}}go test -test.v -test.timeout=120s -covermode=count -coverprofile={{.Name}}_{{len .Imports}}_{{len .Deps}}.coverprofile -coverpkg $(PKGS_DELIM) {{.ImportPath}}{{end}}' $(PKGS) | xargs -0 sh -c 24 gocovmerge `ls *.coverprofile` > cover.out 25 rm *.coverprofile 26 27 cover-html: cover 28 go tool cover -html cover.out 29 30 # find or download controller-gen 31 # download controller-gen if necessary 32 controller-gen: 33 ifeq (, $(shell which controller-gen)) 34 @{ \ 35 set -e ;\ 36 CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ 37 cd $$CONTROLLER_GEN_TMP_DIR ;\ 38 go mod init tmp ;\ 39 go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0 ;\ 40 rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ 41 } 42 CONTROLLER_GEN=$(GOBIN)/controller-gen 43 else 44 CONTROLLER_GEN=$(shell which controller-gen) 45 endif 46 47 golangci-lint: 48 @command -v golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2 49 50 # Run the golangci-lint tool 51 .PHONY: go-lint 52 go-lint: golangci-lint 53 golangci-lint run --timeout=30m ./... 54 55 # Run the licensecheck script to check for license headers 56 .PHONY: licensecheck 57 licensecheck: 58 @echo ">> checking license header" 59 @licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \ 60 awk 'NR<=5' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \ 61 done); \ 62 if [ -n "$${licRes}" ]; then \ 63 echo "license header checking failed:"; echo "$${licRes}"; \ 64 exit 1; \ 65 fi 66 67 # Run all the linters 68 .PHONY: lint 69 lint: licensecheck go-lint 70 71 # generates CRD using controller-gen 72 .PHONY: crd 73 crd: controller-gen 74 ${CONTROLLER_GEN} crd:crdVersions=v1 paths="./endpoint/..." output:crd:stdout > docs/contributing/crd-source/crd-manifest.yaml 75 76 # The verify target runs tasks similar to the CI tasks, but without code coverage 77 .PHONY: test 78 test: 79 go test -race -coverprofile=profile.cov ./... 80 81 # The build targets allow to build the binary and container image 82 .PHONY: build 83 84 BINARY ?= external-dns 85 SOURCES = $(shell find . -name '*.go') 86 IMAGE_STAGING = gcr.io/k8s-staging-external-dns/$(BINARY) 87 REGISTRY ?= us.gcr.io/k8s-artifacts-prod/external-dns 88 IMAGE ?= $(REGISTRY)/$(BINARY) 89 VERSION ?= $(shell git describe --tags --always --dirty --match "v*") 90 BUILD_FLAGS ?= -v 91 LDFLAGS ?= -X sigs.k8s.io/external-dns/pkg/apis/externaldns.Version=$(VERSION) -w -s 92 ARCH ?= amd64 93 SHELL = /bin/bash 94 IMG_PLATFORM ?= linux/amd64,linux/arm64,linux/arm/v7 95 IMG_PUSH ?= true 96 IMG_SBOM ?= none 97 98 build: build/$(BINARY) 99 100 build/$(BINARY): $(SOURCES) 101 CGO_ENABLED=0 go build -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" . 102 103 build.push/multiarch: ko 104 KO_DOCKER_REPO=${IMAGE} \ 105 VERSION=${VERSION} \ 106 ko build --tags ${VERSION} --bare --sbom ${IMG_SBOM} \ 107 --image-label org.opencontainers.image.source="https://github.com/kubernetes-sigs/external-dns" \ 108 --image-label org.opencontainers.image.revision=$(shell git rev-parse HEAD) \ 109 --platform=${IMG_PLATFORM} --push=${IMG_PUSH} . 110 111 build.image/multiarch: 112 $(MAKE) IMG_PUSH=false build.push/multiarch 113 114 build.image: 115 $(MAKE) IMG_PLATFORM=linux/$(ARCH) build.image/multiarch 116 117 build.image-amd64: 118 $(MAKE) ARCH=amd64 build.image 119 120 build.image-arm64: 121 $(MAKE) ARCH=arm64 build.image 122 123 build.image-arm/v7: 124 $(MAKE) ARCH=arm/v7 build.image 125 126 build.push: 127 $(MAKE) IMG_PLATFORM=linux/$(ARCH) build.push/multiarch 128 129 build.push-amd64: 130 $(MAKE) ARCH=amd64 build.push 131 132 build.push-arm64: 133 $(MAKE) ARCH=arm64 build.push 134 135 build.push-arm/v7: 136 $(MAKE) ARCH=arm/v7 build.push 137 138 build.arm64: 139 CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" . 140 141 build.amd64: 142 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" . 143 144 build.arm/v7: 145 CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" . 146 147 clean: 148 @rm -rf build 149 @go clean -cache 150 151 # Builds and push container images to the staging bucket. 152 .PHONY: release.staging 153 154 release.staging: test 155 IMAGE=$(IMAGE_STAGING) $(MAKE) build.push/multiarch 156 157 release.prod: test 158 $(MAKE) build.push/multiarch 159 160 .PHONY: ko 161 ko: 162 scripts/install-ko.sh