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))))
|
2019-03-20 23:25:22 +03:00
|
|
|
DKR_IMAGES := mozdef_alertactions 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 \
|
2019-05-04 00:03:41 +03:00
|
|
|
mozdef_syslog mozdef_nginx mozdef_tester mozdef_rabbitmq mozdef_kibana mozdef_cognito_proxy
|
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
|
2019-03-19 01:56:56 +03:00
|
|
|
BRANCH := master
|
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`)
|
2019-03-19 01:56:56 +03:00
|
|
|
TMPDIR := $(shell mktemp -d )
|
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
|
|
|
|
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'
|
2019-02-01 21:49:59 +03:00
|
|
|
ifneq ("$(wildcard $(ENV))","") #Check for existence of ENV
|
|
|
|
ENV_FILE=$(abspath $(ENV)) docker-compose -f docker/compose/docker-compose.yml -f docker/compose/docker-compose-user-env.yml -p $(NAME) up -d
|
|
|
|
else
|
|
|
|
@echo $(ENV) not found.
|
|
|
|
endif
|
2019-01-28 21:45:19 +03:00
|
|
|
|
2019-03-25 18:05:12 +03:00
|
|
|
.PHONY: test
|
2018-10-30 23:40:13 +03:00
|
|
|
test: build-tests run-tests
|
2019-03-25 18:05:12 +03:00
|
|
|
|
|
|
|
.PHONY: tests
|
2018-10-30 23:40:13 +03:00
|
|
|
tests: build-tests run-tests ## Run all tests (getting/building images as needed)
|
2019-03-25 18:05:12 +03:00
|
|
|
|
|
|
|
.PHONY: run-tests-resources-external
|
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
|
2019-03-25 18:05:12 +03:00
|
|
|
|
|
|
|
.PHONY: run-tests-resources
|
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
|
2019-03-25 18:05:12 +03:00
|
|
|
|
|
|
|
.PHONY: run-test
|
|
|
|
run-test: run-tests
|
|
|
|
|
|
|
|
.PHONY: run-test
|
2018-11-15 00:20:21 +03:00
|
|
|
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)"
|
2019-03-25 18:05:12 +03:00
|
|
|
|
|
|
|
.PHONY: rebuild-run-tests
|
2018-11-27 22:53:55 +03:00
|
|
|
rebuild-run-tests: build-tests run-tests
|
|
|
|
|
2019-03-23 00:31:56 +03:00
|
|
|
.PHONY: build
|
|
|
|
build: build-from-cwd
|
|
|
|
|
2019-03-20 21:07:09 +03:00
|
|
|
.PHONY: build-from-cwd
|
2019-03-19 01:56:56 +03:00
|
|
|
build-from-cwd: ## Build local MozDef images (use make NO_CACHE=--no-cache build to disable caching)
|
2019-05-10 21:49:22 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose.yml -p $(NAME) $(NO_CACHE) $(BUILD_MODE) --parallel
|
2018-10-17 00:56:09 +03:00
|
|
|
|
2019-03-20 21:07:09 +03:00
|
|
|
.PHONY: build-from-github
|
2019-03-19 02:10:57 +03:00
|
|
|
build-from-github: ## Build local MozDef images from the github branch (use make NO_CACHE=--no-cache build to disable caching).
|
2019-03-19 01:56:56 +03:00
|
|
|
@echo "Performing a build from the github branch using $(TMPDIR) for BRANCH=$(BRANCH)"
|
|
|
|
cd $(TMPDIR) && git clone https://github.com/mozilla/MozDef.git && cd MozDef && git checkout $(BRANCH) && make build-from-cwd
|
|
|
|
rm -rf $(TMPDIR)
|
|
|
|
|
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
|
|
|
|
2019-03-25 18:05:12 +03:00
|
|
|
.PHONY: stop
|
2018-10-16 01:39:22 +03:00
|
|
|
stop: down
|
2019-03-25 18:05:12 +03:00
|
|
|
|
|
|
|
.PHONY: 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
|
|
|
|
2019-03-25 18:05:12 +03:00
|
|
|
.PHONY: docker-push
|
2018-10-17 00:10:49 +03:00
|
|
|
docker-push: hub
|
2019-03-25 18:05:12 +03:00
|
|
|
|
|
|
|
.PHONY: 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
|
|
|
|
2019-03-20 21:28:35 +03:00
|
|
|
.PHONY: tag-images
|
|
|
|
tag-images:
|
2019-03-30 01:41:00 +03:00
|
|
|
cloudy_mozdef/ci/docker_tag_or_push tag $(BRANCH)
|
2019-03-20 21:28:35 +03:00
|
|
|
|
2019-03-25 18:05:12 +03:00
|
|
|
.PHONY: docker-push-tagged
|
2019-03-20 21:28:35 +03:00
|
|
|
docker-push-tagged: tag-images hub-tagged
|
2019-03-25 18:05:12 +03:00
|
|
|
|
|
|
|
.PHONY: hub-tagged
|
2019-03-19 02:10:57 +03:00
|
|
|
hub-tagged: ## Upload locally built MozDef images tagged as the BRANCH. Branch and tagged release are interchangeable here.
|
2019-03-30 01:41:00 +03:00
|
|
|
cloudy_mozdef/ci/docker_tag_or_push push $(BRANCH)
|
2019-03-19 01:56:56 +03:00
|
|
|
|
2019-03-25 18:05:12 +03:00
|
|
|
.PHONY: docker-get
|
2018-10-17 02:35:00 +03:00
|
|
|
docker-get: hub-get
|
2019-03-25 18:05:12 +03:00
|
|
|
|
|
|
|
.PHONY: 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
|
|
|
|
2019-03-25 18:05:12 +03:00
|
|
|
.PHONY: docker-login
|
2019-03-19 19:56:36 +03:00
|
|
|
docker-login: hub-login
|
2019-03-25 18:05:12 +03:00
|
|
|
|
|
|
|
.PHONY: hub-login
|
2019-03-19 19:56:36 +03:00
|
|
|
hub-login: ## Login as the MozDef CI user in order to perform a release of the containers.
|
|
|
|
@docker login -u mozdefci --password $(shell aws ssm get-parameter --name '/mozdef/ci/dockerhubpassword' --with-decrypt | jq .Parameter.Value)
|
|
|
|
|
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
|
2019-03-19 01:56:56 +03:00
|
|
|
|
2018-10-16 00:37:10 +03:00
|
|
|
# Shorthands
|
2018-10-16 01:39:22 +03:00
|
|
|
.PHONY: rebuild
|
2019-03-25 18:05:12 +03:00
|
|
|
rebuild: clean build-from-cwd
|
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
|