-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
121 lines (97 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
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
NAME = graphite-ch-optimizer
VERSION = $(shell git describe --long --tags 2>/dev/null | sed 's/^v//;s/\([^-]*-g\)/c\1/;s/-/./g')
VENDOR = "System Administration <it@innogames.com>"
URL = https://github.com/innogames/$(NAME)
define DESC =
'Service to optimize stale GraphiteMergeTree tables
This software looking for tables with GraphiteMergeTree engine and evaluate if some of partitions should be optimized. It could work both as one-shot script and background daemon.'
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
MODULE = github.com/innogames/$(NAME)
GO ?= go
export GOFLAGS += -mod=vendor
export GO111MODULE := on
.PHONY: all clean docker test version
all: build
version:
@echo $(VERSION)
clean:
rm -rf artifact
rm -rf build
rm -rf $(NAME)
rebuild: clean all
# Run tests
test:
$(GO) vet $(MODULE)
$(GO) test $(MODULE)
build: | $(NAME)
mkdir build
docker:
docker build -t innogames/$(NAME):builder -f docker/builder/Dockerfile .
docker build -t innogames/$(NAME):latest -f docker/$(NAME)/Dockerfile .
$(NAME): $(NAME).go
$(GO) build -ldflags "-X 'main.version=$(VERSION)'" -o $@ .
#########################################################
# 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) build/config.toml.example
cd build
mkdir -p pkg/etc/$(NAME)
mkdir -p pkg/usr/bin
cp -l $(NAME) pkg/usr/bin/
cp -l config.toml.example pkg/etc/$(NAME)
build/$(NAME): $(NAME).go
GOOS=linux GOARCH=amd64 $(GO) build -ldflags "-X 'main.version=$(VERSION)'" -o $@ .
build/config.toml.example: build/$(NAME)
./build/$(NAME) --print-defaults > $@
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 MIT \
-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 #
#######