-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathMakefile
147 lines (121 loc) · 4.01 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
145
146
147
# Makefile for building Chaos Exporter
# Reference Guide - https://www.gnu.org/software/make/manual/make.html
IS_DOCKER_INSTALLED = $(shell which docker >> /dev/null 2>&1; echo $$?)
# list only our namespaced directories
PACKAGES = $(shell go list ./... | grep -v '/vendor/')
# docker info
DOCKER_REPO ?= litmuschaos
DOCKER_IMAGE ?= chaos-exporter
DOCKER_TAG ?= ci
.PHONY: all
all: format lint deps build test security-checks push
.PHONY: help
help:
@echo ""
@echo "Usage:-"
@echo "\tmake all -- [default] builds the chaos exporter container"
@echo ""
.PHONY: format
format:
@echo "------------------"
@echo "--> Running go fmt"
@echo "------------------"
@go fmt $(PACKAGES)
.PHONY: lint
lint:
@echo "------------------"
@echo "--> Running golint"
@echo "------------------"
@golint $(PACKAGES)
@echo "------------------"
@echo "--> Running go vet"
@echo "------------------"
@go vet $(PACKAGES)
.PHONY: deps
deps: _build_check_docker godeps bdddeps unused-package-check
_build_check_docker:
@if [ $(IS_DOCKER_INSTALLED) -eq 1 ]; \
then echo "" \
&& echo "ERROR:\tdocker is not installed. Please install it before build." \
&& echo "" \
&& exit 1; \
fi;
godeps:
@echo ""
@echo "INFO:\tverifying dependencies for chaos exporter build ..."
@go get -u -v golang.org/x/lint/golint
@go get -u -v golang.org/x/tools/cmd/goimports
.PHONY: bdddeps
bdddeps:
@echo "------------------"
@echo "bdd test dependencies"
@echo "INFO:\tverifying dependencies for bdddeps ..."
@echo "------------------"
@go get -u github.com/onsi/ginkgo
@go get -u github.com/onsi/gomega
kubectl create -f https://raw.githubusercontent.com/litmuschaos/chaos-operator/master/deploy/chaos_crds.yaml
kubectl create ns litmus
.PHONY: docker.buildx
docker.buildx:
@echo "------------------------------"
@echo "--> Setting up Builder "
@echo "------------------------------"
@if ! docker buildx ls | grep -q multibuilder; then\
docker buildx create --name multibuilder;\
docker buildx inspect multibuilder --bootstrap;\
docker buildx use multibuilder;\
fi
.PHONY: build
build: go-build docker.buildx docker-build
go-build:
@echo "------------------"
@echo "--> Build Chaos Exporter"
@echo "------------------"
@bash build/go-multiarch-build.sh ./cmd/exporter
docker-build:
@echo "------------------"
@echo "--> Build chaos-exporter image"
@echo "------------------"
# Dockerfile available in the repo root
@docker buildx build --file Dockerfile --progress plane --platform linux/arm64,linux/amd64 --no-cache --tag $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) .
.PHONY: test
test:
@echo "------------------"
@echo "--> Run Go Test"
@echo "------------------"
@go test ./... -v -count=1
.PHONY: security-checks
security-checks: trivy-security-check
trivy-security-check:
@echo "------------------"
@echo "--> Trivy Security Check"
@echo "------------------"
./trivy --exit-code 0 --severity HIGH --no-progress $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG)
./trivy --exit-code 1 --severity CRITICAL --no-progress $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG)
.PHONY: push
push: docker.buildx docker-push
docker-push:
@echo "------------------"
@echo "--> Push chaos-exporter image"
@echo "------------------"
REPONAME="$(DOCKER_REPO)" IMGNAME="$(DOCKER_IMAGE)" IMGTAG="$(DOCKER_TAG)" ./buildscripts/push
unused-package-check:
@echo "------------------"
@echo "--> Check unused packages for the chaos-operator"
@echo "------------------"
@tidy=$$(go mod tidy); \
if [ -n "$${tidy}" ]; then \
echo "go mod tidy checking failed!"; echo "$${tidy}"; echo; \
fi
.PHONY: build-amd64
build-amd64:
@echo "-------------------------"
@echo "--> Build chaos-exporter image"
@echo "-------------------------"
@sudo docker build --file Dockerfile --tag $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) . --build-arg TARGETARCH=amd64
.PHONY: push-amd64
push-amd64:
@echo "------------------------------"
@echo "--> Pushing image"
@echo "------------------------------"
@sudo docker push $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG)