-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (69 loc) · 2.12 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
# Go parameters
BINARY_NAME=checkmate
MAIN_PATH=./main.go
DOCKER_IMAGE=checkmate
VERSION=$(shell svu next)
CONFIG_PATH=$(wordlist 2,2,$(MAKECMDGOALS))
# Go commands
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOLINT=golangci-lint
# Build flags
LDFLAGS=-ldflags "-X main.Version=${VERSION}"
.PHONY: all build run clean test coverage lint deps docker-build docker-run docker-push git-release help
all: clean lint test build
build:
CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) $(MAIN_PATH)
run:
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) $(MAIN_PATH)
./$(BINARY_NAME) $(CONFIG_PATH)
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f coverage.out
test:
$(GOTEST) -v ./...
coverage:
$(GOTEST) -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out
lint:
$(GOLINT) run
deps:
$(GOMOD) download
$(GOMOD) tidy
docker-build-local:
KO_DOCKER_REPO=ko.local ko build .
# docker build -t $(DOCKER_IMAGE):$(VERSION) .
# docker tag $(DOCKER_IMAGE):$(VERSION) $(DOCKER_IMAGE):latest
docker-run:
# need to figure out sha for ko
docker run -p 9100:9100 --rm ko.local/$(DOCKER_IMAGE)-$(SHA):latest
# docker run -p 9100:9100 $(DOCKER_IMAGE):$(VERSION)
docker-push:
docker push $(DOCKER_IMAGE):$(VERSION)
docker push $(DOCKER_IMAGE):latest
git-release:
git tag $(VERSION)
git push origin $(VERSION)
goreleaser release --clean
dev: deps lint test build
help:
@echo "Available targets:"
@echo " all : Clean, lint, test, and build"
@echo " build : Build the application"
@echo " run : Run the application"
@echo " clean : Clean build files"
@echo " test : Run tests"
@echo " coverage : Run tests with coverage report"
@echo " lint : Run linter"
@echo " deps : Download dependencies"
@echo " dev : Setup development environment"
@echo " docker-build-local : Build Docker image"
@echo " docker-run : Run Docker container"
@echo " docker-push : Push Docker image"
@echo " git-release : Create a release using goreleaser"
@echo " help : Show this help message"