-
Notifications
You must be signed in to change notification settings - Fork 33
/
Makefile
95 lines (71 loc) · 2.97 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
.DEFAULT_GOAL := build
PACKAGES = $(shell go list ./... | grep -v /vendor/)
TESTARGS ?= -race
CURRENTDIR = $(shell pwd)
SOURCEDIR = $(CURRENTDIR)
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')
APP_SOURCES := $(shell find $(SOURCEDIR) -name '*.go' -not -path '$(SOURCEDIR)/vendor/*')
PATH := $(CURRENTDIR)/bin:$(PATH)
COVERAGEDIR = $(CURRENTDIR)/coverage
VERSION = $(shell cat .goxc.json | python -c "import json,sys;obj=json.load(sys.stdin);print obj['PackageVersion'];")
TEMPDIR := $(shell mktemp -d)
LD_FLAGS = -ldflags '-w' -ldflags "-X main.VERSION=$(VERSION)"
TEST_TARGETS = $(PACKAGES)
all: build
deps:
@./install_consul.sh
@mkdir -p $(COVERAGEDIR)
@which gover > /dev/null || \
(go get github.com/modocache/gover)
@which goxc > /dev/null || \
(go get github.com/laher/goxc)
@which goimports > /dev/null || \
(go get golang.org/x/tools/cmd/goimports)
build-deps: deps format
@mkdir -p bin/
build: check build-deps test
CGO_ENABLED=0 go build $(LD_FLAGS) -o bin/marathon-consul
build-linux: build-deps
CGO_ENABLED=0 GOOS=linux go build -a -tags netgo $(LD_FLAGS) -o bin/marathon-consul
docker: build-linux
docker build -t allegro/marathon-consul .
test: deps $(SOURCES) $(TEST_TARGETS)
gover $(COVERAGEDIR) $(COVERAGEDIR)/gover.coverprofile
$(TEST_TARGETS):
go test -coverprofile=coverage/$(shell basename $@).coverprofile $(TESTARGS) $@
check-deps: deps
@which golangci-lint > /dev/null || \
(GO111MODULE=on go get -v github.com/golangci/golangci-lint/cmd/[email protected])
check: check-deps $(SOURCES) test
golangci-lint run --config=golangcilinter.yaml ./...
format:
goimports -w -l $(APP_SOURCES)
FPM-exists:
@fpm -v || \
(echo >&2 "FPM must be installed on the system. See https://github.com/jordansissel/fpm"; false)
deb: FPM-exists build-linux
mkdir -p dist/$(VERSION)/
cd dist/$(VERSION)/ && \
fpm -s dir \
-t deb \
-n marathon-consul \
-v $(VERSION) \
--url="https://github.com/allegro/marathon-consul" \
--vendor=Allegro \
--architecture=amd64 \
--maintainer="Allegro Group <[email protected]>" \
--description "Marathon-consul service (performs Marathon Tasks registration as Consul Services for service discovery) Marathon-consul takes information provided by the Marathon event bus and forwards it to Consul agents. It also re-syncs all the information from Marathon to Consul on startup and repeats it with given interval." \
--deb-priority optional \
--workdir $(TEMPDIR) \
--license "Apache License, version 2.0" \
../../bin/marathon-consul=/usr/bin/marathon-consul \
../../debian/marathon-consul.service=/etc/systemd/system/marathon-consul.service \
../../debian/marathon-consul.upstart=/etc/init/marathon-consul.conf \
../../debian/config.json=/etc/marathon-consul.d/config.json
release: deb deps
goxc
version: deps
goxc -wc -pv=$(v)
git add .goxc.json
git commit -m "Release $(v)"
.PHONY: all bump build release deb