2023-07-07 11:30:16 +00:00
|
|
|
DESTDIR?=
|
|
|
|
PREFIX?=/usr/local
|
2023-07-09 10:57:07 +00:00
|
|
|
EXECUTABLE?=prometheus-fail2ban-exporter
|
2023-07-07 11:30:16 +00:00
|
|
|
|
2023-07-09 10:59:32 +00:00
|
|
|
CONTAINER_RUNTIME?=$(shell which podman)
|
2023-07-07 12:04:07 +00:00
|
|
|
|
2023-06-21 15:02:11 +00:00
|
|
|
# List make commands
|
|
|
|
.PHONY: ls
|
|
|
|
ls:
|
|
|
|
cat Makefile | grep "^[a-zA-Z#].*" | cut -d ":" -f 1 | sed s';#;\n#;'g
|
2023-06-19 19:06:18 +00:00
|
|
|
|
2023-06-21 15:02:11 +00:00
|
|
|
# Download dependencies
|
|
|
|
.PHONY: download
|
2023-06-19 18:37:27 +00:00
|
|
|
download:
|
2023-06-19 17:58:16 +00:00
|
|
|
go mod download
|
2021-02-05 22:49:47 +00:00
|
|
|
|
2023-06-21 15:02:11 +00:00
|
|
|
# Update project dependencies
|
|
|
|
.PHONY: update
|
|
|
|
update:
|
|
|
|
go get -u
|
|
|
|
go mod download
|
|
|
|
go mod tidy
|
|
|
|
|
|
|
|
# Run project tests
|
|
|
|
.PHONY: test
|
2023-06-19 18:37:27 +00:00
|
|
|
test: download
|
2023-06-19 17:58:16 +00:00
|
|
|
go test ./... -v -race
|
2021-10-17 17:39:02 +00:00
|
|
|
|
2023-06-22 18:24:15 +00:00
|
|
|
# Look for "suspicious constructs" in source code
|
|
|
|
.PHONY: vet
|
|
|
|
vet: download
|
|
|
|
go vet ./...
|
|
|
|
|
2023-06-21 15:02:11 +00:00
|
|
|
# Format code
|
|
|
|
.PHONY: fmt
|
2023-06-19 18:37:27 +00:00
|
|
|
fmt: download
|
2023-06-21 15:02:11 +00:00
|
|
|
go mod tidy
|
2023-06-19 17:58:16 +00:00
|
|
|
go fmt ./...
|
2021-10-17 17:39:02 +00:00
|
|
|
|
2023-06-21 15:02:11 +00:00
|
|
|
# Check for unformatted go code
|
|
|
|
.PHONY: check/fmt
|
2023-06-19 18:37:27 +00:00
|
|
|
check/fmt: download
|
|
|
|
test -z $(shell gofmt -l .)
|
2022-02-12 17:31:01 +00:00
|
|
|
|
2023-06-21 15:02:11 +00:00
|
|
|
# Build project
|
|
|
|
.PHONY: build
|
2023-06-19 18:37:27 +00:00
|
|
|
build:
|
2023-06-22 15:22:42 +00:00
|
|
|
CGO_ENABLED=0 go build \
|
2023-06-19 18:37:27 +00:00
|
|
|
-ldflags "\
|
|
|
|
-X main.version=${shell git describe --tags} \
|
|
|
|
-X main.commit=${shell git rev-parse HEAD} \
|
|
|
|
-X main.date=${shell date --iso-8601=seconds} \
|
|
|
|
-X main.builtBy=manual \
|
|
|
|
" \
|
2023-07-07 11:29:55 +00:00
|
|
|
-trimpath \
|
2023-07-07 11:30:16 +00:00
|
|
|
-o ${EXECUTABLE} \
|
2023-06-19 18:37:27 +00:00
|
|
|
exporter.go
|
2023-06-19 19:06:18 +00:00
|
|
|
|
2023-07-07 12:04:07 +00:00
|
|
|
# build container-image
|
|
|
|
.PHONY: build/container-image
|
|
|
|
build/container-image:
|
|
|
|
${CONTAINER_RUNTIME} build \
|
|
|
|
--tag ${EXECUTABLE} \
|
|
|
|
.
|
2023-07-07 11:30:16 +00:00
|
|
|
|
|
|
|
.PHONY: install
|
|
|
|
install: build
|
2023-07-07 12:04:07 +00:00
|
|
|
mkdir --parents ${DESTDIR}/usr/lib/systemd/system
|
|
|
|
sed -e "s/EXECUTABLE/${EXECUTABLE}/gm" systemd/systemd.service > ${DESTDIR}/usr/lib/systemd/system/${EXECUTABLE}.service
|
|
|
|
chmod 0644 ${DESTDIR}/usr/lib/systemd/system/${EXECUTABLE}.service
|
2023-07-07 11:30:16 +00:00
|
|
|
|
2023-07-07 12:04:07 +00:00
|
|
|
install -D --mode 0755 --target-directory ${DESTDIR}${PREFIX}/bin ${EXECUTABLE}
|
2023-07-07 11:30:16 +00:00
|
|
|
|
|
|
|
# NOTE: Set restrict file permissions by default to protect optional basic auth credentials
|
2023-07-07 12:04:07 +00:00
|
|
|
install -D --mode 0600 env ${DESTDIR}/etc/conf.d/${EXECUTABLE}
|
2023-07-07 11:30:16 +00:00
|
|
|
|
2023-07-07 12:04:07 +00:00
|
|
|
install -D --mode 0755 --target-directory ${DESTDIR}${PREFIX}/share/licenses/${EXECUTABLE} LICENSE
|
2023-07-07 11:33:21 +00:00
|
|
|
|
|
|
|
.PHONY: uninstall
|
|
|
|
uninstall:
|
|
|
|
-rm --recursive --force \
|
|
|
|
${DESTDIR}${PREFIX}/bin/${EXECUTABLE} \
|
|
|
|
${DESTDIR}/usr/lib/systemd/system/${EXECUTABLE}.service \
|
|
|
|
${DESTDIR}/etc/conf.d/${EXECUTABLE} \
|
|
|
|
${DESTDIR}${PREFIX}/share/licenses/${EXECUTABLE}/LICENSE
|