Debian Codegraph @

ansible_collections/community/docker/tests/integration/targets/connection_docker/runme.sh

raw
1 #!/usr/bin/env bash
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 # If you use another image, you possibly also need to adjust
7 # ansible_python_interpreter in test_connection.inventory.
8 source ../setup_docker/vars/main.env
9 IMAGE="${DOCKER_TEST_IMAGE_PYTHON3}"
10
11 # Setup phase
12
13 echo "Setup"
14 ANSIBLE_ROLES_PATH=.. ansible-playbook setup.yml
15
16 # If docker wasn't installed, don't run the tests
17 if [ "$(command -v docker)" == "" ]; then
18 exit
19 fi
20
21
22 # Test phase
23
24 CONTAINER_SUFFIX=-${RANDOM}
25
26 DOCKER_CONTAINERS="docker-connection-test-container${CONTAINER_SUFFIX}"
27
28 [[ -n "$DEBUG" || -n "$ANSIBLE_DEBUG" ]] && set -x
29
30 set -euo pipefail
31
32 cleanup() {
33 echo "Cleanup"
34 docker rm -f ${DOCKER_CONTAINERS}
35 echo "Shutdown"
36 ANSIBLE_ROLES_PATH=.. ansible-playbook shutdown.yml
37 echo "Done"
38 }
39
40 trap cleanup INT TERM EXIT
41
42 echo "Start containers"
43 for CONTAINER in ${DOCKER_CONTAINERS}; do
44 if [ "${ANSIBLE_TEST_COVERAGE:-}" == "" ]; then
45 docker run --rm --name "${CONTAINER}" --detach "${IMAGE}" /bin/sh -c 'sleep 10m'
46 else
47 docker run --rm --name "${CONTAINER}" --detach -v /tmp:/tmp "${IMAGE}" /bin/sh -c 'sleep 10m'
48 docker exec "${CONTAINER}" pip3 install coverage
49 fi
50 echo "${CONTAINER}"
51 done
52
53 cat > test_connection.inventory << EOF
54 [docker]
55 docker-no-pipelining ansible_pipelining=false
56 docker-pipelining ansible_pipelining=true
57 docker-working-dir ansible_docker_working_dir=/home
58 docker-privileged ansible_docker_privileged=true
59
60 [docker:vars]
61 ansible_host=docker-connection-test-container${CONTAINER_SUFFIX}
62 ansible_connection=community.docker.docker
63 ansible_python_interpreter=/usr/local/bin/python3
64 EOF
65
66 echo "Run tests"
67 ./runme-connection.sh "$@"