2019-10-11 00:20:42 +00:00
|
|
|
DOCKER_TAG ?= minitor-go-${USER}
|
2020-07-07 18:37:55 +00:00
|
|
|
VERSION ?= $(shell git describe --tags --dirty)
|
2023-04-18 23:09:30 +00:00
|
|
|
GOFILES = *.go go.mod go.sum
|
2020-07-07 03:05:12 +00:00
|
|
|
# Multi-arch targets are generated from this
|
|
|
|
TARGET_ALIAS = minitor-linux-amd64 minitor-linux-arm minitor-linux-arm64 minitor-darwin-amd64
|
|
|
|
TARGETS = $(addprefix dist/,$(TARGET_ALIAS))
|
2020-07-07 17:49:58 +00:00
|
|
|
#
|
2020-07-07 03:05:12 +00:00
|
|
|
# Default make target will run tests
|
|
|
|
.DEFAULT_GOAL = test
|
|
|
|
|
|
|
|
# Build all static Minitor binaries
|
2020-01-10 21:58:17 +00:00
|
|
|
.PHONY: all
|
2020-07-07 03:05:12 +00:00
|
|
|
all: $(TARGETS)
|
2019-10-03 19:56:03 +00:00
|
|
|
|
2020-07-07 03:05:12 +00:00
|
|
|
# Build all static Linux Minitor binaries. Used in Docker images
|
|
|
|
.PHONY: all-linux
|
|
|
|
all-linux: $(filter dist/minitor-linux-%,$(TARGETS))
|
2019-10-03 19:56:03 +00:00
|
|
|
|
2020-07-07 03:05:12 +00:00
|
|
|
# Build minitor for the current machine
|
|
|
|
minitor: $(GOFILES)
|
2020-01-10 21:58:17 +00:00
|
|
|
@echo Version: $(VERSION)
|
|
|
|
go build -ldflags '-X "main.version=${VERSION}"' -o minitor
|
2019-10-03 19:56:03 +00:00
|
|
|
|
2020-07-07 03:05:12 +00:00
|
|
|
.PHONY: build
|
|
|
|
build: minitor
|
|
|
|
|
|
|
|
# Run minitor for the current machine
|
2019-10-03 19:56:03 +00:00
|
|
|
.PHONY: run
|
2020-07-07 03:05:12 +00:00
|
|
|
run: minitor
|
2020-01-10 21:58:17 +00:00
|
|
|
./minitor -debug
|
2019-11-16 01:36:10 +00:00
|
|
|
|
|
|
|
.PHONY: run-metrics
|
2020-07-07 03:05:12 +00:00
|
|
|
run-metrics: minitor
|
2020-01-10 21:58:17 +00:00
|
|
|
./minitor -debug -metrics
|
2019-10-03 19:56:03 +00:00
|
|
|
|
2020-07-07 03:05:12 +00:00
|
|
|
# Run all tests
|
2019-10-03 19:56:03 +00:00
|
|
|
.PHONY: test
|
|
|
|
test:
|
|
|
|
go test -coverprofile=coverage.out
|
|
|
|
go tool cover -func=coverage.out
|
2019-10-07 21:58:21 +00:00
|
|
|
@go tool cover -func=coverage.out | awk -v target=80.0% \
|
|
|
|
'/^total:/ { print "Total coverage: " $$3 " Minimum coverage: " target; if ($$3+0.0 >= target+0.0) print "ok"; else { print "fail"; exit 1; } }'
|
|
|
|
|
2019-11-21 23:30:19 +00:00
|
|
|
# Installs pre-commit hooks
|
|
|
|
.PHONY: install-hooks
|
|
|
|
install-hooks:
|
|
|
|
pre-commit install --install-hooks
|
|
|
|
|
2020-11-16 23:51:41 +00:00
|
|
|
# Runs pre-commit checks on files
|
2019-11-21 23:30:19 +00:00
|
|
|
.PHONY: check
|
|
|
|
check:
|
|
|
|
pre-commit run --all-files
|
|
|
|
|
2019-10-03 19:56:03 +00:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2020-01-10 21:58:17 +00:00
|
|
|
rm -f ./minitor
|
2019-10-03 19:56:03 +00:00
|
|
|
rm -f ./coverage.out
|
2020-07-07 03:05:12 +00:00
|
|
|
rm -fr ./dist
|
2019-10-11 00:20:42 +00:00
|
|
|
|
|
|
|
.PHONY: docker-build
|
|
|
|
docker-build:
|
2020-01-10 21:58:17 +00:00
|
|
|
docker build -f ./Dockerfile.multi-stage -t $(DOCKER_TAG)-linux-amd64 .
|
2019-10-11 00:20:42 +00:00
|
|
|
|
|
|
|
.PHONY: docker-run
|
|
|
|
docker-run: docker-build
|
2024-11-15 20:05:17 +00:00
|
|
|
docker run --rm -v $(shell pwd)/sample-config.hcl:/root/config.hcl $(DOCKER_TAG)
|
2020-01-10 21:58:17 +00:00
|
|
|
|
|
|
|
## Multi-arch targets
|
2020-07-07 03:05:12 +00:00
|
|
|
$(TARGETS): $(GOFILES)
|
|
|
|
mkdir -p ./dist
|
|
|
|
GOOS=$(word 2, $(subst -, ,$(@))) GOARCH=$(word 3, $(subst -, ,$(@))) CGO_ENABLED=0 \
|
|
|
|
go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
|
|
|
|
-o $@
|
2020-01-10 21:58:17 +00:00
|
|
|
|
2020-07-07 03:05:12 +00:00
|
|
|
.PHONY: $(TARGET_ALIAS)
|
|
|
|
$(TARGET_ALIAS):
|
|
|
|
$(MAKE) $(addprefix dist/,$@)
|
2020-01-10 21:58:17 +00:00
|
|
|
|
|
|
|
# Arch specific docker build targets
|
|
|
|
.PHONY: docker-build-arm
|
2020-07-07 03:05:12 +00:00
|
|
|
docker-build-arm: dist/minitor-linux-arm
|
2024-04-03 19:15:11 +00:00
|
|
|
docker build --platform linux/arm . -t ${DOCKER_TAG}-linux-arm
|
2020-01-10 21:58:17 +00:00
|
|
|
|
2020-07-07 03:05:12 +00:00
|
|
|
.PHONY: docker-build-arm64
|
|
|
|
docker-build-arm64: dist/minitor-linux-arm64
|
2024-04-03 19:15:11 +00:00
|
|
|
docker build --platform linux/arm64 . -t ${DOCKER_TAG}-linux-arm64
|
2020-01-10 21:58:17 +00:00
|
|
|
|
|
|
|
# Cross run on host architechture
|
|
|
|
.PHONY: docker-run-arm
|
|
|
|
docker-run-arm: docker-build-arm
|
|
|
|
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run ${DOCKER_TAG}-linux-arm
|
|
|
|
|
|
|
|
.PHONY: docker-run-arm64
|
|
|
|
docker-run-arm64: docker-build-arm64
|
|
|
|
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run ${DOCKER_TAG}-linux-arm64
|