iac/Makefile

111 lines
2.4 KiB
Makefile

# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
define ping
. ./venv/bin/activate && \
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/ping.yml
endef
define configure_base
. ./venv/bin/activate && \
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/playbook.yml
endef
define configure_locust
. ./venv/bin/activate && \
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/locust.yml
endef
define configure_cache
. ./venv/bin/activate && \
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/cache.yml
endef
define test_base
. ./venv/bin/activate && \
cd tests/ && \
pwd && \
py.test --hosts='ansible://all' \
-n 10 \
--verbose \
--ansible-inventory="../${INVENTORY}" \
test_basic.py
endef
define test_cache
. ./venv/bin/activate && \
cd tests/cache/ && \
ANSIBLE_REMOTE_USER=root \
py.test --hosts='ansible://mcaptcha_hosts' \
-n 10 \
--verbose \
--ansible-inventory="../../${INVENTORY}" \
base.py
endef
define test_locust
. ./venv/bin/activate && \
cd tests/locust/ && \
py.test --hosts='ansible://mcaptcha_dos*' \
-n 10 \
--verbose \
--ansible-inventory="../../${INVENTORY}" \
base.py
endef
# ```bash
# INVENTORY=./terraform/dos/hosts.ini make conf.base
# ```
#conf.base: ## Get all VMs to base level configuration
# $(call configure_base)
#
lint: ## Lint source code
terraform fmt
. ./venv/bin/activate && \
ansible-lint --write $(find ansible -type f)
. ./venv/bin/activate && black tests/
# ```bash
# INVENTORY=./terraform/dos/hosts.ini make conf.base
# ```
conf.dos: ## Configure all DoS VMs
$(call configure_locust)
# ```bash
# INVENTORY=./terraform/dos/hosts.ini make conf.cache
# ```
conf.cache: ## Configure all cache VMs
$(call configure_cache)
# ```bash
# INVENTORY=./terraform/dos/hosts.ini make conf.ping
# ```
conf.ping: ## Ping all DoS VMs
$(call ping)
test: ## Run all tests
$(call test_base)
$(call test_locust)
test.base: ## Test base configuration on all VMs
$(call test_base)
test.cache: ## Test cache configuration
$(call test_cache)
help: ## Prints help for targets with comments
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-].+:.*?## .*$$' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'