-
Notifications
You must be signed in to change notification settings - Fork 64
/
Makefile
164 lines (135 loc) · 5.52 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
e_Y=\033[1;33m
C_C=\033[0;36m
C_M=\033[0;35m
C_R=\033[0;41m
C_N=\033[0m
SHELL=/bin/bash
# Project variables
BINARY_NAME ?= apiclarity
DOCKER_REGISTRY ?= ghcr.io/openclarity
VERSION ?= $(shell git rev-parse HEAD)
DOCKER_IMAGE ?= $(DOCKER_REGISTRY)/$(BINARY_NAME)
DOCKER_TAG ?= ${VERSION}
# Dependency versions
GOLANGCI_VERSION = 1.42.1
LICENSEI_VERSION = 0.6.1
# HELP
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
.PHONY: ui
ui: ## Build UI
@(echo "Building UI ..." )
@(cd ui; npm i ; npm run build; )
@ls -l ui/build
.PHONY: ui_no_bin_links
ui_no_bin_links: ## Build UI
@(echo "Building UI (without bin links) ..." )
@(cd ui; npm i --no-bin-links; npm run buildfulllink; )
@ls -l ui/build
.PHONY: backend
backend: ## Build Backend
@(echo "Building Backend ..." )
@(cd backend && go build --tags=json1 -o bin/backend cmd/backend/main.go && ls -l bin/)
.PHONY: backend_linux
backend_linux: ## Build Backend Linux
@(echo "Building Backend linux..." )
@(cd backend && GOOS=linux go build --tags=json1 -o bin/backend_linux cmd/backend/main.go && ls -l bin/)
.PHONY: backend_test
backend_test: ## Build Backend test
@(echo "Building Backend test ..." )
@(cd backend && go build --tags=json1 -o bin/backend_test cmd/test/main.go && ls -l bin/)
.PHONY: api3-verify
api3-verify:
@(echo "Checking if api3 code was generated")
@(cd api3; ./generate.sh --verify)
.PHONY: api3
api3:
@(cd api3; ./generate.sh)
.PHONY: api
api: api3 ## Generating API code
@(echo "Generating API code ..." )
@(cd api; ./generate.sh)
.PHONY: docker
docker: docker-backend docker-plugins
.PHONY: docker-backend
docker-backend: ## Build Docker image
@(echo "Building backend docker image ..." )
@(cd backend)
docker build --build-arg VERSION=${VERSION} \
--build-arg BUILD_TIMESTAMP=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \
--build-arg COMMIT_HASH=$(shell git rev-parse HEAD) \
-t ${DOCKER_IMAGE}:${DOCKER_TAG} .
.PHONY: push-docker-backend
push-docker-backend: docker-backend ## Build and Push Docker image
@echo "Publishing backend Docker image ..."
docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
.PHONY: docker-plugins
docker-plugins: ## Build plugins Docker image
$(MAKE) docker -C plugins
.PHONY: push-docker-plugins
push-docker-plugins: ## Build and Push plugins Docker image
$(MAKE) push-docker -C plugins
.PHONY: test
test: ## Run Unit Tests
@(cd backend && go test ./pkg/...)
cd plugins/gateway/kong && go test ./...
cd plugins/gateway/tyk/v3.2.2 && go test ./...
cd plugins/taper && go test ./...
cd plugins/otel-collector/apiclarityexporter && go test ./...
.PHONY: clean
clean: clean-ui clean-backend ## Clean all build artifacts
.PHONY: clean-ui
clean-ui:
@(rm -rf ui/build ; echo "UI cleanup done" )
.PHONY: clean-backend
clean-backend:
@(rm -rf bin ; echo "Backend cleanup done" )
bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
bin/golangci-lint-${GOLANGCI_VERSION}:
@mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b ./bin/ v${GOLANGCI_VERSION}
@mv bin/golangci-lint $@
# TODO: remove temporarily exempted package from typecheck linter
.PHONY: lint
lint: bin/golangci-lint ## Run linter
cd backend && ../bin/golangci-lint run
cd plugins/gateway/kong && ../../../bin/golangci-lint run
cd plugins/gateway/tyk/v3.2.2 && ../../../../bin/golangci-lint run
cd plugins/taper && ../../bin/golangci-lint run
cd plugins/otel-collector/apiclarityexporter && ../../../bin/golangci-lint run \
--skip-files '../../../../../../go/pkg/mod/github.com/klauspost/compress'
.PHONY: fix
fix: bin/golangci-lint ## Fix lint violations
cd backend && ../bin/golangci-lint run --fix
cd plugins/gateway/kong && ../../../bin/golangci-lint run --fix
cd plugins/gateway/tyk/v3.2.2 && ../../../../bin/golangci-lint run --fix
cd plugins/taper && ../../bin/golangci-lint run --fix
cd plugins/otel-collector/apiclarityexporter && ../../../bin/golangci-lint run --fix
bin/licensei: bin/licensei-${LICENSEI_VERSION}
@ln -sf licensei-${LICENSEI_VERSION} bin/licensei
bin/licensei-${LICENSEI_VERSION}:
@mkdir -p bin
curl -sfL https://raw.githubusercontent.com/goph/licensei/master/install.sh | bash -s v${LICENSEI_VERSION}
@mv bin/licensei $@
.PHONY: license-check
license-check: bin/licensei ## Run license check
bin/licensei header
cd backend && ../bin/licensei check --config=../.licensei.toml
cd plugins/gateway/kong && ../../../bin/licensei check --config=../../../.licensei.toml
cd plugins/gateway/tyk/v3.2.2 && ../../../../bin/licensei check --config=../../../../.licensei.toml
cd plugins/taper && ../../bin/licensei check --config=../../.licensei.toml
cd plugins/otel-collector/apiclarityexporter && ../../../bin/licensei check --config=../../../.licensei.toml
.PHONY: license-cache
license-cache: bin/licensei ## Generate license cache
cd backend && ../bin/licensei cache --config=../.licensei.toml
cd plugins/gateway/kong && ../../../bin/licensei cache --config=../../../.licensei.toml
cd plugins/gateway/tyk/v3.2.2 && ../../../../bin/licensei cache --config=../../../../.licensei.toml
cd plugins/taper && ../../bin/licensei cache --config=../../.licensei.toml
cd plugins/otel-collector/apiclarityexporter && ../../../bin/licensei cache --config=../../../.licensei.toml
.PHONY: check
check: lint test ## Run tests and linters