-
Notifications
You must be signed in to change notification settings - Fork 112
/
Makefile
83 lines (65 loc) · 3.07 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
.PHONY: clean test check build.local build.linux build.osx build.docker build.push
BINARY ?= kube-metrics-adapter
VERSION ?= $(shell git describe --tags --always --dirty)
IMAGE ?= registry-write.opensource.zalan.do/teapot/$(BINARY)
TAG ?= $(VERSION)
SOURCES = $(shell find . -name '*.go')
DOCKERFILE ?= Dockerfile
GOPKGS = $(shell go list ./...)
BUILD_FLAGS ?= -v
OPENAPI ?= pkg/api/generated/openapi/zz_generated.openapi.go
LDFLAGS ?= -X main.version=$(VERSION) -w -s
CRD_SOURCES = $(shell find pkg/apis/zalando.org -name '*.go')
CRD_TYPE_SOURCE = pkg/apis/zalando.org/v1/types.go
GENERATED_CRDS = docs/scaling_schedules_crd.yaml
GENERATED = pkg/apis/zalando.org/v1/zz_generated.deepcopy.go
default: build.local
clean:
rm -rf build
rm -rf $(OPENAPI)
test: $(GENERATED)
go test -v -coverprofile=profile.cov $(GOPKGS)
check: $(GENERATED)
go mod download
golangci-lint run --timeout=2m ./...
$(GENERATED): go.mod $(CRD_TYPE_SOURCE) $(OPENAPI)
./hack/update-codegen.sh
$(GENERATED_CRDS): $(GENERATED) $(CRD_SOURCES)
go run sigs.k8s.io/controller-tools/cmd/controller-gen crd:crdVersions=v1 paths=./pkg/apis/... output:crd:dir=docs
mv docs/zalando.org_clusterscalingschedules.yaml docs/cluster_scaling_schedules_crd.yaml
mv docs/zalando.org_scalingschedules.yaml docs/scaling_schedules_crd.yaml
$(OPENAPI): go.mod
go run k8s.io/kube-openapi/cmd/openapi-gen \
--go-header-file hack/boilerplate.go.txt \
--logtostderr \
--output-dir pkg/api/generated/openapi \
--output-pkg github.com/zalando-incubator/kube-metrics-adapter/pkg/api/generated/openapi \
--output-file zz_generated.openapi.go \
-r /dev/null \
k8s.io/metrics/pkg/apis/custom_metrics \
k8s.io/metrics/pkg/apis/custom_metrics/v1beta1 \
k8s.io/metrics/pkg/apis/custom_metrics/v1beta2 \
k8s.io/metrics/pkg/apis/external_metrics \
k8s.io/metrics/pkg/apis/external_metrics/v1beta1 \
k8s.io/metrics/pkg/apis/metrics \
k8s.io/metrics/pkg/apis/metrics/v1beta1 \
k8s.io/apimachinery/pkg/apis/meta/v1 \
k8s.io/apimachinery/pkg/api/resource \
k8s.io/apimachinery/pkg/version \
k8s.io/api/core/v1
build.local: build/$(BINARY) $(GENERATED_CRDS)
build.linux: build/linux/$(BINARY)
build.linux.amd64: build/linux/amd64/$(BINARY)
build.linux.arm64: build/linux/arm64/$(BINARY)
build/$(BINARY): go.mod $(SOURCES) $(GENERATED)
CGO_ENABLED=0 go build -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" .
build/linux/$(BINARY): go.mod $(SOURCES) $(GENERATED)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/linux/$(BINARY) -ldflags "$(LDFLAGS)" .
build/linux/amd64/$(BINARY): go.mod $(SOURCES)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/linux/amd64/$(BINARY) -ldflags "$(LDFLAGS)" .
build/linux/arm64/$(BINARY): go.mod $(SOURCES)
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/linux/arm64/$(BINARY) -ldflags "$(LDFLAGS)" .
build.docker: build.linux
docker build --rm -t "$(IMAGE):$(TAG)" -f $(DOCKERFILE) --build-arg TARGETARCH= .
build.push: build.docker
docker push "$(IMAGE):$(TAG)"