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
|
2019-08-02 02:41:37 +03:00
|
|
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-04-16 22:40:15 +04:00
|
|
|
# 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
|
2019-05-19 18:42:04 +03:00
|
|
|
PARALLEL := --parallel
|
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
|
|
|
|
2019-09-24 18:40:14 +03:00
|
|
|
.PHONY: lint
|
2019-09-24 18:42:28 +03:00
|
|
|
lint: ## Run the flake8 linter over the entire codebase
|
2019-09-24 18:37:54 +03:00
|
|
|
flake8 --config .flake8 ./
|
|
|
|
|
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
|
|
|
|
|
2019-07-16 20:01:34 +03:00
|
|
|
.PHONY: run-tests
|
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-06-29 09:09:03 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose.yml -p $(NAME) $(BUILD_MODE) $(PARALLEL) $(NO_CACHE) base
|
2019-05-19 18:42:04 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose.yml -p $(NAME) $(BUILD_MODE) $(PARALLEL) $(NO_CACHE)
|
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
|
2019-06-29 09:09:03 +03:00
|
|
|
docker-compose -f docker/compose/docker-compose-tests.yml -p test-$(NAME) $(NO_CACHE) $(BUILD_MODE) base
|
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
|
2019-10-16 23:45:52 +03:00
|
|
|
|
|
|
|
.PHONY: run-docs
|
|
|
|
run-docs: stop-docs ## Start container to serve up documentation for development
|
|
|
|
docker-compose -f docker/compose/dev-docs.yml up -d
|
|
|
|
@echo "Visit http://localhost:8000 - Feel free to update source code and then refresh webpage!"
|
|
|
|
|
|
|
|
.PHONY: stop-docs
|
|
|
|
stop-docs: ## Stop the docs development container if running
|
|
|
|
-docker-compose -f docker/compose/dev-docs.yml stop
|