-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
112 lines (81 loc) · 3.33 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
.PHONY: all clean install fmt check version build run test
SHELL := /bin/sh
BASEDIR := $(shell echo $${PWD})
# build variables (provided to binaries by linker LDFLAGS below)
VERSION := 0.0.1
LDFLAGS=-ldflags "-X=main.Version=$(VERSION)"
# ignore vendor directory for go files
SRC := $(shell find . -type f -name '*.go' -not -path './vendor/*' -not -path './.git/*')
# for walking directory tree (like for proto rule)
DIRS = $(shell find . -type d -not -path '.' -not -path './vendor' -not -path './vendor/*' -not -path './.git' -not -path './.git/*')
# generated files that can be cleaned
GENERATED := $(shell find . -type f -name '*.pb.go' -not -path './vendor/*' -not -path './.git/*')
# ignore generated files when formatting/linting/vetting
CHECKSRC := $(shell find . -type f -name '*.go' -not -name '*.pb.go' -not -path './vendor/*' -not -path './.git/*')
OWNER := freignat91
NAME := blockchain
TAG := latest
IMAGE := $(OWNER)/$(NAME):$(TAG)
IMAGETEST := $(OWNER)/$(NAME):test
REPO := github.com/$(OWNER)/blockchain
CLIENT := bchain
SERVER := server
TESTS := tests
all: version check install
version:
@echo "version: $(VERSION)"
clean:
@rm -rf $(GENERATED)
install-client:
@go install $(LDFLAGS) $(REPO)/$(CLIENT)
install-server:
@go install $(LDFLAGS) $(REPO)/$(SERVER)
install: install-server install-client
proto:
@protoc server/gnode/gnode.proto --go_out=plugins=grpc:.
# format and simplify if possible (https://golang.org/cmd/gofmt/#hdr-The_simplify_command)
fmt:
@gofmt -s -l -w $(CHECKSRC)
check:
@test -z $(shell gofmt -l ${CHECKSRC} | tee /dev/stderr) || echo "[WARN] Fix formatting issues with 'make fmt'"
@for d in $$(go list ./... | grep -v /vendor/); do golint $${d} | sed '/pb\.go/d'; done
@go tool vet ${CHECKSRC}
build: install-client
@docker build -t $(IMAGE) .
buildtest: install-client
@docker build -t $(IMAGETEST) .
run: build
@CID=$(shell docker run --net=host -d --name $(NAME) $(IMAGE)) && echo $${CID}
test:
@go test ./tests -v
install-deps:
@glide install --strip-vcs --strip-vendor --update-vendored
update-deps:
@glide update --strip-vcs --strip-vendor --update-vendored
start:
@docker node inspect self > /dev/null 2>&1 || docker swarm inspect > /dev/null 2>&1 || (echo "> Initializing swarm" && docker swarm init --advertise-addr 127.0.0.1)
@docker network ls | grep aNetwork || (echo "> Creating overlay network 'aNetwork'" && docker network create -d overlay aNetwork)
@mkdir -p /tmp/blockchain/data
@chmod 700 /tmp/blockchain/data
@docker service create --network aNetwork --name antblockchain \
--publish 30103:30103 \
--detach=true \
--mount type=bind,source=/tmp/blockchain/data,target=/data \
--replicas=5 \
$(IMAGE)
starttest:
@docker node inspect self > /dev/null 2>&1 || docker swarm inspect > /dev/null 2>&1 || (echo "> Initializing swarm" && docker swarm init --advertise-addr 127.0.0.1)
@docker network ls | grep aNetwork || (echo "> Creating overlay network 'aNetwork'" && docker network create -d overlay aNetwork)
@mkdir -p /tmp/blockchain/data
@chmod 700 /tmp/blockchain/data
@docker service create --network aNetwork --name antblockchain \
--publish 30103:30103 \
--detach=true \
--mount type=bind,source=/tmp/blockchain/data,target=/data \
--replicas=5 \
$(IMAGETEST)
stop:
@docker service rm antblockchain || true
init:
@docker service rm antblockchain || true
@rm -f ./logs/*