-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
89 lines (71 loc) · 2.62 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
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 ?= yara-rule-server
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.52.2
LICENSEI_VERSION = 0.5.0
# 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: build
build: ## Build Yara Rule Server
@(echo "Building Yara Rule Server ..." )
@(go mod tidy && go build -o bin/yara-rule-server main.go && ls -l bin/)
.PHONY: docker
docker: ## Build Yara Rule Server docker image
@(echo "Building Yara Rule Server docker image [${DOCKER_IMAGE}:${DOCKER_TAG}] ..." )
@(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: docker-push
docker-push: docker ## Build Yara Rule Server docker image and push it to remote
@(echo "Pushing Yara Rule Server docker image [${DOCKER_IMAGE}:${DOCKER_TAG}] ..." )
@(docker push ${DOCKER_IMAGE}:${DOCKER_TAG})
.PHONY: test
test: ## Run Unit Tests
@(go test ./pkg/...)
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 $@
.PHONY: lint-go
lint-go: bin/golangci-lint
./bin/golangci-lint run
.PHONY: lint
lint: lint-go ## Run linters
.PHONY: fix
fix: bin/golangci-lint ## Fix lint violations
./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
.PHONY: license-cache
license-cache: bin/licensei ## Generate license cache
./bin/licensei cache --config=.licensei.toml
.PHONY: check
check: lint test ## Run tests and linters
.PHONY: clean
clean: ## Clean all build artifacts
@(rm -rf bin/* ; echo "Build artifacts cleanup done" )