-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
76 lines (60 loc) · 2.41 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
MODULE = $(shell go list -m)
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || echo "1.0.0")
PACKAGES := $(shell go list ./... | grep -v /vendor/)
LDFLAGS := -ldflags "-X main.Version=${VERSION}"
DOCKER_IMAGE = "becram/k8s-api-client"
PID_FILE := './.pid'
FSWATCH_FILE := './fswatch.cfg'
.PHONY: default
default: help
# generate help info from comments: thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## help information about make commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: test
test: ## run unit tests
@echo "mode: count" > coverage-all.out
@$(foreach pkg,$(PACKAGES), \
go test -p=1 -cover -covermode=count -coverprofile=coverage.out ${pkg}; \
tail -n +2 coverage.out >> coverage-all.out; )
.PHONY: test-cover
test-cover: test ## run unit tests and show test coverage information
go tool cover -html=coverage-all.out
.PHONY: run
run: ## run the API server
go run main.go
.PHONY: build
build: ## run the API server
go build -o k8s-api-client .
.PHONY: run-restart
run-restart: ## restart the API server
@pkill -P `cat $(PID_FILE)` || true
@printf '%*s\n' "80" '' | tr ' ' -
@echo "Source file changed. Restarting server..."
@go run ${LDFLAGS} main.go & echo $$! > $(PID_FILE)
@printf '%*s\n' "80" '' | tr ' ' -
run-live: ## run the API server with live reload support (requires fswatch)
@go run ${LDFLAGS} main.go & echo $$! > $(PID_FILE)
@fswatch -x -o --event Created --event Updated --event Renamed -r . | xargs -n1 -I {} make run-restart
.PHONY: build-docker
build-docker: ## build the API server as a docker image
docker build -f ./Dockerfile -t ${DOCKER_IMAGE}:${VERSION} .
.PHONY: push-docker
push-docker: ## build the API server as a docker image
docker push ${DOCKER_IMAGE}:${VERSION}
.PHONY: dc
dc: ## build the API server as a docker image
docker rm -f k8s-api-client
docker run -d --name k8s-api-client -v "/home/bikram/.kube/config:/.kube/config" -p 8080:8080 becram/k8s-api-client:${TAG}
.PHONY: clean
clean: ## remove temporary files
rm -rf k8s-api-client coverage.out coverage-all.out
.PHONY: version
version: ## display the version of the API server
@echo $(VERSION)
.PHONY: lint
lint: ## run golint on all Go package
@golint $(PACKAGES)
.PHONY: fmt
fmt: ## run "go fmt" on all Go packages
@go fmt $(PACKAGES)