ansible-taler-exchange

Ansible playbook to deploy a production Taler Exchange
Log | Files | Refs | README | LICENSE

test.sh (2814B)


      1 #!/bin/bash
      2 set -exuo pipefail
      3 
      4 repo_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
      5 cd "$repo_dir"
      6 
      7 test_container=ansible-taler-test
      8 test_state_dir=$(mktemp -d)
      9 
     10 cleanup() {
     11 	podman rm --force "$test_container" >/dev/null 2>&1 || true
     12 	rm -rf -- "${test_state_dir:?}"
     13 }
     14 trap cleanup EXIT
     15 
     16 ssh-keygen -q -t ed25519 -N "" -f "$test_state_dir/id_ed25519"
     17 podman rm --force "$test_container" >/dev/null 2>&1 || true
     18 
     19 # Build our image
     20 podman build -f Containerfile -t "$test_container"
     21 
     22 # Run in background (-d) with systemd init. Taler's hardened systemd units
     23 # require capabilities that Podman otherwise removes from the container.
     24 podman run \
     25 	--rm \
     26 	--name "$test_container" \
     27 	-p 127.0.0.1:8022:22 \
     28 	--systemd=always \
     29 	--privileged \
     30 	-d "localhost/$test_container" sh -c "exec /usr/sbin/init --show-status"
     31 
     32 # Use a disposable key because the deployment correctly disables SSH password
     33 # authentication, and check mode runs in a separate SSH session afterwards.
     34 podman exec "$test_container" install -d -m 0700 /root/.ssh
     35 podman cp "$test_state_dir/id_ed25519.pub" "$test_container:/root/.ssh/authorized_keys"
     36 podman exec "$test_container" chmod 0600 /root/.ssh/authorized_keys
     37 
     38 # Print to log that container is running
     39 podman ps
     40 
     41 export ANSIBLE_CONFIG="$repo_dir/test-ansible.cfg"
     42 export ANSIBLE_SSH_ARGS="-o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o UserKnownHostsFile=$test_state_dir/known_hosts"
     43 
     44 for attempt in {1..30}; do
     45 	if ssh \
     46 		-i "$test_state_dir/id_ed25519" \
     47 		-p 8022 \
     48 		-o StrictHostKeyChecking=no \
     49 		-o "UserKnownHostsFile=$test_state_dir/known_hosts" \
     50 		root@127.0.0.1 true; then
     51 		break
     52 	fi
     53 	if (( attempt == 30 )); then
     54 		echo "SSH did not become ready in the test container" >&2
     55 		exit 1
     56 	fi
     57 	sleep 1
     58 done
     59 
     60 ansible_args=(
     61 	-i inventories/default
     62 	-l podman-localhost
     63 	--user root
     64 	--private-key "$test_state_dir/id_ed25519"
     65 	playbooks/setup.yml
     66 )
     67 
     68 # Provision, then prove that a separate check-mode run can inspect the result.
     69 ansible-playbook --verbose "${ansible_args[@]}"
     70 ansible-playbook --check --diff "${ansible_args[@]}"
     71 
     72 # Basic smoke checks independent of Ansible's post-deployment checks.
     73 podman exec "$test_container" systemctl is-active --quiet \
     74 	taler-exchange.target \
     75 	taler-exchange-httpd.service \
     76 	libeufin-nexus-httpd.service \
     77 	taler-auditor-httpd.service
     78 podman exec "$test_container" curl --fail --silent --show-error \
     79 	--unix-socket /var/run/taler-exchange/httpd/exchange-http.sock \
     80 	http://localhost/config >/dev/null
     81 podman exec "$test_container" curl --fail --silent --show-error \
     82 	http://127.0.0.1:8082/taler-prepared-transfer/config >/dev/null
     83 podman exec "$test_container" curl --fail --silent --show-error \
     84 	--unix-socket /var/run/taler-auditor/httpd/auditor-http.sock \
     85 	http://localhost/config >/dev/null