prometheus-fail2ban-exporter/Makefile

86 lines
2.0 KiB
Makefile
Raw Normal View History

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
CONTAINER_RUNTIME?=$(shell which podman)
# List make commands
.PHONY: ls
ls:
cat Makefile | grep "^[a-zA-Z#].*" | cut -d ":" -f 1 | sed s';#;\n#;'g
# 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
# 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
# Look for "suspicious constructs" in source code
.PHONY: vet
vet: download
go vet ./...
# Format code
.PHONY: fmt
2023-06-19 18:37:27 +00:00
fmt: download
go mod tidy
2023-06-19 17:58:16 +00:00
go fmt ./...
# Check for unformatted go code
.PHONY: check/fmt
2023-06-19 18:37:27 +00:00
check/fmt: download
test -z $(shell gofmt -l .)
# Build project
.PHONY: build
2023-06-19 18:37:27 +00:00
build:
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
# 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
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
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
install -D --mode 0600 env ${DESTDIR}/etc/conf.d/${EXECUTABLE}
2023-07-07 11:30:16 +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