-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
142 lines (122 loc) · 3.92 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Variables
BUILD_DIR := build
GITHASH := $(shell git rev-parse HEAD)
VERSION := $(shell git describe --abbrev=0 --tags --always)
DATE := $(shell TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ UTC')
LINT_PATHS := ./...
FORMAT_PATHS := .
# Compilation variables
CC := go build
DFLAGS := -race
CFLAGS := -X 'main.githash=$(GITHASH)' \
-X 'main.date=$(DATE)' \
-X 'main.version=$(VERSION)'
PLATFORMS=darwin linux windows
ARCHITECTURES=386 amd64
# Makefile variables
VPATH := $(BUILD_DIR)
.SECONDEXPANSION:
.PHONY: all
all: init format lint test release
.PHONY: init
init:
go get github.com/golangci/golangci-lint/cmd/[email protected]
go get -u github.com/onsi/ginkgo/ginkgo
go get -u golang.org/x/tools/cmd/cover
go get -u github.com/modocache/gover
go get golang.org/x/tools/cmd/goimports
.PHONY: cleanmake
clean:
rm -rf $(BUILD_DIR)
rm -rf dist
.PHONY: format
format:
gofmt -w -s $(FORMAT_PATHS)
goimports -w $(FORMAT_PATHS)
.PHONY: lint
lint:
@command -v golangci-lint >/dev/null 2>&1 || { echo >&2 "golangci-lint is required but not available please follow instructions from https://github.com/golangci/golangci-lint"; exit 1; }
golangci-lint run --config golangci.yml
.PHONY: test
test:
$(GOPATH)/bin/ginkgo -r --randomizeAllSpecs --randomizeSuites --failOnPending --cover --trace --progress --compilers=2
.PHONY: testrun
testrun:
$(GOPATH)/bin/ginkgo watch -r ./
.PHONY: cover
cover:
$(GOPATH)/bin/gover . coverage.txt
.PHONY: dev
dev: format lint build
.PHONY: build
build:
$(CC) $(DFLAGS) -ldflags "-s -w $(CFLAGS)" -o $(BUILD_DIR)/lookatch-agent
.PHONY: release
release:
$(CC) -ldflags "-s -w $(CFLAGS)" -o $(BUILD_DIR)/lookatch-agent
.PHONY: dist
dist:
@for GOOS in $(PLATFORMS) ; do \
for GOARCH in $(ARCHITECTURES) ; do \
GOOS=$${GOOS} GOARCH=$${GOARCH} $(CC) -ldflags "-s -w $(CFLAGS)" -o $(BUILD_DIR)/$${GOOS}/$${GOARCH}/lookatch-agent; \
done \
done
.PHONY: install
install: release
cp -v $(BUILD_DIR)/lookatch-agent $(GOPATH)/bin/lookatch-agent
.PHONY: deb
deb:
rm -f lookatch-agent*.deb
rm -f package/deb/input-*
for ARCH in $(ARCHITECTURES) ; do \
sed "s/%ARCH%/$${ARCH}/g" <package/deb/input >package/deb/input-$${ARCH}; \
fpm -m "<Pirionfr>" \
--description "replicate and synchronize your data" \
--url "https://github.com/Pirionfr/lookatch-agent" \
--license "Apache-2.0" \
--version $(VERSION) \
-n lookatch-agent \
-d logrotate \
-s dir \
-t deb \
-a $${ARCH} \
--deb-user lookatch \
--deb-group lookatch \
--deb-no-default-config-files \
--config-files /etc/lookatch/config.json \
--deb-systemd package/rpm/lookatch-agent.service \
--directories /var/log/lookatch-agent \
--before-install package/deb/before-install.sh \
--after-install package/deb/after-install.sh \
--before-upgrade package/deb/before-upgrade.sh \
--after-upgrade package/deb/after-upgrade.sh \
--before-remove package/deb/before-remove.sh \
--after-remove package/deb/after-remove.sh \
--inputs package/deb/input-$${ARCH} ; \
done
.PHONY: rpm
rpm:
rm -f lookatch-agent*.rpm
rm -f package/rpm/input-*
for ARCH in $(ARCHITECTURES) ; do \
sed "s/%ARCH%/$${ARCH}/g" <package/rpm/input >package/rpm/input-$${ARCH}; \
fpm -m "<Pirionfr>" \
--description "replicate and synchronize your data" \
--url "https://github.com/Pirionfr/lookatch-agent" \
--license "Apache-2.0" \
--version $(VERSION) \
-n lookatch-agent \
-s dir \
-t rpm \
-a $${ARCH} \
--rpm-user lookatch \
--rpm-group lookatch \
--config-files /etc/lookatch/config.json \
--before-install package/rpm/before-install.sh \
--after-install package/rpm/after-install.sh \
--before-upgrade package/rpm/before-upgrade.sh \
--after-upgrade package/rpm/after-upgrade.sh \
--before-remove package/rpm/before-remove.sh \
--after-remove package/rpm/after-remove.sh \
--inputs package/rpm/input-$${ARCH} ; \
done