-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
106 lines (85 loc) · 2.66 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
GOHOSTOS ?= $(shell go env GOHOSTOS)
GOHOSTARCH ?= $(shell go env GOHOSTARCH)
TAG := `git describe --tags --always`
VERSION :=
AZURE_SUBSCRIPTION_ID ?= $(shell az account show --query id -o tsv)
AZURE_RESOURCE_GROUP ?=
AZURE_CLUSTER_NAME ?=
# Adds a '-dirty' suffix to version string if there are uncommitted changes
changes := $(shell git status --porcelain)
ifeq ($(changes),)
VERSION := $(TAG)
else
VERSION := $(TAG)-dirty
endif
LINTER_VERSION ?= v1.53.2
include ie.mk
LDFLAGS := "-X github.com/Azure/kubectl-aks/cmd.version=$(VERSION) -extldflags '-static'"
.DEFAULT_GOAL := kubectl-aks
# Build
KUBECTL_AKS_TARGETS = \
kubectl-aks-linux-amd64 \
kubectl-aks-linux-arm64 \
kubectl-aks-darwin-amd64 \
kubectl-aks-darwin-arm64 \
kubectl-aks-windows-amd64
.PHONY: list-kubectl-aks-targets
list-kubectl-aks-targets:
@echo $(KUBECTL_AKS_TARGETS)
.PHONY: kubectl-aks-all
kubectl-aks-all: $(KUBECTL_AKS_TARGETS)
.PHONY: kubectl-aks
kubectl-aks: kubectl-aks-$(GOHOSTOS)-$(GOHOSTARCH)
mv kubectl-aks-$(GOHOSTOS)-$(GOHOSTARCH) kubectl-aks
# make does not allow implicit rules (with '%') to be phony so let's use
# the 'phony_explicit' dependency to make implicit rules inherit the phony
# attribute
.PHONY: phony_explicit
phony_explicit:
.PHONY: kubectl-aks-%
kubectl-aks-%: phony_explicit
export GO111MODULE=on CGO_ENABLED=0 && \
export GOOS=$(shell echo $* |cut -f1 -d-) GOARCH=$(shell echo $* |cut -f2 -d-) && \
go build -ldflags $(LDFLAGS) \
-o kubectl-aks-$${GOOS}-$${GOARCH} \
github.com/Azure/kubectl-aks
# Lint
.PHONY: lint
lint:
docker run --rm --env XDG_CACHE_HOME=/tmp/xdg_home_cache \
--env GOLANGCI_LINT_CACHE=/tmp/golangci_lint_cache \
--user $(shell id -u):$(shell id -g) -v $(shell pwd):/app -w /app \
golangci/golangci-lint:$(LINTER_VERSION) golangci-lint run
# Install
.PHONY: install
install: kubectl-aks
mkdir -p ~/.local/bin/
cp kubectl-aks ~/.local/bin/
# Uninstall
.PHONY: uninstall
uninstall:
rm -f ~/.local/bin/kubectl-aks
# Run unit tests
.PHONY: unit-test
unit-test:
go test -v ./...
# Run integration tests
.PHONY: integration-test
integration-test: kubectl-aks
KUBECTL_AKS="$(shell pwd)/kubectl-aks" \
AZURE_SUBSCRIPTION_ID=$(AZURE_SUBSCRIPTION_ID) \
AZURE_RESOURCE_GROUP=$(AZURE_RESOURCE_GROUP) \
AZURE_CLUSTER_NAME=$(AZURE_CLUSTER_NAME) \
go test -v ./test/integration/... -integration
# Run documentation tests
.PHONY: documentation-test
documentation-test: kubectl-aks install-ie
ie --help > /dev/null || (echo "ie is not installed, please install it from https://github.com/Azure/InnovationEngine" && exit 1)
ie execute README.md
# Clean
.PHONY: clean
clean:
rm -f kubectl-aks
.PHONY: cleanall
cleanall: clean
rm -f $(KUBECTL_AKS_TARGETS)