-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
125 lines (98 loc) · 3.44 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
COMMIT ?= $(shell git rev-parse HEAD)
SOURCES := $(shell find . -name '*.go')
BINARY := anchore-adapter
IMAGE_TAG ?= dev
IMAGE_REPOSITORY ?= anchore/harbor-scanner-adapter
IMAGE ?= $(IMAGE_REPOSITORY):$(IMAGE_TAG)
TEMPDIR = ./.tmp
DISTDIR = ./dist
SNAPSHOTDIR = ./snapshot
# Linting
LINTCMD = $(TEMPDIR)/golangci-lint run --tests=false --timeout 5m --config .golangci.yaml
GOIMPORTS_CMD = $(TEMPDIR)/gosimports -local github.com/anchore
# ci dependency versions
GOLANG_CI_VERSION = v1.54.2
GOSIMPORTS_VERSION = v0.3.8
GORELEASER_VERSION = v1.16.1
ifndef TEMPDIR
$(error TEMPDIR is not set)
endif
ifndef SNAPSHOTDIR
$(error SNAPSHOTDIR is not set)
endif
ifndef DISTDIR
$(error DISTDIR is not set)
endif
all: test build
$(TEMPDIR):
mkdir -p $(TEMPDIR)
.PHONY: bootstrap-go
bootstrap-go:
$(call title,Boostrapping dependencies)
go mod download
.PHONY: bootstrap-tools
bootstrap-tools: $(TEMPDIR) $(RESULTSDIR)
$(call title,Boostrapping tools)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TEMPDIR)/ $(GOLANG_CI_VERSION)
GOBIN="$(realpath $(TEMPDIR))" go install github.com/rinchsan/gosimports/cmd/gosimports@$(GOSIMPORTS_VERSION)
GOBIN="$(realpath $(TEMPDIR))" go install github.com/goreleaser/goreleaser@$(GORELEASER_VERSION)
.PHONY: bootstrap
bootstrap: bootstrap-go bootstrap-tools ## Download and install all go dependencies (+ prep tooling in the ./tmp dir)
.PHONY: static-analysis
static-analysis: lint
# Placeholder for future static analysis checks (this make target is used by CI)
.PHONY: lint
lint: ## Run gofmt + golangci lint checks
$(call title,Running linters)
# ensure there are no go fmt differences
@printf "files with gofmt issues: [$(shell gofmt -l -s .)]\n"
@test -z "$(shell gofmt -l -s .)"
# run all golangci-lint rules
$(LINTCMD)
@[ -z "$(shell $(GOIMPORTS_CMD) -d .)" ] || (echo "goimports needs to be fixed" && false)
# go tooling does not play well with certain filename characters, ensure the common cases don't result in future "go get" failures
$(eval MALFORMED_FILENAMES := $(shell find . | grep -e ':'))
@bash -c "[[ '$(MALFORMED_FILENAMES)' == '' ]] || (printf '\nfound unsupported filename characters:\n$(MALFORMED_FILENAMES)\n\n' && false)"
.PHONY: lint-fix
lint-fix: ## Auto-format all source code + run golangci lint fixers
$(call title,Running lint fixers)
gofmt -w -s .
$(GOIMPORTS_CMD) -w .
$(LINTCMD) --fix
go mod tidy
.PHONY: build
build:
$(TEMPDIR)/goreleaser build --clean --snapshot
.PHONY: debug
debug: debug-build debug-run
.PHONY: debug-build
debug-build:
docker build -f Dockerfile-dev -t anchore/harbor-scanner-adapter:debug .
.PHONY: debug-stop
debug-stop:
kubectl delete -l app=harbor-scanner-anchore
.PHONY: debug-run
debug-run:
kubectl apply -f ./k8s/harbor-adapter-anchore-debug.yaml
kubectl port-forward $(shell kubectl get pods -o name -l app=harbor-scanner-anchore) 2345:2345 8080:8080
.PHONY: debug-logs
debug-logs:
kubectl logs -f $(shell kubectl get pods -o name -l app=harbor-scanner-anchore)
.PHONY: test
test:
CGO_ENABLED=0 go test ./...
.PHONY: clean
clean: clean-binary clean-image
.PHONY: clean-binary
clean-binary:
rm -f $(BINARY)
rm -rf dist/
.PHONY: clean-image
clean-image:
docker rmi -f $(IMAGE)
.PHONY: release
release:
IMAGE_REPOSITORY=$(IMAGE_REPOSITORY) $(TEMPDIR)/goreleaser release --clean
.PHONY: snapshot
snapshot:
IMAGE_REPOSITORY=$(IMAGE_REPOSITORY) $(TEMPDIR)/goreleaser release --clean --snapshot