-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
79 lines (67 loc) · 2.45 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
# Copyright 2022 Richard Kosegi
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
REGISTRY ?= ghcr.io/rkosegi
DOCKER ?= docker
IMAGE_NAME := $(REGISTRY)"/netflow-collector"
VERSION := $(shell cat VERSION)
VER_PARTS := $(subst ., ,$(VERSION))
VER_MAJOR := $(word 1,$(VER_PARTS))
VER_MINOR := $(word 2,$(VER_PARTS))
VER_PATCH := $(word 3,$(VER_PARTS))
VER_NEXT_PATCH := $(VER_MAJOR).$(VER_MINOR).$(shell echo $$(($(VER_PATCH)+1)))
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
BRANCH ?= $(strip $(shell git rev-parse --abbrev-ref HEAD))
PKG := github.com/prometheus/common
ARCH ?= $(shell go env GOARCH)
OS ?= $(shell uname -s | tr A-Z a-z)
LDFLAGS = -s -w
LDFLAGS += -X ${PKG}/version.Version=v${VERSION}
LDFLAGS += -X ${PKG}/version.Revision=${GIT_COMMIT}
LDFLAGS += -X ${PKG}/version.Branch=${BRANCH}
LDFLAGS += -X ${PKG}/version.BuildUser=$(shell id -u -n)@$(shell hostname)
LDFLAGS += -X ${PKG}/version.BuildDate=${BUILD_DATE}
.DEFAULT_GOAL := build-local
bump-patch-version:
@echo Current: $(VERSION)
@echo Next: $(VER_NEXT_PATCH)
@echo "$(VER_NEXT_PATCH)" > VERSION
git add -- VERSION
git commit -sm "Bump version to $(VER_NEXT_PATCH)"
git-tag:
git tag -am "Release $(VERSION)" $(VERSION)
git-push-tag:
git push --tags
new-release: bump-patch-version git-tag
update-go-deps:
@for m in $$(go list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
go get -d $$m; \
done
go mod tidy
build-docker:
docker build -t "$(IMAGE_NAME):v$(VERSION)" \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
.
push-docker:
docker push $(IMAGE_NAME):$(VERSION)
build-local:
go fmt ./...
go mod tidy
GOOS=$(OS) GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o netflow-collector cmd/main.go
lint:
pre-commit run --all-files
test:
go test -v ./...