-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
76 lines (62 loc) · 2.13 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
# Makefile for etcdpasswd
PACKAGES := fakeroot
DOC_DIR := debian/usr/share/doc/etcdpasswd
CONTROL := debian/DEBIAN/control
SUDO = sudo
ETCD_VER=3.5.17
# Test tools
BIN_DIR := $(shell pwd)/bin
STATICCHECK := $(BIN_DIR)/staticcheck
CUSTOM_CHECKER := $(BIN_DIR)/custom-checker
ETCD := $(BIN_DIR)/etcd
all: test
.PHONY: check-generate
check-generate:
go mod tidy
git diff --exit-code --name-only
.PHONY: test
test:
test -z "$$(gofmt -s -l . | tee /dev/stderr)"
$(STATICCHECK) ./...
test -z "$$($(CUSTOM_CHECKER) -restrictpkg.packages=html/template,log $$(go list ./...) 2>&1 | tee /dev/stderr)"
go test -race -count=1 -v ./...
go vet ./...
$(CONTROL): control
sed 's/@VERSION@/$(patsubst v%,%,$(VERSION))/' $< > $@
.PHONY: deb
deb: $(CONTROL)
mkdir -p debian/usr/bin
GOBIN=$(CURDIR)/debian/usr/bin CGO_ENABLED=0 go install -ldflags="-s -w" ./pkg/etcdpasswd
mkdir -p debian/usr/sbin
GOBIN=$(CURDIR)/debian/usr/sbin CGO_ENABLED=0 go install -ldflags="-s -w" ./pkg/ep-agent
mkdir -p $(DOC_DIR)
cp config.yml.example README.md LICENSE $(DOC_DIR)
cp pkg/etcdpasswd/USAGE.md $(DOC_DIR)/etcdpasswd.md
mkdir -p debian/lib/systemd/system
cp pkg/ep-agent/ep-agent.service debian/lib/systemd/system
chmod -R g-w debian
fakeroot dpkg-deb --build debian .
.PHONY: test-tools
test-tools: $(STATICCHECK) $(CUSTOM_CHECKER) $(ETCD)
.PHONY: clean
clean:
rm -f *.deb
rm -rf $(CONTROL) debian/usr debian/lib
rm -rf $(BIN_DIR)
.PHONY: setup
setup:
$(SUDO) apt-get update
$(SUDO) apt-get -y --no-install-recommends install $(PACKAGES)
$(STATICCHECK):
mkdir -p $(BIN_DIR)
GOBIN=$(BIN_DIR) go install honnef.co/go/tools/cmd/staticcheck@latest
$(CUSTOM_CHECKER):
mkdir -p $(BIN_DIR)
GOBIN=$(BIN_DIR) go install github.com/cybozu-go/golang-custom-analyzer/cmd/custom-checker@latest
$(ETCD):
mkdir -p $(BIN_DIR)
curl -sL https://github.com/etcd-io/etcd/releases/download/v${ETCD_VER}/etcd-v${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-v${ETCD_VER}-linux-amd64.tar.gz
mkdir /tmp/etcd
tar xzvf /tmp/etcd-v${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd --strip-components=1
$(SUDO) mv /tmp/etcd/etcd $(ETCD)
rm -rf /tmp/etcd-v${ETCD_VER}-linux-amd64.tar.gz /tmp/etcd