2014-04-16 22:40:15 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
# Copyright (c) 2014 Mozilla Corporation
|
|
|
|
#
|
|
|
|
|
2018-10-16 00:37:10 +03:00
|
|
|
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
2018-10-17 00:10:49 +03:00
|
|
|
DKR_IMAGES := mozdef_alertplugins mozdef_alerts mozdef_base mozdef_bootstrap mozdef_meteor mozdef_rest \
|
2018-10-24 23:42:03 +03:00
|
|
|
mozdef_mq_worker mozdef_loginput mozdef_cron mozdef_elasticsearch mozdef_mongodb \
|
2018-10-17 19:39:01 +03:00
|
|
|
mozdef_syslog mozdef_nginx mozdef_tester mozdef_rabbitmq mozdef_kibana
|
2018-10-30 23:01:47 +03:00
|
|
|
BUILD_MODE := build ## Pass `pull` in order to pull images instead of building them
|
2018-10-16 01:39:22 +03:00
|
|
|
NAME := mozdef
|
|
|
|
VERSION := 0.1
|
2018-10-18 00:30:36 +03:00
|
|
|
NO_CACHE := ## Pass `--no-cache` in order to disable Docker cache
|
2018-10-30 23:01:47 +03:00
|
|
|
GITHASH := latest ## Pass `$(git rev-parse --short HEAD`) to tag docker hub images as latest git-hash instead
|
2018-10-30 23:40:13 +03:00
|
|
|
TEST_CASE := tests ## Run all (`tests`) or a specific test case (ex `tests/alerts/tests/alerts/test_proxy_drop_exfil_domains.py`)
|
2014-04-01 08:06:49 +04:00
|
|
|
|
2018-10-16 01:39:22 +03:00
|
|
|
.PHONY:all
|
2018-10-16 00:37:10 +03:00
|
|
|
all:
|
|
|
|
@echo 'Available make targets:'
|
2018-10-16 01:39:22 +03:00
|
|
|
@grep '^[^#[:space:]^\.PHONY.*].*:' Makefile
|
2018-10-16 00:37:10 +03:00
|
|
|
|
2018-10-30 23:01:47 +03:00
|
|
|
.PHONY: run
|
2018-10-17 19:39:01 +03:00
|
|
|
run: build ## Run all MozDef containers
|
2018-10-30 23:01:47 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose.yml -p $(NAME) up -d
|
2018-10-17 19:39:01 +03:00
|
|
|
|
2018-10-19 19:49:41 +03:00
|
|
|
.PHONY: run-cloudy-mozdef restart-cloudy-mozdef
|
2018-10-17 19:39:01 +03:00
|
|
|
run-cloudy-mozdef: ## Run the MozDef containers necessary to run in AWS (`cloudy-mozdef`). This is used by the CloudFormation-initiated setup.
|
2018-10-18 18:43:48 +03:00
|
|
|
$(shell test -f docker/compose/cloudy_mozdef.env || touch docker/compose/cloudy_mozdef.env)
|
2018-10-18 18:58:28 +03:00
|
|
|
$(shell test -f docker/compose/cloudy_mozdef_kibana.env || touch docker/compose/cloudy_mozdef_kibana.env)
|
2018-10-18 02:45:40 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose-cloudy-mozdef.yml -p $(NAME) pull
|
2018-10-18 01:40:43 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose-cloudy-mozdef.yml -p $(NAME) up -d
|
2017-07-15 03:00:52 +03:00
|
|
|
|
2019-01-28 21:45:19 +03:00
|
|
|
.PHONY: run-env-mozdef
|
|
|
|
run-env-mozdef: ## Run the MozDef containers with a user specified env file. Run with make 'run-env-mozdef -e ENV=my.env'
|
|
|
|
$(shell test -f $(ENV) || touch $(ENV))
|
2019-01-29 01:53:33 +03:00
|
|
|
ENV_FILE=$(abspath $(ENV))
|
|
|
|
docker-compose -f docker/compose/docker-compose.yml -f docker/compose/docker-compose-user-env.yml -p $(NAME) up -d
|
2019-01-28 21:45:19 +03:00
|
|
|
|
2018-10-19 19:49:41 +03:00
|
|
|
restart-cloudy-mozdef:
|
|
|
|
docker-compose -f docker/compose/docker-compose-cloudy-mozdef.yml -p $(NAME) restart
|
|
|
|
|
2018-11-28 22:33:01 +03:00
|
|
|
.PHONY: tests run-tests-resources run-tests-resources-external run-tests
|
2018-10-30 23:40:13 +03:00
|
|
|
test: build-tests run-tests
|
|
|
|
tests: build-tests run-tests ## Run all tests (getting/building images as needed)
|
2018-11-28 22:33:01 +03:00
|
|
|
run-tests-resources-external: ## Just spin up external resources for tests and have them listen externally
|
|
|
|
docker-compose -f docker/compose/docker-compose-tests.yml -p test-$(NAME) run -p 9200:9200 -d elasticsearch
|
|
|
|
docker-compose -f docker/compose/docker-compose-tests.yml -p test-$(NAME) run -p 5672:5672 -d rabbitmq
|
2018-11-15 00:20:21 +03:00
|
|
|
run-tests-resources: ## Just run the external resources required for tests
|
2018-10-30 23:06:50 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose-tests.yml -p test-$(NAME) up -d
|
2018-11-15 00:20:21 +03:00
|
|
|
run-test:
|
|
|
|
run-tests: run-tests-resources ## Just run the tests (no build/get). Use `make TEST_CASE=tests/...` for specific tests only
|
2018-10-31 00:04:16 +03:00
|
|
|
docker run -it --rm mozdef/mozdef_tester bash -c "source /opt/mozdef/envs/python/bin/activate && flake8 --config .flake8 ./"
|
2018-10-30 23:40:13 +03:00
|
|
|
docker run -it --rm --network=test-mozdef_default mozdef/mozdef_tester bash -c "source /opt/mozdef/envs/python/bin/activate && py.test --delete_indexes --delete_queues $(TEST_CASE)"
|
2018-11-27 22:53:55 +03:00
|
|
|
rebuild-run-tests: build-tests run-tests
|
|
|
|
|
2018-10-16 01:39:22 +03:00
|
|
|
|
|
|
|
.PHONY: build
|
2018-10-17 18:37:54 +03:00
|
|
|
build: ## Build local MozDef images (use make NO_CACHE=--no-cache build to disable caching)
|
2018-10-30 23:01:47 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose.yml -p $(NAME) $(NO_CACHE) $(BUILD_MODE)
|
2018-10-17 00:56:09 +03:00
|
|
|
|
2018-10-30 23:06:50 +03:00
|
|
|
.PHONY: build-tests
|
2018-10-30 23:01:47 +03:00
|
|
|
build-tests: ## Build end-to-end test environment only
|
2018-10-30 23:06:50 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose-tests.yml -p test-$(NAME) $(NO_CACHE) $(BUILD_MODE)
|
2017-09-07 06:14:10 +03:00
|
|
|
|
2018-10-16 01:39:22 +03:00
|
|
|
.PHONY: stop down
|
|
|
|
stop: down
|
2018-10-17 18:37:54 +03:00
|
|
|
down: ## Shutdown all services we started with docker-compose
|
2018-10-30 23:01:47 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose.yml -p $(NAME) stop
|
2018-10-30 23:40:13 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose.yml -p test-$(NAME) stop
|
2017-07-15 03:00:52 +03:00
|
|
|
|
2018-10-17 02:35:00 +03:00
|
|
|
.PHONY: docker-push docker-get hub hub-get
|
2018-10-17 00:10:49 +03:00
|
|
|
docker-push: hub
|
2018-10-18 00:30:36 +03:00
|
|
|
hub: ## Upload locally built MozDef images tagged as the current git head (hub.docker.com/mozdef).
|
2018-10-17 00:10:49 +03:00
|
|
|
docker login
|
2018-10-30 23:53:07 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose.yml -p $(NAME) push
|
2018-10-31 00:03:23 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose-tests.yml -p test-$(NAME) push
|
2018-10-17 00:10:49 +03:00
|
|
|
|
2018-10-17 02:35:00 +03:00
|
|
|
docker-get: hub-get
|
2018-10-17 18:37:54 +03:00
|
|
|
hub-get: ## Download all pre-built images (hub.docker.com/mozdef)
|
2018-10-30 23:53:07 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose.yml -p $(NAME) pull
|
|
|
|
docker-compose -f docker/compose/docker-compose-test.yml -p test-$(NAME) pull
|
2018-10-17 02:35:00 +03:00
|
|
|
|
2018-10-16 01:39:22 +03:00
|
|
|
.PHONY: clean
|
2018-10-17 18:37:54 +03:00
|
|
|
clean: ## Cleanup all docker volumes and shutdown all related services
|
2018-10-30 23:01:47 +03:00
|
|
|
-docker-compose -f docker/compose/docker-compose.yml -p $(NAME) down -v --remove-orphans
|
2018-10-30 23:40:13 +03:00
|
|
|
-docker-compose -f docker/compose/docker-compose-tests.yml -p test-$(NAME) down -v --remove-orphans
|
2018-10-16 00:37:10 +03:00
|
|
|
# Shorthands
|
2018-10-16 01:39:22 +03:00
|
|
|
.PHONY: rebuild
|
2018-10-17 18:37:54 +03:00
|
|
|
rebuild: clean build
|
2018-10-31 22:21:29 +03:00
|
|
|
|
|
|
|
.PHONY: new-alert
|
|
|
|
new-alert: ## Create an example alert and working alert unit test
|
|
|
|
python tests/alert_templater.py
|