-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
133 lines (106 loc) · 3.65 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
NAME = grafsy
# This is space separated words, e.g. '[email protected] leoleovich grafsy.git' or 'https github.com leoleovich grafsy.git'
REPO_LIST = $(shell git remote get-url origin | tr ':/' ' ' )
# And here we take the word before the last to get the organization name
ORG_NAME = $(word $(words $(REPO_LIST)), first_word $(REPO_LIST))
# version in format $(tag without leading v).c$(commits since release).g$(sha1)
VERSION = $(shell git describe --long --tags 2>/dev/null | sed 's/^v//;s/\([^-]*-g\)/c\1/;s/-/./g')
VENDOR = "GitHub Actions of $(ORG_NAME)/$(NAME) <[email protected]>"
URL = https://github.com/$(ORG_NAME)/$(NAME)
define DESC =
'A very light proxy for graphite metrics with additional features
This software receives carbon metrics localy, buffering them, aggregating, filtering bad metrics, and periodicaly sends them to one or few carbon servers'
endef
GO_FILES = $(shell find -name '*.go')
PKG_FILES = build/$(NAME)_$(VERSION)_amd64.deb build/$(NAME)-$(VERSION)-1.x86_64.rpm
SUM_FILES = build/sha256sum build/md5sum
GO_FLAGS =
GO_BUILD = go build $(GO_FLAGS) -ldflags "-X 'main.version=$(VERSION)'" -o $@ $<
export GO111MODULE=on
.PHONY: all clean docker test version
all: build
version:
@echo $(VERSION)
clean:
rm -rf artifact
rm -rf build
rebuild: clean all
# Run tests
test:
go vet ./...
go test -v ./...
build: build/$(NAME) build/$(NAME)-client
docker:
docker build -t $(ORG_NAME)/$(NAME):builder -f docker/builder/Dockerfile .
docker build --build-arg IMAGE=$(ORG_NAME)/$(NAME) -t $(ORG_NAME)/$(NAME):latest -f docker/$(NAME)/Dockerfile .
build/$(NAME): $(NAME)/main.go
$(GO_BUILD)
build/$(NAME)-client: $(NAME)-client/main.go
$(GO_BUILD)
build/$(NAME).exe: $(NAME)/main.go
GOOS=windows $(GO_BUILD)
build/$(NAME)-client.exe: $(NAME)-client/main.go
GOOS=windows $(GO_BUILD)
#########################################################
# Prepare artifact directory and set outputs for upload #
#########################################################
github_artifact: $(foreach art,$(PKG_FILES) $(SUM_FILES), artifact/$(notdir $(art)))
artifact:
mkdir $@
# Link artifact to directory with setting step output to filename
artifact/%: ART=$(notdir $@)
artifact/%: TYPE=$(lastword $(subst ., ,$(ART)))
artifact/%: build/% | artifact
cp -l $< $@
@echo '::set-output name=$(TYPE)::$(ART)'
#######
# END #
#######
#############
# Packaging #
#############
# Prepare everything for packaging
.ONESHELL:
build/pkg: build/$(NAME)-client_linux_x64 build/$(NAME)_linux_x64 $(NAME).toml
cd build
mkdir -p pkg/etc/$(NAME)/example/
mkdir -p pkg/usr/bin
cp -l $(NAME)_linux_x64 pkg/usr/bin/$(NAME)
cp -l $(NAME)-client_linux_x64 pkg/usr/bin/$(NAME)-client
cp -l ../$(NAME).toml pkg/etc/$(NAME)/example/
build/$(NAME)_linux_x64: $(NAME)/main.go
GOOS=linux GOARCH=amd64 $(GO_BUILD)
build/$(NAME)-client_linux_x64: $(NAME)-client/main.go
GOOS=linux GOARCH=amd64 $(GO_BUILD)
packages: $(PKG_FILES) $(SUM_FILES)
# md5 and sha256 sum-files for packages
$(SUM_FILES): COMMAND = $(notdir $@)
$(SUM_FILES): PKG_FILES_NAME = $(notdir $(PKG_FILES))
.ONESHELL:
$(SUM_FILES): $(PKG_FILES)
cd build
$(COMMAND) $(PKG_FILES_NAME) > $(COMMAND)
deb: $(word 1, $(PKG_FILES))
rpm: $(word 2, $(PKG_FILES))
# Set TYPE to package suffix w/o dot
$(PKG_FILES): TYPE = $(subst .,,$(suffix $@))
$(PKG_FILES): build/pkg
fpm --verbose \
-s dir \
-a x86_64 \
-t $(TYPE) \
--vendor $(VENDOR) \
-m $(VENDOR) \
--url $(URL) \
--description $(DESC) \
--license Apache \
-n $(NAME) \
-v $(VERSION) \
--after-install packaging/postinst \
--before-remove packaging/prerm \
-p build \
build/pkg/=/ \
packaging/$(NAME).service=/lib/systemd/system/$(NAME).service
#######
# END #
#######