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
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
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'
2019-02-01 21:49:59 +03:00
i f n e q ( "$(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
e l s e
@echo $( ENV) not found.
e n d i f
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
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)
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
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
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
2019-03-19 01:56:56 +03:00
.PHONY : docker -push -tagged docker -get hub hub -get
docker-push-tagged : 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-19 01:56:56 +03:00
docker tag mozdef/mozdef_meteor:latest mozdef/mozdef_meteor:$( BRANCH) && docker push mozdef/mozdef_meteor:$( BRANCH)
docker tag mozdef/mozdef_base:latest mozdef/mozdef_base:$( BRANCH) && docker push mozdef/mozdef_base:$( BRANCH)
docker tag mozdef/mozdef_tester:latest mozdef/mozdef_tester:$( BRANCH) && docker push mozdef/mozdef_tester:$( BRANCH)
docker tag mozdef/mozdef_mq_worker:latest mozdef/mozdef_mq_worker:$( BRANCH) && docker push mozdef/mozdef_mq_worker:$( BRANCH)
docker tag mozdef/mozdef_kibana:latest mozdef/mozdef_kibana:$( BRANCH) && docker push mozdef/mozdef_kibana:$( BRANCH)
docker tag mozdef/mozdef_syslog:latest mozdef/mozdef_syslog:$( BRANCH) && docker push mozdef/mozdef_syslog:$( BRANCH)
docker tag mozdef/mozdef_cron:latest mozdef/mozdef_cron:$( BRANCH) && docker push mozdef/mozdef_cron:$( BRANCH)
docker tag mozdef/mozdef_elasticsearch:latest mozdef/mozdef_elasticsearch:$( BRANCH) && docker push mozdef/mozdef_elasticsearch:$( BRANCH)
docker tag mozdef/mozdef_loginput:latest mozdef/mozdef_loginput:$( BRANCH) && docker push mozdef/mozdef_loginput:$( BRANCH)
docker tag mozdef/mozdef_mongodb:latest mozdef/mozdef_mongodb:$( BRANCH) && docker push mozdef/mozdef_mongodb:$( BRANCH)
docker tag mozdef/mozdef_bootstrap:latest mozdef/mozdef_bootstrap:$( BRANCH) && docker push mozdef/mozdef_bootstrap:$( BRANCH)
docker tag mozdef/mozdef_alerts:latest mozdef/mozdef_alerts:$( BRANCH) && docker push mozdef/mozdef_alerts:$( BRANCH)
docker tag mozdef/mozdef_nginx:latest mozdef/mozdef_nginx:$( BRANCH) && docker push mozdef/mozdef_nginx:$( BRANCH)
docker tag mozdef/mozdef_alertplugins:latest mozdef/mozdef_alertplugins:$( BRANCH) && docker push mozdef/mozdef_alertplugins:$( BRANCH)
docker tag mozdef/mozdef_rabbitmq:latest mozdef/mozdef_rabbitmq:$( BRANCH) && docker push mozdef/mozdef_rabbitmq:$( BRANCH)
docker tag mozdef/mozdef_rest:latest mozdef/mozdef_rest:$( BRANCH) && docker push mozdef/mozdef_rest:$( BRANCH)
docker tag mozdef/mozdef_base:latest mozdef/mozdef_base:$( BRANCH) && docker push mozdef/mozdef_base:$( BRANCH)
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
2019-03-19 19:56:36 +03:00
docker-login : hub -login
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-19 01:56:56 +03:00
rebuild : clean build -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-03-20 20:34:21 +03:00
.PHONY : set -version -and -fetch -docker -container
2019-03-20 21:07:09 +03:00
set-version-and-fetch-docker-container : build -from -cwd hub -tagged # Lock the release of MozDef by pulling the docker containers on AMI build and caching replace all instances of latest in the compose override with the BRANCH
2019-03-20 20:34:30 +03:00
sed -i s/latest/$( BRANCH) /g docker/compose/docker-compose-cloudy-mozdef.yml