2023-09-09 19:30:55 +02:00
.PHONY : all clean generate build test e 2e -test lint run fmt docker -build help
2022-10-21 20:56:26 +02:00
.DEFAULT_GOAL := help
2021-09-09 22:57:05 +02:00
2022-10-21 20:56:26 +02:00
VERSION ?= $( shell git describe --always --tags)
2023-10-08 23:34:54 +02:00
BUILD_TIME ?= $( shell date --iso-8601= seconds)
DOC_PATH ?= "main"
2022-09-08 22:34:08 +02:00
DOCKER_IMAGE_NAME = spx01/blocky
2022-10-21 20:56:26 +02:00
BINARY_NAME := blocky
BIN_OUT_DIR ?= bin
2022-10-21 23:59:35 +02:00
GOARCH ?= $( shell go env GOARCH)
GOARM ?= $( shell go env GOARM)
2022-10-21 20:56:26 +02:00
2022-10-21 23:59:35 +02:00
GO_BUILD_FLAGS ?= -v
2022-10-21 20:56:26 +02:00
GO_BUILD_LD_FLAGS := \
-w \
-s \
-X github.com/0xERR0R/blocky/util.Version= ${ VERSION } \
2023-10-08 23:34:54 +02:00
-X github.com/0xERR0R/blocky/util.BuildTime= $( shell date -d " ${ BUILD_TIME } " '+%Y%m%d-%H%M%S' ) \
2022-10-21 21:13:54 +02:00
-X github.com/0xERR0R/blocky/util.Architecture= ${ GOARCH } ${ GOARM }
2022-10-21 20:56:26 +02:00
GO_BUILD_OUTPUT := $( BIN_OUT_DIR) /$( BINARY_NAME) $( BINARY_SUFFIX)
2020-01-12 18:23:35 +01:00
2023-01-05 08:44:04 +01:00
# define version of golangci-lint here. If defined in tools.go, go mod perfoms automatically downgrade to older version which doesn't work with golang >=1.18
2024-04-12 22:44:50 +02:00
GOLANG_LINT_VERSION = v1.57.2
2023-01-05 08:44:04 +01:00
2023-11-11 17:58:31 +01:00
GINKGO_PROCS ?= -p
2021-09-09 22:57:05 +02:00
export PATH = $( shell go env GOPATH) /bin:$( shell echo $$ PATH)
2021-11-10 21:44:52 +01:00
all : build test lint ## Build binary (with tests)
2020-01-12 18:23:35 +01:00
clean : ## cleans output directory
2022-10-21 20:56:26 +02:00
rm -rf $( BIN_OUT_DIR) /*
2020-01-12 18:23:35 +01:00
2021-03-05 08:02:00 +01:00
serve_docs : ## serves online docs
2022-11-18 15:29:33 +01:00
pip install mkdocs-material
2021-03-05 08:02:00 +01:00
mkdocs serve
2023-02-07 14:00:53 +01:00
generate : ## Go generate
2022-10-21 20:56:26 +02:00
i f d e f G O _ S K I P _ G E N E R A T E
$( info skipping go generate)
e l s e
2021-09-09 22:57:05 +02:00
go generate ./...
2022-10-21 20:56:26 +02:00
e n d i f
2023-02-07 14:00:53 +01:00
2023-11-17 15:58:35 +01:00
build : generate ## Build binary
2022-10-21 20:56:26 +02:00
go build $( GO_BUILD_FLAGS) -ldflags= " $( GO_BUILD_LD_FLAGS) " -o $( GO_BUILD_OUTPUT)
i f d e f B I N _ U S E R
2022-10-21 21:07:40 +02:00
$( info setting owner of $( GO_BUILD_OUTPUT) to $( BIN_USER) )
chown $( BIN_USER) $( GO_BUILD_OUTPUT)
2022-10-21 20:56:26 +02:00
e n d i f
i f d e f B I N _ A U T O C A B
$( info setting cap_net_bind_service to $( GO_BUILD_OUTPUT) )
setcap 'cap_net_bind_service=+ep' $( GO_BUILD_OUTPUT)
e n d i f
2022-09-08 22:34:08 +02:00
2022-11-24 21:54:52 +01:00
test : ## run tests
2023-11-11 17:58:31 +01:00
go run github.com/onsi/ginkgo/v2/ginkgo --label-filter= "!e2e" --coverprofile= coverage.txt --covermode= atomic --cover -r ${ GINKGO_PROCS }
2023-11-17 15:58:35 +01:00
go tool cover -html coverage.txt -o coverage.html
2022-11-24 21:54:52 +01:00
e2e-test : ## run e2e tests
docker buildx build \
--build-arg VERSION = blocky-e2e \
--network= host \
-o type = docker \
-t blocky-e2e \
.
2023-09-18 11:43:27 +02:00
go run github.com/onsi/ginkgo/v2/ginkgo --label-filter= "e2e" --timeout 15m --flake-attempts 1 e2e
2020-01-12 18:23:35 +01:00
2022-05-06 22:34:08 +02:00
race : ## run tests with race detector
2023-11-11 17:58:31 +01:00
go run github.com/onsi/ginkgo/v2/ginkgo --label-filter= "!e2e" --race -r ${ GINKGO_PROCS }
2022-05-06 22:34:08 +02:00
2023-04-04 09:25:45 +02:00
lint : fmt ## run golangcli-lint checks
2023-01-05 08:44:04 +01:00
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$( GOLANG_LINT_VERSION) run --timeout 5m
2020-01-12 18:23:35 +01:00
run : build ## Build and run binary
./$( BIN_OUT_DIR) /$( BINARY_NAME)
2021-08-25 22:12:12 +02:00
fmt : ## gofmt and goimports all go files
2022-12-26 22:11:45 +01:00
go run mvdan.cc/gofumpt -l -w -extra .
2023-04-04 09:25:45 +02:00
find . -name '*.go' -exec go run golang.org/x/tools/cmd/goimports -w { } +
2021-08-25 22:12:12 +02:00
2023-11-17 15:58:35 +01:00
docker-build : generate ## Build docker image
2022-10-22 00:26:20 +02:00
docker buildx build \
2022-10-22 00:31:52 +02:00
--build-arg VERSION = ${ VERSION } \
--build-arg BUILD_TIME = ${ BUILD_TIME } \
2023-10-08 23:34:54 +02:00
--build-arg DOC_PATH = ${ DOC_PATH } \
2022-10-22 00:31:52 +02:00
--network= host \
-o type = docker \
-t ${ DOCKER_IMAGE_NAME } \
.
2020-02-13 17:18:24 +01:00
2020-01-12 18:23:35 +01:00
help : ## Shows help
2022-11-24 21:54:52 +01:00
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $( MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'