This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Makefile
95 lines (74 loc) · 2.95 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
# Copyright (C) 2020 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
VERSION?=$(shell git describe --tags --first-parent --abbrev=7 --long --dirty --always)
TEST_KUBECONFIG?=$(HOME)/.kube/config
TEST_TIMEOUT=600s
TEST_PARALLELISM=3
# Verify Go in PATH
ifeq (, $(shell which go))
$(error You must install Go to build - https://golang.org/dl/ )
endif
INSTALL_DIR=/usr/local/bin
BIN_DIR=./bin
NATIVE_ARCH=$(shell uname | tr A-Z a-z)
GOARCH=amd64
export GOARCH
CI_OSES=linux darwin windows
CI_BUILD_TARGETS=$(foreach os,$(CI_OSES),\
$(if $(filter windows,$(os)),\
$(BIN_DIR)/$(os)/kubectl-buildkit.exe $(BIN_DIR)/$(os)/kubectl-build.exe,\
$(BIN_DIR)/$(os)/kubectl-buildkit $(BIN_DIR)/$(os)/kubectl-build) \
)
CI_ARCHIVES=$(foreach os,$(CI_OSES),$(BIN_DIR)/$(os).tgz)
GO_MOD_NAME=github.com/vmware-tanzu/buildkit-cli-for-kubectl
GO_DEPS=$(foreach dir,$(shell go list -deps -f '{{.Dir}}' ./cmd/kubectl-buildkit ./cmd/kubectl-build),$(wildcard $(dir)/*.go)) Makefile
REVISION=$(shell git describe --match 'v[0-9]*' --always --dirty --tags)
GO_FLAGS=-ldflags "-buildid= -s -w -X $(GO_MOD_NAME)/version.Version=${VERSION}" -mod=vendor
GO_COVER_FLAGS=-cover -coverpkg=./... -covermode=count
.PHONY: help
help:
@echo "To install the CLI plugin locall run 'make build && sudo make install'"
@echo "(Note: You must have Go installed on your host to compile)"
.PHONY: clean
clean:
-rm -rf $(BIN_DIR) cover*.out cover*.html
.PHONY: build
build: $(BIN_DIR)/$(NATIVE_ARCH)/kubectl-buildkit $(BIN_DIR)/$(NATIVE_ARCH)/kubectl-build
$(BIN_DIR)/%/kubectl-buildkit $(BIN_DIR)/%/kubectl-buildkit.exe: $(GO_DEPS)
GOOS=$* go build -trimpath $(GO_FLAGS) -o $@ ./cmd/kubectl-buildkit
$(BIN_DIR)/%/kubectl-build $(BIN_DIR)/%/kubectl-build.exe: $(GO_DEPS)
GOOS=$* go build -trimpath $(GO_FLAGS) -o $@ ./cmd/kubectl-build
install: $(BIN_DIR)/$(NATIVE_ARCH)/kubectl-buildkit $(BIN_DIR)/$(NATIVE_ARCH)/kubectl-build
cp $(BIN_DIR)/$(NATIVE_ARCH)/kubectl-buildkit $(BIN_DIR)/$(NATIVE_ARCH)/kubectl-build $(INSTALL_DIR)
print-%:
@echo '$*=$($*)'
.PHONY: build-ci
build-ci: $(CI_BUILD_TARGETS)
.PHONY: dist
dist: $(CI_BUILD_TARGETS) $(CI_ARCHIVES)
$(BIN_DIR)/%.tgz: $(BIN_DIR)/%/*
cd $(BIN_DIR)/$* && tar -czvf ../$*.tgz kubectl-*
.PHONY: test
test:
go test $(GO_FLAGS) $(GO_COVER_FLAGS) -coverprofile=./cover-unit.out ./...
.PHONY: integration
integration:
@echo "Running integration tests with $(TEST_KUBECONFIG)"
@kubectl config get-contexts
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test -timeout $(TEST_TIMEOUT) $(GO_FLAGS) \
-parallel $(TEST_PARALLELISM) \
$(EXTRA_GO_TEST_FLAGS) \
$(GO_COVER_FLAGS) -coverprofile=./cover-int.out \
./integration/...
go tool cover -html=./cover-int.out -o ./cover-int.html
.PHONY: coverage
coverage: cover.html
cover.html: cover-int.out cover-unit.out
cp cover-int.out cover.out
tail +2 cover-unit.out >> cover.out
go tool cover -html=./cover.out -o ./cover.html
go tool cover -func cover.out | grep total:
open ./cover.html
.PHONY: lint
lint:
golangci-lint run