-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
111 lines (87 loc) · 2.53 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
# Build config:
BINARY_DIR=bin
BINARY_NAME=master
BINARY_PATH=$(BINARY_DIR)/$(BINARY_NAME)
RELEASE_NAME=tinykv
# Test config:
COVERAGE_PROFILE=cover.out
# Docker config:
DOCKER_IMAGE=tinykv-master
DOCKER_IMAGE_DEV=$(DOCKER_IMAGE)-dev
DOCKER_IMAGE_WATCH=$(DOCKER_IMAGE)-watch
WATCH_MASTER_PORT=3000
WATCH_VOL1_PORT=3001
WATCH_VOL2_PORT=3002
WATCH_VOL3_PORT=3003
WATCH_MASTER_INDEX_PATH=tmp/indexdb
WATCH_VOL1_PATH=tmp/vol1
WATCH_VOL2_PATH=tmp/vol2
WATCH_VOL3_PATH=tmp/vol3
# Docker setup config:
HOST=localhost
REPLICAS=3
VOLUME=3
.PHONY: vendor
all: format lint coverage build
# Build:
setup:
@go mod download
build:
@go build -buildvcs=false -o $(BINARY_PATH) ./cmd/master
clean:
@go clean --cache
@rm -rf $(BINARY_DIR)
@rm $(COVERAGE_PROFILE)
vendor:
@GO111MODULE=on go mod vendor
watch:
$(eval PACKAGE_NAME=$(shell head -n 1 go.mod | cut -d ' ' -f2))
@docker build -t $(DOCKER_IMAGE_WATCH) --target watch .
@docker run -it --rm \
-w /go/src/$(PACKAGE_NAME) \
-v $(shell pwd):/go/src/$(PACKAGE_NAME) \
-p $(WATCH_MASTER_PORT):3000 \
-p $(WATCH_VOL1_PORT):3001 \
-p $(WATCH_VOL2_PORT):3002 \
-p $(WATCH_VOL3_PORT):3003 \
--name $(DOCKER_IMAGE_WATCH) \
$(DOCKER_IMAGE_WATCH)
# Test:
test:
@go test -v -race ./...
coverage:
@go test -v -race -cover -covermode=atomic -coverprofile=$(COVERAGE_PROFILE) ./...
@go tool cover -func $(COVERAGE_PROFILE)
# Benchmark:
bench:
@go test -bench=. -run=^a -benchtime=5x ./...
# Format:
format:
@go fmt ./...
# Lint:
lint:
@golangci-lint run
# Release:
release:
@go build -buildvcs=false -o $(BINARY_NAME) ./cmd/master
@tar -czvf $(RELEASE_NAME).tar.gz $(BINARY_NAME) volume README.md LICENSE
@rm $(BINARY_NAME)
# Docker dev:
docker-dev-setup:
@docker build -t $(DOCKER_IMAGE_DEV) --target dev .
@docker run --rm --name $(DOCKER_IMAGE_DEV) -d -v $(shell pwd):/app $(DOCKER_IMAGE_DEV)
docker-dev-stop:
@docker stop $(DOCKER_IMAGE_DEV)
docker-check:
@docker exec $(DOCKER_IMAGE_DEV) make
docker-test:
@docker exec $(DOCKER_IMAGE_DEV) make test
docker-bench:
@docker exec $(DOCKER_IMAGE_DEV) make bench
docker-up-volume:
@docker compose -p tinykv -f docker/docker-compose.yml up -d --scale volume=$(VOLUME) volume
docker-up-master:
@VOLUMES=$$(for i in `seq 1 $(VOLUME)`; do docker compose -p tinykv -f docker/docker-compose.yml port volume 80 --index $$i | cut -d: -f2-; done | sed 's/^/$(HOST):/;s/$$/\n/' | paste -sd "," - | sed 's/,,/,/g;s/,$$//') \
REPLICAS=$(REPLICAS) \
docker compose -p tinykv -f docker/docker-compose.yml up -d master
docker-up: docker-up-volume docker-up-master