forked from QubitProducts/exporter_exporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
159 lines (134 loc) · 4.43 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
GITHUB_ORG = QubitProducts
GITHUB_REPO = exporter_exporter
VERSION = 0.3.1
DOCKER_REGISTRY = qubitproducts
DOCKER_NAME = exporter_exporter
DOCKER_IMAGE = $(DOCKER_REGISTRY)/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE_LATEST = $(DOCKER_REGISTRY)/$(DOCKER_NAME):latest
SHELL := /usr/bin/env bash
GO := go
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
FILES = $(shell find . -name '*.go' | grep -v vendor)
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
PACKAGE_TARGET = deb
PACKAGE_NAME = expexp
PACKAGE_VERSION = $(VERSION)
PACKAGE_REVISION = 3
PACKAGE_ARCH = amd64
PACKAGE_MAINTAINER = [email protected]
PACKAGE_FILE = $(PACKAGE_NAME)_$(PACKAGE_VERSION)-$(PACKAGE_REVISION)_$(PACKAGE_ARCH).$(PACKAGE_TARGET)
BINNAME = exporter_exporter
PWD := $(shell pwd)
all: package
clean:
rm -f $(PACKAGE_FILE)
rm -rf dist
rm -rf build
.PHONY: test
test:
echo ">> running short tests"
$(GO) test -short $(pkgs)
.PHONY: test-static
test-static:
echo ">> running static tests"
$(GO) vet $(pkgs)
[[ "$(shell gofmt -l $(files))" == "" ]] || (echo "gofmt check failed"; exit 1)
.PHONY: format
format:
echo ">> formatting code"
$(GO) fmt $(pkgs)
.PHONY: vet
vet:
echo ">> vetting code"
$(GO) vet $(pkgs)
.PHONY: prepare-package clean-package package
prepare-package: clean-package build/$(BINNAME)-$(VERSION).linux-amd64/$(BINNAME)
mkdir -p dist/usr/local/bin
mkdir -p dist/etc/init
mkdir -p dist/etc/default
mkdir -p dist/etc/exporter_exporter.d/
install -m755 build/$(BINNAME)-$(VERSION).linux-amd64/$(BINNAME) dist/usr/local/bin/$(BINNAME)
install -m644 $(BINNAME).conf dist/etc/init/$(BINNAME).conf
install -m644 $(BINNAME).defaults dist/etc/default/$(BINNAME)
install -m644 expexp.yaml dist/etc/exporter_exporter.yaml
touch dist/etc/exporter_exporter.d/.dir
clean-package:
rm -rf dist
.PHONY: AUTHORS
AUTHORS:
# There's only so much credit I need.
git log --format='%aN <%aE>' | grep -v Tristan\ Colgate\ | sort -u > AUTHORS
$(PACKAGE_FILE): prepare-package
cd dist && \
fpm \
-t $(PACKAGE_TARGET) \
-m $(PACKAGE_MAINTAINER) \
-n $(PACKAGE_NAME) \
-a $(PACKAGE_ARCH) \
-v $(PACKAGE_VERSION) \
--iteration $(PACKAGE_REVISION) \
--config-files /etc/$(BINNAME).yaml \
--config-files /etc/init/$(BINNAME).conf \
--config-files /etc/default/$(BINNAME) \
-s dir \
-p ../$(PACKAGE_FILE) \
.
.PHONY: build-docker release-docker
build-docker:
docker build -t $(DOCKER_IMAGE) .
release-docker: build-docker
docker push $(DOCKER_IMAGE)
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE_LATEST)
docker push $(DOCKER_IMAGE_LATEST)
LDFLAGS = -X main.Version=$(VERSION) \
-X main.Branch=$(BRANCH) \
-X main.Revision=$(REVISION) \
-X main.BuildUser=$(BUILDUSER) \
-X main.BuildDate=$(BUILDDATE)
build/$(BINNAME)-$(VERSION).windows-amd64/$(BINNAME).exe: $(SRCS)
GOOS=$* GOARCH=amd64 $(GO) build \
-ldflags "$(LDFLAGS)" \
-o $@ \
.
build/$(BINNAME)-$(VERSION).windows-amd64.zip: build/expoter_exporter-$(VERSION).windows-amd64/$(BINNAME).exe
zip $@ $<
build/$(BINNAME)-$(VERSION).%-amd64/$(BINNAME): $(SRCS)
GOOS=$* GOARCH=amd64 $(GO) build \
-ldflags "$(LDFLAGS)" \
-o $@ \
.
build/$(BINNAME)-$(VERSION).%-amd64.tar.gz: build/$(BINNAME)-$(VERSION).%-amd64/$(BINNAME)
cd build && \
tar cfzv $(BINNAME)-$(VERSION).$*-amd64.tar.gz $(BINNAME)-$(VERSION).$*-amd64
package: $(PACKAGE_FILE)
package-release: $(PACKAGE_FILE)
go run github.com/aktau/github-release upload \
-u $(GITHUB_ORG) \
-r $(GITHUB_REPO) \
--tag v$(VERSION) \
--name $(PACKAGE_FILE) \
--file $(PACKAGE_FILE)
release-windows: build/exporter_exporter-$(VERSION).windows-amd64.zip
go run github.com/aktau/github-release upload \
-u $(GITHUB_ORG) \
-r $(GITHUB_REPO) \
--tag v$(VERSION) \
--name exporter_exporter-$(VERSION).windows-amd64.zip \
-f ./build/exporter_exporter-$(VERSION).windows-amd64.zip
release-%: build/exporter_exporter-$(VERSION).%-amd64.tar.gz
go run github.com/aktau/github-release upload \
-u $(GITHUB_ORG) \
-r $(GITHUB_REPO) \
--tag v$(VERSION) \
--name exporter_exporter-$(VERSION).$*-amd64.tar.gz \
-f ./build/exporter_exporter-$(VERSION).$*-amd64.tar.gz
release:
git tag v$(VERSION)
git push origin v$(VERSION)
go run github.com/aktau/github-release release \
-u $(GITHUB_ORG) \
-r $(GITHUB_REPO) \
--tag v$(VERSION) \
--name v$(VERSION)
make release-darwin release-linux release-windows package-release