-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
119 lines (97 loc) · 2.96 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
NAME=policy-admission
AUTHOR=ukhomeofficedigital
AUTHOR_EMAIL=gambol99@gmail.com
REGISTRY=quay.io
ROOT_DIR=${PWD}
HARDWARE=$(shell uname -m)
GIT_SHA=$(shell git --no-pager describe --always --dirty)
GOVERSION=1.13
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%I:%M:%S%p')
VERSION ?= $(shell awk '/Version.*=/ { print $$3 }' cmd/policy-admission/main.go | sed 's/"//g')
PACKAGES=$(shell go list ./...)
LFLAGS ?= -X main.GitSHA=${GIT_SHA}
VETARGS ?= -asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -unsafeptr
.PHONY: test authors changelog build docker static release lint cover vet glide-install version
default: build
golang:
@echo "--> Go Version"
@go version
version:
@sed -i "s/const gitSHA =.*/const gitSHA = \"${GIT_SHA}\"/" doc.go
build:
@echo "--> Compiling the project"
mkdir -p bin
go build -ldflags "${LFLAGS}" -o bin/${NAME} cmd/policy-admission/*.go
static: golang modules
@echo "--> Compiling the static binary"
mkdir -p bin
CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags "-w ${LFLAGS}" -o bin/${NAME} cmd/policy-admission/*.go
docker: static
@echo "--> Building the docker image"
docker build -t ${REGISTRY}/${AUTHOR}/${NAME}:${VERSION} .
docker-build:
@echo "--> Compiling the project"
docker run -ti --rm \
-v ${ROOT_DIR}:/go/src/github.com/UKHomeOffice/${NAME} \
-w /go/src/github.com/UKHomeOffice/${NAME} \
-e GOOS=linux golang:${GOVERSION} \
make test
docker-release:
@echo "--> Building a release image"
@make static
@make docker
@docker push ${REGISTRY}/${AUTHOR}/${NAME}:${VERSION}
release: static
mkdir -p release
gzip -c bin/${NAME} > release/${NAME}_${VERSION}_linux_${HARDWARE}.gz
rm -f release/${NAME}
clean:
rm -rf ./bin 2>/dev/null
rm -rf ./release 2>/dev/null
authors:
@echo "--> Updating the AUTHORS"
git log --format='%aN <%aE>' | sort -u > AUTHORS
modules:
@echo "--> Downloading modules"
@go mod download
vet:
@echo "--> Running go vet $(VETARGS) ."
@go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
go get golang.org/x/tools/cmd/vet; \
fi
@go vet $(VETARGS) $(PACKAGES)
lint:
@echo "--> Running golint"
@which golint 2>/dev/null ; if [ $$? -eq 1 ]; then \
go get -u github.com/golang/lint/golint; \
fi
@golint .
gofmt:
@echo "--> Running gofmt check"
@gofmt -s -l ./... | grep -q \.go ; if [ $$? -eq 0 ]; then \
echo "You need to run the make format, we have file unformatted"; \
gofmt -s -l *.go; \
exit 1; \
fi
bench:
@echo "--> Running go bench"
@go test -v -bench=.
coverage:
@echo "--> Running go coverage"
@go test -coverprofile cover.out
@go tool cover -html=cover.out -o cover.html
cover:
@echo "--> Running go cover"
@go test -cover $(PACKAGES)
test-nomodules:
@echo "--> Running the tests"
@go test -v ${PACKAGES}
@$(MAKE) vet
@$(MAKE) cover
test: modules
@echo "--> Running the tests"
@go test -v ${PACKAGES}
@$(MAKE) vet
@$(MAKE) cover
changelog: release
git log $(shell git tag | tail -n1)..HEAD --no-merges --format=%B > changelog