forked from Azure/application-gateway-kubernetes-ingress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
127 lines (103 loc) · 3.43 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
ORG_PATH := github.com/Azure
PROJECT_NAME := application-gateway-kubernetes-ingress
REPO_PATH = ${ORG_PATH}/${PROJECT_NAME}
VERSION_VAR = ${REPO_PATH}/pkg/version.Version
BUILD_TAG ?= $(shell git describe --abbrev=0 --tags)
DATE_VAR = ${REPO_PATH}/pkg/version.BuildDate
BUILD_DATE ?= $(shell date +%Y-%m-%d-%H:%MT%z)
COMMIT_VAR = ${REPO_PATH}/pkg/version.GitCommit
GIT_HASH ?= $(shell git rev-parse --short HEAD)
GO_BINARY_NAME ?= appgw-ingress
GOOS ?= linux
GARCH ?= arm64
BUILD_BASE_IMAGE ?= golang:1.19.5
REPO ?= appgwreg.azurecr.io
IMAGE_NAME = public/azure-application-gateway/kubernetes-ingress-staging
IMAGE = ${REPO}/${IMAGE_NAME}
IMAGE_RESULT_FLAG = --output=type=oci,dest=$(shell pwd)/image/ingress-agic-$(VERSION).tar
ifeq ($(PUSH_IMAGE), true)
IMAGE_RESULT_FLAG = --push
endif
ifeq ($(RELEASE_IMAGE), true)
IMAGE_NAME = public/azure-application-gateway/kubernetes-ingress
endif
TAG_LATEST ?= false
ifeq ($(TAG_LATEST), true)
IMAGE_TAGS = \
--tag $(IMAGE):$(BUILD_TAG) \
--tag $(IMAGE):latest
else
IMAGE_TAGS = \
--tag $(IMAGE):$(BUILD_TAG)
endif
# Platforms to build the multi-arch image for.
IMAGE_PLATFORMS ?= linux/amd64,linux/arm64
GO_BUILD_VARS = \
${REPO_PATH}/pkg/version.Version=${BUILD_TAG} \
${REPO_PATH}/pkg/version.BuildDate=${BUILD_DATE} \
${REPO_PATH}/pkg/version.GitCommit=${GIT_HASH}
GO_LDFLAGS := -s -w $(patsubst %,-X %, $(GO_BUILD_VARS))
build-image-multi-arch:
@mkdir -p $(shell pwd)/image
@docker run --rm --privileged linuxkit/binfmt:v0.8
@docker buildx build $(IMAGE_RESULT_FLAG) \
--platform $(IMAGE_PLATFORMS) \
--build-arg "BUILD_BASE_IMAGE=$(BUILD_BASE_IMAGE)" \
--build-arg "BUILD_TAG=$(BUILD_TAG)" \
--build-arg "BUILD_DATE=$(BUILD_DATE)" \
--build-arg "GIT_HASH=$(GIT_HASH)" \
$(IMAGE_TAGS) \
$(shell pwd)
build:
go build -mod=readonly -v -ldflags="$(GO_LDFLAGS)" -v -o ./bin/${GO_BINARY_NAME} ./cmd/appgw-ingress
lint-all: lint lint-helm
lint:
@go install golang.org/x/lint/golint@latest
@golint $(go list ./... | grep -v /vendor/) | tee /tmp/lint.out
@if [ -s /tmp/lint.out ]; then \
echo "\e[101;97m golint FAILED \e[0m"; \
exit 1; \
fi
@echo "\e[42;97m golint SUCCEEDED \e[0m"
lint-helm:
helm lint ./helm/ingress-azure
vet-all: vet vet-unittest vet-e2e
vet:
@echo "Vetting controller source code"
@if go vet -v ./...; then \
echo "\e[42;97m govet SUCCEEDED \e[0m"; \
else \
echo "\e[101;97m govet FAILED \e[0m"; \
exit 1; \
fi
vet-unittest:
@echo "Vetting test source code"
@if go vet -v -tags=unittest ./...; then \
echo "\e[42;97m govet SUCCEEDED \e[0m"; \
else \
echo "\e[101;97m govet FAILED \e[0m"; \
exit 1; \
fi
vet-e2e:
@echo "Vetting e2e source code"
@cd ./scripts/e2e
@if go vet -v -tags=e2e ./...; then \
echo "\e[42;97m govet SUCCEEDED \e[0m"; \
else \
echo "\e[101;97m govet FAILED \e[0m"; \
exit 1; \
fi
@cd ../..
test-all: unittest
unittest:
@go install github.com/jstemmer/go-junit-report@latest
@go install github.com/axw/gocov/gocov@latest
@go install github.com/AlekSi/gocov-xml@latest
@go install github.com/matm/gocov-html/cmd/gocov-html@latest
@go mod tidy
@go test -timeout 80s -v -coverprofile=coverage.txt -covermode count -tags unittest ./... > testoutput.txt || { echo "go test returned non-zero"; cat testoutput.txt; exit 1; }
@cat testoutput.txt | go-junit-report > report.xml
@gocov convert coverage.txt > coverage.json
@gocov-xml < coverage.json > coverage.xml
@mkdir coverage
@gocov-html < coverage.json > coverage/index.html