-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
109 lines (90 loc) · 3.32 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
ifdef VERSION
version := $(VERSION)
else
git_rev := $(shell git rev-parse --short HEAD)
git_tag := $(shell git tag --points-at=$(git_rev))
version := $(if $(git_tag),$(git_tag),dev-$(git_rev))
endif
pkgs := $(shell go list ./... | grep -v /vendor/)
files := $(shell find . -path ./vendor -prune -o -name '*.go' -print)
build_time := $(shell date -u)
ldflags := -X "github.com/sky-uk/feed/feed-ingress/cmd.version=$(version)" -X "github.com/sky-uk/feed/feed-ingress/cmd.buildTime=$(build_time)"
os := $(shell uname)
ifeq ("$(os)", "Linux")
GOOS = linux
else ifeq ("$(os)", "Darwin")
GOOS = darwin
endif
GOARCH ?= amd64
.PHONY: all format test build vet lint copy docker release checkformat check clean fakenginx check-vulnerabilities
all : format check build
check : vet lint test
travis : checkformat check docker check-vulnerabilities
format :
@echo "== format"
@go run golang.org/x/tools/cmd/goimports@v0.1.10 -w $(files)
@sync
dist/feed-ingress : $(files)
mkdir -p dist
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o dist/feed-ingress ./feed-ingress
dist/feed-dns : $(files)
mkdir -p dist
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o dist/feed-dns ./feed-dns
build : dist/feed-ingress dist/feed-dns
checkformat :
@echo "== check formatting"
@unformatted=`go run golang.org/x/tools/cmd/goimports@v0.1.10 -l $(files)`; if [ "$$unformatted" != "" ]; then \
echo "needs formatting: $$unformatted"; \
exit 1; \
fi
vet :
@echo "== vet"
@go vet $(pkgs)
lint :
@echo "== lint"
@for pkg in $(pkgs); do \
go run golang.org/x/lint/golint@83fdc39ff7b5 -set_exit_status $$pkg || exit 1; \
done;
fakenginx:
@echo "== build fake nginx for tests"
@go build -o nginx/fake/fake_graceful_nginx nginx/fake/fake_graceful_nginx.go
.PHONY: mocks
mocks: k8s/mocks/mocks.go
k8s/mocks/mocks.go:
go run github.com/golang/mock/mockgen@v1.6.0 -package mocks -destination $@ \
k8s.io/client-go/kubernetes/typed/networking/v1 IngressInterface,IngressesGetter
test : build fakenginx mocks
@echo "== run tests"
@go test -race $(pkgs)
# Docker build
git_rev := $(shell git rev-parse --short HEAD)
git_tag := $(shell git tag --points-at=$(git_rev))
REGISTRY ?= skycirrus
image_prefix := $(REGISTRY)/feed
docker : test
@echo "== build docker images"
cp dist/feed-dns docker/dns
cp dist/feed-ingress docker/ingress
cp nginx/nginx.tmpl docker/ingress
docker build -t $(image_prefix)-ingress:latest docker/ingress/
docker build -t $(image_prefix)-dns:latest docker/dns/
rm -f docker/dns/feed-dns
rm -f docker/ingress/feed-ingress
rm -f docker/ingress/nginx.tmpl
release : docker
@echo "== release docker images"
ifeq ($(strip $(git_tag)),)
@echo "no tag on $(git_rev), skipping release"
else
@echo "releasing $(image)-(dns|ingress):$(git_tag)"
@docker login -u $(DOCKER_USERNAME) -p $(DOCKER_PASSWORD)
docker tag $(image_prefix)-ingress:latest $(image_prefix)-ingress:$(git_tag)
docker tag $(image_prefix)-dns:latest $(image_prefix)-dns:$(git_tag)
docker push $(image_prefix)-ingress:$(git_tag)
docker push $(image_prefix)-ingress:latest
docker push $(image_prefix)-dns:$(git_tag)
docker push $(image_prefix)-dns:latest
endif
check-vulnerabilities:
@echo "== Checking for vulnerabilities in the docker image"
trivy image --exit-code=1 --severity="HIGH,CRITICAL" --ignorefile=trivy-ignore-file.txt $(image_prefix)-ingress:latest