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 \
|
|
|
|
mozdef_mq_eventtask 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-18 00:30:36 +03:00
|
|
|
USE_DKR_IMAGES := docker/compose/docker-compose-rebuild.yml ## Pass docker/compose/docker-compose-norebuild.yml to use hub.docker.com images
|
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
|
|
|
|
GITHASH := $(shell git rev-parse --short HEAD) ## Pass `latest` to tag docker hub images as latest instead
|
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-18 00:30:36 +03:00
|
|
|
.PHONY: run run-only
|
2018-10-17 19:39:01 +03:00
|
|
|
run: build ## Run all MozDef containers
|
2018-10-18 00:30:36 +03:00
|
|
|
docker-compose -f $(USE_DKR_IMAGES) -f docker/compose/docker-compose.yml -p $(NAME) up -d
|
2018-10-17 19:39:01 +03:00
|
|
|
|
2018-10-18 00:30:36 +03:00
|
|
|
run-only:
|
|
|
|
docker-compose -f $(USE_DKR_IMAGES) -f docker/compose/docker-compose.yml -p $(NAME) up -d
|
2018-10-17 19:39:01 +03:00
|
|
|
|
|
|
|
.PHONY: run-cloudy-mozdef
|
|
|
|
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 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
|
|
|
|
2018-10-16 01:39:22 +03:00
|
|
|
# TODO? add custom test targets for individual tests (what used to be `multiple-tests` for example
|
|
|
|
# The docker files are still in docker/compose/docker*test*
|
2018-10-18 00:30:36 +03:00
|
|
|
.PHONY: test tests run-tests
|
2018-10-17 22:46:42 +03:00
|
|
|
test: build-tests run-tests ## Running tests from locally-built images
|
|
|
|
tests: build-tests run-tests
|
2018-10-17 02:41:43 +03:00
|
|
|
|
2018-10-17 22:46:42 +03:00
|
|
|
run-tests:
|
2018-10-18 00:30:36 +03:00
|
|
|
docker-compose -f $(USE_DKR_IMAGES) -f tests/docker-compose.yml -p $(NAME) up -d
|
2018-10-17 02:41:43 +03:00
|
|
|
@echo "Waiting for the instance to come up..."
|
|
|
|
sleep 10
|
|
|
|
@echo "Running flake8.."
|
2018-10-16 01:39:22 +03:00
|
|
|
docker run -it mozdef_tester bash -c "source /opt/mozdef/envs/python/bin/activate && flake8 --config .flake8 ./"
|
|
|
|
@echo "Running py.test..."
|
|
|
|
docker run -it --network=mozdef_default mozdef_tester bash -c "source /opt/mozdef/envs/python/bin/activate && py.test --delete_indexes --delete_queues tests"
|
|
|
|
|
|
|
|
.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-18 00:30:36 +03:00
|
|
|
docker-compose -f $(USE_DKR_IMAGES) -f docker/compose/docker-compose.yml -p $(NAME) $(NO_CACHE) build
|
2018-10-17 00:56:09 +03:00
|
|
|
|
|
|
|
.PHONY: build-tests nobuild-tests
|
2018-10-16 00:37:10 +03:00
|
|
|
build-tests:
|
2018-10-18 00:30:36 +03:00
|
|
|
docker-compose -f $(USE_DKR_IMAGES) -f tests/docker-compose.yml -p $(NAME) $(NO_CACHE) build
|
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-18 00:30:36 +03:00
|
|
|
docker-compose -f $(USE_DKR_IMAGES) -f docker/compose/docker-compose.yml -p $(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-17 00:56:09 +03:00
|
|
|
@echo "Tagging current docker images with git HEAD shorthash..."
|
2018-10-18 18:21:00 +03:00
|
|
|
$(foreach var,$(DKR_IMAGES),docker tag $(var) mozdef/$(var):$(GITHASH);)
|
2018-10-17 00:56:09 +03:00
|
|
|
@echo "Uploading images to docker..."
|
2018-10-17 00:10:49 +03:00
|
|
|
$(foreach var,$(DKR_IMAGES),docker push mozdef/$(var):$(GITHASH);)
|
|
|
|
|
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-17 02:35:00 +03:00
|
|
|
$(foreach var,$(DKR_IMAGES),docker pull mozdef/$(var):$(GITHASH);)
|
|
|
|
|
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-18 00:30:36 +03:00
|
|
|
-docker-compose -f $(USE_DKR_IMAGES) -f docker/compose/docker-compose.yml -p $(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
|