iac/Makefile

163 lines
4.4 KiB
Makefile
Raw Normal View History

2023-08-14 09:16:20 +05:30
# 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
2023-08-17 05:06:08 +05:30
define configure_base
. ./venv/bin/activate && \
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/playbook.yml
endef
define configure_locust
. ./venv/bin/activate && \
2023-10-13 16:28:38 +05:30
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/locust.yml
2023-08-17 05:06:08 +05:30
endef
define configure_cache
. ./venv/bin/activate && \
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/cache.yml
endef
define configure_mcaptcha
. ./venv/bin/activate && \
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/mcaptcha.yml
endef
2023-08-17 05:06:08 +05:30
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_mcaptcha
. ./venv/bin/activate && \
cd tests/mcaptcha/ && \
ANSIBLE_REMOTE_USER=root \
py.test --hosts='ansible://mcaptcha_hosts' \
-n 10 \
--verbose \
--ansible-inventory="../../${INVENTORY}" \
base.py
endef
2023-08-17 05:06:08 +05:30
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
# ```
2023-10-13 16:28:38 +05:30
#conf.base: ## Get all VMs to base level configuration
# $(call configure_base)
#
2023-08-17 05:06:08 +05:30
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.mcaptcha
# ```
conf.mcaptcha: ## Configure all mcaptcha VMs
$(call configure_mcaptcha)
2023-08-14 09:16:20 +05:30
# ```bash
# INVENTORY=./terraform/dos/hosts.ini make conf.ping
# ```
conf.ping: ## Ping all DoS VMs
$(call ping)
2023-08-17 05:06:08 +05:30
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)
test.mcaptcha: ## Test mcaptcha configuration
$(call test_mcaptcha)
2023-12-11 19:30:28 +05:30
ci.init:
apt-get update
apt-get install -y ca-certificates curl gnupg tar wget libssl-dev python3-pip cython3 pipx apt-transport-https coreutils iputils-ping openssh-client libvirt-clients genisoimage
2023-12-11 19:30:28 +05:30
./scripts/ci.sh --init "$$TEST_NODE_SSH_KEY"
ssh-add /tmp/ci-ssh-id
ssh -o StrictHostKeyChecking=accept-new mcaptcha-ci@192.168.0.102 "echo f"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://packages.opentofu.org/opentofu/tofu/gpgkey | gpg --no-tty --batch --dearmor -o /etc/apt/keyrings/opentofu.gpg
chmod a+r /etc/apt/keyrings/opentofu.gpg
echo "deb [signed-by=/etc/apt/keyrings/opentofu.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main" > /etc/apt/sources.list.d/opentofu.list
echo "deb-src [signed-by=/etc/apt/keyrings/opentofu.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main" >> /etc/apt/sources.list.d/opentofu.list
apt-get update
apt-get install -y tofu
tofu -chdir=terraform/mcaptcha/ init
tofu -chdir=terraform/mcaptcha/ plan -var-file="ci.tfvars" -out="mcaptcha"
tofu -chdir=terraform/mcaptcha/ apply "mcaptcha"
pip install virtualenv && virtualenv venv
. venv/bin/activate && pip install ansible pytest-testinfra requests
. venv/bin/activate && ansible-galaxy install -r ./ansible/requirements.yml
2023-12-11 19:30:28 +05:30
ci.clean:
echo yes | tofu -chdir=terraform/mcaptcha/ destroy -var-file="ci.tfvars"
2023-12-11 19:30:28 +05:30
./scripts/ci.sh --clean
2023-08-14 09:16:20 +05:30
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}'