2023-03-07 10:46:52 +00:00
|
|
|
include mk/platform.mk
|
2022-01-06 10:20:59 +00:00
|
|
|
|
2023-05-25 08:32:05 +00:00
|
|
|
BUILD_CODENAME ?= alphaga
|
|
|
|
|
2022-05-17 10:14:59 +00:00
|
|
|
CROWDSEC_FOLDER = ./cmd/crowdsec
|
|
|
|
CSCLI_FOLDER = ./cmd/crowdsec-cli/
|
2022-01-06 10:20:59 +00:00
|
|
|
|
2023-05-25 08:32:05 +00:00
|
|
|
HTTP_PLUGIN_FOLDER = plugins/notifications/http
|
|
|
|
SLACK_PLUGIN_FOLDER = plugins/notifications/slack
|
|
|
|
SPLUNK_PLUGIN_FOLDER = plugins/notifications/splunk
|
|
|
|
EMAIL_PLUGIN_FOLDER = plugins/notifications/email
|
|
|
|
DUMMY_PLUGIN_FOLDER = plugins/notifications/dummy
|
2022-01-06 10:20:59 +00:00
|
|
|
|
2022-05-17 10:14:59 +00:00
|
|
|
HTTP_PLUGIN_BIN = notification-http$(EXT)
|
|
|
|
SLACK_PLUGIN_BIN = notification-slack$(EXT)
|
|
|
|
SPLUNK_PLUGIN_BIN = notification-splunk$(EXT)
|
|
|
|
EMAIL_PLUGIN_BIN = notification-email$(EXT)
|
2023-05-25 08:32:05 +00:00
|
|
|
DUMMY_PLUGIN_BIN = notification-dummy$(EXT)
|
2022-05-17 10:14:59 +00:00
|
|
|
|
|
|
|
CROWDSEC_BIN = crowdsec$(EXT)
|
|
|
|
CSCLI_BIN = cscli$(EXT)
|
2020-05-15 09:39:16 +00:00
|
|
|
|
2023-01-19 21:24:45 +00:00
|
|
|
GO_MODULE_NAME = github.com/crowdsecurity/crowdsec
|
2022-02-04 12:02:45 +00:00
|
|
|
|
|
|
|
LD_OPTS_VARS= \
|
2023-05-23 08:52:47 +00:00
|
|
|
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Version=$(BUILD_VERSION)' \
|
|
|
|
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.BuildDate=$(BUILD_TIMESTAMP)' \
|
|
|
|
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Tag=$(BUILD_TAG)' \
|
2023-01-19 21:24:45 +00:00
|
|
|
-X '$(GO_MODULE_NAME)/pkg/cwversion.Codename=$(BUILD_CODENAME)' \
|
|
|
|
-X '$(GO_MODULE_NAME)/pkg/csconfig.defaultConfigDir=$(DEFAULT_CONFIGDIR)' \
|
|
|
|
-X '$(GO_MODULE_NAME)/pkg/csconfig.defaultDataDir=$(DEFAULT_DATADIR)'
|
2021-04-26 12:45:52 +00:00
|
|
|
|
2023-03-22 10:57:29 +00:00
|
|
|
ifneq (,$(DOCKER_BUILD))
|
|
|
|
LD_OPTS_VARS += -X '$(GO_MODULE_NAME)/pkg/cwversion.System=docker'
|
|
|
|
endif
|
|
|
|
|
2022-09-14 12:22:57 +00:00
|
|
|
ifdef BUILD_STATIC
|
2023-03-30 13:05:09 +00:00
|
|
|
$(warning WARNING: The BUILD_STATIC variable is deprecated and has no effect. Builds are static by default since v1.5.0.)
|
|
|
|
endif
|
|
|
|
|
|
|
|
export LD_OPTS=-ldflags "-s -w -extldflags '-static' $(LD_OPTS_VARS)" \
|
|
|
|
-trimpath -tags netgo,osusergo,sqlite_omit_load_extension
|
|
|
|
|
|
|
|
ifneq (,$(TEST_COVERAGE))
|
|
|
|
LD_OPTS += -cover
|
2022-09-14 12:22:57 +00:00
|
|
|
endif
|
2021-04-26 12:45:52 +00:00
|
|
|
|
2022-09-14 12:22:57 +00:00
|
|
|
GOCMD = go
|
|
|
|
GOTEST = $(GOCMD) test
|
2022-02-14 21:21:19 +00:00
|
|
|
|
2020-05-15 09:39:16 +00:00
|
|
|
RELDIR = crowdsec-$(BUILD_VERSION)
|
|
|
|
|
2023-05-25 08:32:05 +00:00
|
|
|
# flags for sub-makefiles
|
|
|
|
MAKE_FLAGS = --no-print-directory GOARCH=$(GOARCH) GOOS=$(GOOS) RM="$(RM)" WIN_IGNORE_ERR="$(WIN_IGNORE_ERR)" CP="$(CP)" CPR="$(CPR)" MKDIR="$(MKDIR)"
|
|
|
|
|
2022-02-01 08:22:47 +00:00
|
|
|
.PHONY: build
|
2021-08-25 09:43:29 +00:00
|
|
|
build: goversion crowdsec cscli plugins
|
2020-05-15 09:39:16 +00:00
|
|
|
|
2022-02-18 17:09:19 +00:00
|
|
|
.PHONY: all
|
|
|
|
all: clean test build
|
|
|
|
|
2022-02-01 08:22:47 +00:00
|
|
|
.PHONY: plugins
|
2022-03-16 08:30:04 +00:00
|
|
|
plugins: http-plugin slack-plugin splunk-plugin email-plugin dummy-plugin
|
2021-08-25 09:43:29 +00:00
|
|
|
|
2022-02-01 08:22:47 +00:00
|
|
|
.PHONY: clean
|
2022-02-14 21:21:19 +00:00
|
|
|
clean: testclean
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(MAKE) -C $(CROWDSEC_FOLDER) clean $(MAKE_FLAGS)
|
|
|
|
@$(MAKE) -C $(CSCLI_FOLDER) clean $(MAKE_FLAGS)
|
2022-05-17 10:14:59 +00:00
|
|
|
@$(RM) $(CROWDSEC_BIN) $(WIN_IGNORE_ERR)
|
|
|
|
@$(RM) $(CSCLI_BIN) $(WIN_IGNORE_ERR)
|
|
|
|
@$(RM) *.log $(WIN_IGNORE_ERR)
|
|
|
|
@$(RM) crowdsec-release.tgz $(WIN_IGNORE_ERR)
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(RM) ./$(HTTP_PLUGIN_FOLDER)/$(HTTP_PLUGIN_BIN) $(WIN_IGNORE_ERR)
|
|
|
|
@$(RM) ./$(SLACK_PLUGIN_FOLDER)/$(SLACK_PLUGIN_BIN) $(WIN_IGNORE_ERR)
|
|
|
|
@$(RM) ./$(SPLUNK_PLUGIN_FOLDER)/$(SPLUNK_PLUGIN_BIN) $(WIN_IGNORE_ERR)
|
|
|
|
@$(RM) ./$(EMAIL_PLUGIN_FOLDER)/$(EMAIL_PLUGIN_BIN) $(WIN_IGNORE_ERR)
|
|
|
|
@$(RM) ./$(DUMMY_PLUGIN_FOLDER)/$(DUMMY_PLUGIN_BIN) $(WIN_IGNORE_ERR)
|
2020-05-15 09:39:16 +00:00
|
|
|
|
2022-02-14 21:21:19 +00:00
|
|
|
|
2021-08-25 09:43:29 +00:00
|
|
|
cscli: goversion
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(MAKE) -C $(CSCLI_FOLDER) build $(MAKE_FLAGS)
|
2020-05-15 09:39:16 +00:00
|
|
|
|
2021-08-25 09:43:29 +00:00
|
|
|
crowdsec: goversion
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(MAKE) -C $(CROWDSEC_FOLDER) build $(MAKE_FLAGS)
|
2020-05-15 09:39:16 +00:00
|
|
|
|
2021-08-25 09:43:29 +00:00
|
|
|
http-plugin: goversion
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(MAKE) -C ./$(HTTP_PLUGIN_FOLDER) build $(MAKE_FLAGS)
|
2020-05-15 09:39:16 +00:00
|
|
|
|
2021-08-25 09:43:29 +00:00
|
|
|
slack-plugin: goversion
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(MAKE) -C ./$(SLACK_PLUGIN_FOLDER) build $(MAKE_FLAGS)
|
2020-05-15 09:39:16 +00:00
|
|
|
|
2021-08-25 09:43:29 +00:00
|
|
|
splunk-plugin: goversion
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(MAKE) -C ./$(SPLUNK_PLUGIN_FOLDER) build $(MAKE_FLAGS)
|
2020-05-15 09:39:16 +00:00
|
|
|
|
2022-01-06 10:20:59 +00:00
|
|
|
email-plugin: goversion
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(MAKE) -C ./$(EMAIL_PLUGIN_FOLDER) build $(MAKE_FLAGS)
|
2021-08-25 09:43:29 +00:00
|
|
|
|
2022-03-16 08:30:04 +00:00
|
|
|
dummy-plugin: goversion
|
2023-05-25 08:32:05 +00:00
|
|
|
$(MAKE) -C ./$(DUMMY_PLUGIN_FOLDER) build $(MAKE_FLAGS)
|
2022-03-16 08:30:04 +00:00
|
|
|
|
2022-02-14 21:21:19 +00:00
|
|
|
.PHONY: testclean
|
2022-03-09 13:45:36 +00:00
|
|
|
testclean: bats-clean
|
2022-05-17 10:14:59 +00:00
|
|
|
@$(RM) pkg/apiserver/ent $(WIN_IGNORE_ERR)
|
|
|
|
@$(RM) pkg/cwhub/hubdir $(WIN_IGNORE_ERR)
|
2022-05-17 13:54:52 +00:00
|
|
|
@$(RM) pkg/cwhub/install $(WIN_IGNORE_ERR)
|
|
|
|
@$(RM) pkg/types/example.txt $(WIN_IGNORE_ERR)
|
2022-02-14 21:21:19 +00:00
|
|
|
|
2023-03-08 13:41:16 +00:00
|
|
|
export AWS_ENDPOINT_FORCE=http://localhost:4566
|
|
|
|
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
|
|
|
|
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
|
|
|
|
|
|
|
testenv:
|
2022-06-16 14:13:48 +00:00
|
|
|
@echo 'NOTE: You need Docker, docker-compose and run "make localstack" in a separate shell ("make localstack-stop" to terminate it)'
|
2023-03-08 13:41:16 +00:00
|
|
|
|
|
|
|
.PHONY: test
|
|
|
|
test: testenv goversion
|
2022-02-14 21:21:19 +00:00
|
|
|
$(GOTEST) $(LD_OPTS) ./...
|
2021-08-25 09:43:29 +00:00
|
|
|
|
2023-03-08 13:41:16 +00:00
|
|
|
.PHONY: go-acc
|
|
|
|
go-acc: testenv goversion
|
|
|
|
go-acc ./... -o coverage.out --ignore database,notifications,protobufs,cwversion,cstest,models -- $(LD_OPTS) | \
|
|
|
|
sed 's/ *coverage:.*of statements in.*//'
|
|
|
|
|
2022-05-17 13:54:52 +00:00
|
|
|
.PHONY: localstack
|
|
|
|
localstack:
|
2023-03-03 14:54:49 +00:00
|
|
|
docker-compose -f test/localstack/docker-compose.yml up
|
2022-05-17 13:54:52 +00:00
|
|
|
|
2022-06-16 14:13:48 +00:00
|
|
|
.PHONY: localstack-stop
|
|
|
|
localstack-stop:
|
2023-03-03 14:54:49 +00:00
|
|
|
docker-compose -f test/localstack/docker-compose.yml down
|
2022-06-16 14:13:48 +00:00
|
|
|
|
2022-03-15 10:19:35 +00:00
|
|
|
package-common:
|
2022-05-17 10:14:59 +00:00
|
|
|
@echo "Building Release to dir $(RELDIR)"
|
|
|
|
@$(MKDIR) $(RELDIR)/cmd/crowdsec
|
|
|
|
@$(MKDIR) $(RELDIR)/cmd/crowdsec-cli
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(MKDIR) $(RELDIR)/$(HTTP_PLUGIN_FOLDER)
|
|
|
|
@$(MKDIR) $(RELDIR)/$(SLACK_PLUGIN_FOLDER)
|
|
|
|
@$(MKDIR) $(RELDIR)/$(SPLUNK_PLUGIN_FOLDER)
|
|
|
|
@$(MKDIR) $(RELDIR)/$(EMAIL_PLUGIN_FOLDER)
|
2022-05-17 10:14:59 +00:00
|
|
|
|
|
|
|
@$(CP) $(CROWDSEC_FOLDER)/$(CROWDSEC_BIN) $(RELDIR)/cmd/crowdsec
|
|
|
|
@$(CP) $(CSCLI_FOLDER)/$(CSCLI_BIN) $(RELDIR)/cmd/crowdsec-cli
|
|
|
|
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(CP) ./$(HTTP_PLUGIN_FOLDER)/$(HTTP_PLUGIN_BIN) $(RELDIR)/$(HTTP_PLUGIN_FOLDER)
|
|
|
|
@$(CP) ./$(SLACK_PLUGIN_FOLDER)/$(SLACK_PLUGIN_BIN) $(RELDIR)/$(SLACK_PLUGIN_FOLDER)
|
|
|
|
@$(CP) ./$(SPLUNK_PLUGIN_FOLDER)/$(SPLUNK_PLUGIN_BIN) $(RELDIR)/$(SPLUNK_PLUGIN_FOLDER)
|
|
|
|
@$(CP) ./$(EMAIL_PLUGIN_FOLDER)/$(EMAIL_PLUGIN_BIN) $(RELDIR)/$(EMAIL_PLUGIN_FOLDER)
|
2022-05-17 10:14:59 +00:00
|
|
|
|
2023-05-25 08:32:05 +00:00
|
|
|
@$(CP) ./$(HTTP_PLUGIN_FOLDER)/http.yaml $(RELDIR)/$(HTTP_PLUGIN_FOLDER)
|
|
|
|
@$(CP) ./$(SLACK_PLUGIN_FOLDER)/slack.yaml $(RELDIR)/$(SLACK_PLUGIN_FOLDER)
|
|
|
|
@$(CP) ./$(SPLUNK_PLUGIN_FOLDER)/splunk.yaml $(RELDIR)/$(SPLUNK_PLUGIN_FOLDER)
|
|
|
|
@$(CP) ./$(EMAIL_PLUGIN_FOLDER)/email.yaml $(RELDIR)/$(EMAIL_PLUGIN_FOLDER)
|
2022-05-17 10:14:59 +00:00
|
|
|
|
|
|
|
@$(CPR) ./config $(RELDIR)
|
|
|
|
@$(CP) wizard.sh $(RELDIR)
|
|
|
|
@$(CP) scripts/test_env.sh $(RELDIR)
|
|
|
|
@$(CP) scripts/test_env.ps1 $(RELDIR)
|
2021-09-14 13:32:35 +00:00
|
|
|
|
2022-03-15 10:19:35 +00:00
|
|
|
.PHONY: package
|
|
|
|
package: package-common
|
|
|
|
@tar cvzf crowdsec-release.tgz $(RELDIR)
|
2022-01-06 10:20:59 +00:00
|
|
|
|
2021-08-25 09:43:29 +00:00
|
|
|
.PHONY: check_release
|
|
|
|
check_release:
|
2022-09-14 12:22:57 +00:00
|
|
|
ifneq ($(OS), Windows_NT)
|
2021-08-25 09:43:29 +00:00
|
|
|
@if [ -d $(RELDIR) ]; then echo "$(RELDIR) already exists, abort" ; exit 1 ; fi
|
2022-05-17 10:14:59 +00:00
|
|
|
else
|
|
|
|
@if (Test-Path -Path $(RELDIR)) { echo "$(RELDIR) already exists, abort" ; exit 1 ; }
|
|
|
|
endif
|
2021-08-25 09:43:29 +00:00
|
|
|
|
2022-02-01 08:22:47 +00:00
|
|
|
.PHONY: release
|
2021-08-25 09:43:29 +00:00
|
|
|
release: check_release build package
|
|
|
|
|
2022-05-17 10:14:59 +00:00
|
|
|
.PHONY: windows_installer
|
|
|
|
windows_installer: build
|
|
|
|
@.\make_installer.ps1 -version $(BUILD_VERSION)
|
|
|
|
|
|
|
|
.PHONY: chocolatey
|
|
|
|
chocolatey: windows_installer
|
|
|
|
@.\make_chocolatey.ps1 -version $(BUILD_VERSION)
|
2022-03-09 13:45:36 +00:00
|
|
|
|
2023-03-03 14:54:49 +00:00
|
|
|
# Include test/bats.mk only if it exists
|
2023-01-25 09:39:23 +00:00
|
|
|
# to allow building without a test/ directory
|
|
|
|
# (i.e. inside docker)
|
2023-03-03 14:54:49 +00:00
|
|
|
ifeq (,$(wildcard test/bats.mk))
|
2023-01-25 09:39:23 +00:00
|
|
|
bats-clean:
|
|
|
|
else
|
2023-03-03 14:54:49 +00:00
|
|
|
include test/bats.mk
|
2023-01-25 09:39:23 +00:00
|
|
|
endif
|
2023-03-07 10:46:52 +00:00
|
|
|
|
|
|
|
include mk/goversion.mk
|