From 713ec1dd18ab0a491d1adf20172e90a3c02a2bb1 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Tue, 12 Dec 2023 19:45:29 +0530 Subject: [PATCH] feat: cleanup ci config and use tofu-generated hostfile in ansible --- .woodpecker.yml | 35 ++++++++++++----------------------- Makefile | 12 ++++++++++++ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 9fd0ae8..7cf44b6 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,33 +1,22 @@ steps: backend: image: python:3-bookworm + environment: + - ANSIBLE_HOST_KEY_CHECKING=False commands: - - 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 + - export PATH=$PATH:/root/.local/bin + - eval "$(ssh-agent -s)" - make ci.init - - cat /tmp/ci-ssh-id - - eval "$(ssh-agent -s)" - - 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" - - cd ../../ - - pipx install --include-deps ansible - - pipx ensurepath && echo $SHELL - - /root/.local/bin/ansible-galaxy install -r ./ansible/requirements.yml - - /root/.local/bin/ansible-playbook --become --connection=local -i localhost, --limit 127.0.0.1 ./ansible/mcaptcha.yml - - pipx install --include-deps pytest-testinfra - - cd tests/cache/ && py.test --verbose base.py - - cd tests/mcaptcha/ && py.test --verbose base.py - - echo yes | tofu destroy \ - -var-file="ci.tfvars" + - pip install virtualenv && virtualenv venv + - . venv/bin/activate && pip install ansible pytest-testinfra requests + - . venv/bin/activate && ansible-galaxy install -r ./ansible/requirements.yml + - . venv/bin/activate && ansible-playbook --become -i terraform/mcaptcha/hosts.ini ./ansible/mcaptcha.yml + - cat terraform/mcaptcha/hosts.ini + - export ANSIBLE_REMOTE_USER=root + - . venv/bin/activate && py.test --hosts="ansible://mcaptcha_hosts" --ansible-inventory=terraform/mcaptcha/hosts.ini --verbose tests/cache/base.py + - . venv/bin/activate && py.test --hosts="ansible://mcaptcha_hosts" --ansible-inventory=terraform/mcaptcha/hosts.ini --verbose tests/mcaptcha/base.py - make ci.clean secrets: [TEST_NODE_SSH_KEY] diff --git a/Makefile b/Makefile index a4f7aee..4539d40 100644 --- a/Makefile +++ b/Makefile @@ -135,9 +135,21 @@ test.mcaptcha: ## Test mcaptcha configuration $(call test_mcaptcha) 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 ./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 ci.clean: + echo yes | tofu destroy -var-file="ci.tfvars" ./scripts/ci.sh --clean help: ## Prints help for targets with comments