| 1 |
# Go parameters |
| 2 |
GOCMD=go |
| 3 |
GOBUILD=$(GOCMD) build |
| 4 |
GOCLEAN=$(GOCMD) clean |
| 5 |
GOTEST=$(GOCMD) test |
| 6 |
GOGET=$(GOCMD) get |
| 7 |
|
| 8 |
# Current versioning information from env |
| 9 |
BUILD_VERSION?="$(shell git describe --tags)" |
| 10 |
BUILD_GOVERSION=$(shell go env GOVERSION | sed s/go//) |
| 11 |
BUILD_TIMESTAMP=$(shell date +%F"_"%T) |
| 12 |
BUILD_TAG?=$(shell git rev-parse HEAD) |
| 13 |
|
| 14 |
LD_OPTS_VARS=\ |
| 15 |
-X github.com/crowdsecurity/cs-firewall-bouncer/pkg/version.Version=$(BUILD_VERSION) \ |
| 16 |
-X github.com/crowdsecurity/cs-firewall-bouncer/pkg/version.BuildDate=$(BUILD_TIMESTAMP) \ |
| 17 |
-X github.com/crowdsecurity/cs-firewall-bouncer/pkg/version.Tag=$(BUILD_TAG) |
| 18 |
|
| 19 |
ifdef BUILD_STATIC |
| 20 |
export LD_OPTS=-ldflags "-a -s -w -extldflags '-static' $(LD_OPTS_VARS)" -tags netgo |
| 21 |
else |
| 22 |
export LD_OPTS=-ldflags "-a -s -w $(LD_OPTS_VARS)" |
| 23 |
endif |
| 24 |
|
| 25 |
PREFIX?="/" |
| 26 |
BINARY_NAME=crowdsec-firewall-bouncer |
| 27 |
|
| 28 |
MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1 |
| 29 |
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 13 |
| 30 |
|
| 31 |
#Golang version info |
| 32 |
go_major_minor = $(subst ., ,$(BUILD_GOVERSION)) |
| 33 |
GO_MAJOR_VERSION = $(word 1, $(go_major_minor)) |
| 34 |
GO_MINOR_VERSION = $(word 2, $(go_major_minor)) |
| 35 |
|
| 36 |
GO_VERSION_VALIDATION_ERR_MSG = Golang version ($(BUILD_GOVERSION)) is not supported, please use at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION) |
| 37 |
|
| 38 |
RELDIR = "crowdsec-firewall-bouncer-${BUILD_VERSION}" |
| 39 |
|
| 40 |
PYTHON=python3 |
| 41 |
PIP=pip |
| 42 |
|
| 43 |
all: clean build |
| 44 |
|
| 45 |
goversion: |
| 46 |
@if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ |
| 47 |
exit 0 ;\ |
| 48 |
elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ |
| 49 |
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ |
| 50 |
exit 1; \ |
| 51 |
elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \ |
| 52 |
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ |
| 53 |
exit 1; \ |
| 54 |
fi |
| 55 |
|
| 56 |
|
| 57 |
.PHONY: lint |
| 58 |
lint: |
| 59 |
golangci-lint run |
| 60 |
|
| 61 |
build: goversion clean |
| 62 |
$(GOBUILD) $(LD_OPTS) $(BUILD_VENDOR_FLAGS) -o $(BINARY_NAME) |
| 63 |
|
| 64 |
test: |
| 65 |
@$(GOTEST) $(LD_OPTS) ./... |
| 66 |
|
| 67 |
clean: |
| 68 |
@$(RM) $(BINARY_NAME) |
| 69 |
@$(RM) -r ${RELDIR} |
| 70 |
@$(RM) crowdsec-firewall-bouncer.tgz |
| 71 |
@$(RM) -r tests/venv |
| 72 |
|
| 73 |
.PHONY: func-tests |
| 74 |
func-tests: build |
| 75 |
( \ |
| 76 |
$(PYTHON) -m venv tests/venv ; \ |
| 77 |
tests/venv/bin/$(PIP) install -r tests/requirements.txt ; \ |
| 78 |
sudo tests/venv/bin/$(PYTHON) -B -m unittest -v ; \ |
| 79 |
) |
| 80 |
|
| 81 |
.PHONY: release |
| 82 |
release: build |
| 83 |
@if [ -z ${BUILD_VERSION} ] ; then BUILD_VERSION="local" ; fi |
| 84 |
@if [ -d $(RELDIR) ]; then echo "$(RELDIR) already exists, clean" ; exit 1 ; fi |
| 85 |
@echo Building Release to dir $(RELDIR) |
| 86 |
@mkdir $(RELDIR)/ |
| 87 |
@cp $(BINARY_NAME) $(RELDIR)/ |
| 88 |
@cp -R ./config $(RELDIR)/ |
| 89 |
@cp ./scripts/install.sh $(RELDIR)/ |
| 90 |
@cp ./scripts/uninstall.sh $(RELDIR)/ |
| 91 |
@cp ./scripts/upgrade.sh $(RELDIR)/ |
| 92 |
@chmod +x $(RELDIR)/install.sh |
| 93 |
@chmod +x $(RELDIR)/uninstall.sh |
| 94 |
@chmod +x $(RELDIR)/upgrade.sh |
| 95 |
@tar cvzf crowdsec-firewall-bouncer.tgz $(RELDIR) |