forked from kubernetes-sigs/metrics-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
144 lines (109 loc) · 4 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Common User-Settable Flags
# --------------------------
REGISTRY?=gcr.io/k8s-staging-metrics-server
ARCH?=amd64
# Release variables
# ------------------
GIT_COMMIT?=$(shell git rev-parse "HEAD^{commit}" 2>/dev/null)
GIT_TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null)
BUILD_DATE:=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
# Consts
# ------
ALL_ARCHITECTURES=amd64 arm arm64 ppc64le s390x
GOLANGCI_VERSION=v1.23.6
export DOCKER_CLI_EXPERIMENTAL=enabled
# Computed variables
# ------------------
HAS_GOLANGCI:=$(shell which golangci-lint)
GOPATH:=$(shell go env GOPATH)
REPO_DIR:=$(shell pwd)
LDFLAGS=-w $(VERSION_LDFLAGS)
.PHONY: all
all: _output/$(ARCH)/metrics-server
# Build Rules
# -----------
src_deps=$(shell find pkg cmd -type f -name "*.go")
LDFLAGS:=-X sigs.k8s.io/metrics-server/pkg/version.gitVersion=$(GIT_TAG) -X sigs.k8s.io/metrics-server/pkg/version.gitCommit=$(GIT_COMMIT) -X sigs.k8s.io/metrics-server/pkg/version.buildDate=$(BUILD_DATE)
_output/%/metrics-server: $(src_deps) _output
GO111MODULE=on GOARCH=$* CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o _output/$*/metrics-server sigs.k8s.io/metrics-server/cmd/metrics-server
yaml_deps=$(shell find manifests -type f -name "*.yaml")
_output/components.yaml: $(yaml_deps) _output
cat manifests/*.yaml > _output/components.yaml
_output:
mkdir -p _output
# Image Rules
# -----------
.PHONY: container
container: container-$(ARCH)
.PHONY: container-*
container-%:
docker build --pull -t $(REGISTRY)/metrics-server-$*:$(GIT_COMMIT) --build-arg GOARCH=$* --build-arg LDFLAGS='$(LDFLAGS)' .
# Official Container Push Rules
# -----------------------------
.PHONY: push
push: $(addprefix sub-push-,$(ALL_ARCHITECTURES)) push-multi-arch;
.PHONY: sub-push-*
sub-push-%: container-% do-push-% ;
.PHONY: do-push-*
do-push-%:
docker tag $(REGISTRY)/metrics-server-$*:$(GIT_COMMIT) $(REGISTRY)/metrics-server-$*:$(GIT_TAG)
docker push $(REGISTRY)/metrics-server-$*:$(GIT_TAG)
.PHONY: push-multi-arch
push-multi-arch:
docker manifest create --amend $(REGISTRY)/metrics-server:$(GIT_TAG) $(shell echo $(ALL_ARCHITECTURES) | sed -e "s~[^ ]*~$(REGISTRY)/metrics-server\-&:$(GIT_TAG)~g")
@for arch in $(ALL_ARCHITECTURES); do docker manifest annotate --arch $${arch} $(REGISTRY)/metrics-server:$(GIT_TAG) $(REGISTRY)/metrics-server-$${arch}:${GIT_TAG}; done
docker manifest push --purge $(REGISTRY)/metrics-server:$(GIT_TAG)
# Release rules
# -------------
.PHONY: release-tag
release-tag:
git tag $(GIT_TAG)
git push $(GIT_TAG)
.PHONY: release-manifests
release-manifests: _output/components.yaml
echo "Please upload file _output/components.yaml to GitHub release"
# Unit tests
# ----------
.PHONY: test-unit
test-unit:
ifeq ($(ARCH),amd64)
GO111MODULE=on GOARCH=$(ARCH) go test --test.short -race ./pkg/...
else
GO111MODULE=on GOARCH=$(ARCH) go test --test.short ./pkg/...
endif
# Binary tests
# ------------
.PHONY: test-version
test-version: container
IMAGE=$(REGISTRY)/metrics-server-$(ARCH):$(GIT_COMMIT) EXPECTED_VERSION=$(GIT_TAG) ./test/version.sh
# E2e tests
# -----------
.PHONY: test-e2e
test-e2e: test-e2e-1.17
.PHONY: test-e2e-all
test-e2e-all: test-e2e-1.17 test-e2e-1.16 test-e2e-1.15
.PHONY: test-e2e-1.17
test-e2e-1.17: container-amd64 _output/components.yaml
KUBERNETES_VERSION=v1.17.0 IMAGE=$(REGISTRY)/metrics-server-amd64:$(GIT_COMMIT) ./test/e2e.sh
.PHONY: test-e2e-1.16
test-e2e-1.16: container-amd64 _output/components.yaml
KUBERNETES_VERSION=v1.16.1 IMAGE=$(REGISTRY)/metrics-server-amd64:$(GIT_COMMIT) ./test/e2e.sh
.PHONY: test-e2e-1.15
test-e2e-1.15: container-amd64 _output/components.yaml
KUBERNETES_VERSION=v1.15.0 IMAGE=$(REGISTRY)/metrics-server-amd64:$(GIT_COMMIT) ./test/e2e.sh
# Static analysis
# ---------------
.PHONY: lint
lint:
ifndef HAS_GOLANGCI
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin ${GOLANGCI_VERSION}
endif
GO111MODULE=on golangci-lint run
.PHONY: fmt
fmt:
find pkg cmd -type f -name "*.go" | xargs gofmt -s -w
# Clean
# -----
.PHONY: clean
clean:
rm -rf _output