-
Notifications
You must be signed in to change notification settings - Fork 109
/
Makefile
66 lines (53 loc) · 1.59 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
NAME := kube-cleanup-operator
AUTHOR=lwolf
VERSION ?= 0.6.0
REGISTRY ?= quay.io
GIT_SHA=$(shell git rev-list --count HEAD)-$(shell git rev-parse --short=7 HEAD)
COMMIT_TIME=$(shell git show --format=%ct --no-patch)
LFLAGS ?= -X main.gitsha=${GIT_SHA} -X main.committed=${COMMIT_TIME}
ROOT_DIR=${PWD}
GOVERSION ?= 1.14.0
HARDWARE=$(shell uname -m)
.PHONY: build docker static release install_deps test
default: build
golang:
@echo "--> Go Version"
@go version
install_deps:
go mod tidy
go mod vendor
build: golang
@echo "--> Compiling the project"
@mkdir -p bin
go build -mod=vendor -ldflags "${LFLAGS}" -o bin/$(NAME) ./cmd
test:
go test -race ./pkg/... -coverprofile=coverage.txt -covermode=atomic
static: golang
@echo "--> Compiling the static binary"
@mkdir -p bin
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -mod=vendor -a -tags netgo -ldflags "-w ${LFLAGS}" -o bin/${NAME} ./cmd
docker-build:
@echo "--> Compiling the project"
docker run --rm \
-v ${ROOT_DIR}:/go/src/github.com/${AUTHOR}/${NAME} \
-w /go/src/github.com/${AUTHOR}/${NAME} \
-e GOOS=linux golang:${GOVERSION} \
make static
docker-release:
@echo "--> Building a release image"
@$(MAKE) static
@$(MAKE) docker
@docker push ${REGISTRY}/${AUTHOR}/${NAME}:${VERSION}
docker:
@echo "--> Building the docker image"
docker build -t ${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
format:
@echo "--> Running go fmt"
@gofmt -s -w ./