-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
135 lines (104 loc) · 3.41 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
NAME = graphite-ch-optimizer
MODULE = github.com/go-graphite/$(NAME)
VERSION = $(shell git describe --always --tags 2>/dev/null | sed 's:^v::; s/\([^-]*-g\)/c\1/; s|-|.|g')
define DESCRIPTION =
'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
PKG_FILES = $(wildcard out/*$(VERSION)*.deb out/*$(VERSION)*.rpm )
SUM_FILES = out/sha256sum out/md5sum
GO ?= go
GO_VERSION = -ldflags "-X 'main.version=$(VERSION)'"
ifeq ("$(CGO_ENABLED)", "0")
GOFLAGS += -ldflags=-extldflags=-static
endif
export GO111MODULE := on
SRCS:=$(shell find . -name '*.go')
.PHONY: all clean docker test version _nfpm
all: $(NAME)
build: $(NAME)
$(NAME): $(SRCS)
$(GO) build $(GO_VERSION) -o $@ .
version:
@echo $(VERSION)
clean:
rm -rf artifact
rm -rf $(NAME)
rm -rf out
rebuild: clean all
# Run tests
test:
$(GO) vet $(MODULE)
$(GO) test $(MODULE)
static:
CGO_ENABLED=0 $(MAKE) $(NAME)
docker:
docker build --label 'org.opencontainers.image.source=https://$(MODULE)' -t ghcr.io/go-graphite/$(NAME):latest .
# we need it static
.PHONY: gox-build
gox-build:
@CGO_ENABLED=0 $(MAKE) out/$(NAME)-linux-amd64 out/$(NAME)-linux-arm64
out/$(NAME)-linux-%: $(SRCS) | out
GOOS=linux GOARCH=$* $(GO) build $(GO_VERSION) -o $@ $(MODULE)
out: out/done
out/done:
mkdir -p out/done
#########################################################
# 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/%: out/% | artifact
cp -l $< $@
@echo '::set-output name=$(TYPE)::$(ART)'
#######
# END #
#######
#############
# Packaging #
#############
# Prepare everything for packaging
out/config.toml.example: $(NAME) | out
./$(NAME) --print-defaults > $@
.ONESHELL:
nfpm:
@$(MAKE) _nfpm ARCH=amd64 PACKAGER=deb
@$(MAKE) _nfpm ARCH=arm64 PACKAGER=deb
@$(MAKE) _nfpm ARCH=amd64 PACKAGER=rpm
@$(MAKE) _nfpm ARCH=arm64 PACKAGER=rpm
_nfpm: nfpm.yaml out/config.toml.example | out/done gox-build
@NAME=$(NAME) DESCRIPTION=$(DESCRIPTION) ARCH=$(ARCH) VERSION_STRING=$(VERSION) nfpm package --packager $(PACKAGER) --target out/
packages: nfpm $(SUM_FILES)
# md5 and sha256 sum-files for packages
$(SUM_FILES): COMMAND = $(notdir $@)
$(SUM_FILES): PKG_FILES_NAME = $(notdir $(PKG_FILES))
$(SUM_FILES): nfpm
cd out && $(COMMAND) $(PKG_FILES_NAME) > $(COMMAND)
#######
# END #
#######
##############
# PUBLISHING #
##############
# Use `go install github.com/mlafeldt/pkgcloud/cmd/pkgcloud-push`
.ONESHELL:
packagecloud-push-rpm: $(wildcard out/$(NAME)-$(VERSION)*.rpm)
for repo in el/{7..9}; do
pkgcloud-push $(REPO)/$${repo} $^ || true
done
.ONESHELL:
packagecloud-push-deb: $(wildcard out/$(NAME)_$(VERSION)*.deb)
for repo in ubuntu/{bionic,focal,jammy,nomble} debian/{buster,bullseye,bookworm}; do
pkgcloud-push $(REPO)/$${repo} $^ || true
done
packagecloud-push: nfpm
@$(MAKE) packagecloud-push-rpm
@$(MAKE) packagecloud-push-deb
packagecloud-autobuilds:
$(MAKE) packagecloud-push REPO=go-graphite/autobuilds
packagecloud-stable:
$(MAKE) packagecloud-push REPO=go-graphite/stable