Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/setup_docker/README.md

raw
1 <!--
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
7 Setup Docker
8 ============
9
10 This role provides a mechanism to install docker automatically within the context of an integration test.
11
12 For the time being (Apr 2023) it has been tested in Fedora 37 and Ubuntu Jammy.
13
14 This role was largely based on the `setup_snap` one written by @felixfontein.
15
16
17 Quickstart
18 ----------
19
20 Add the file `meta/main.yml` to your integration test target it it does not yet contain one, and add (or update) the `dependencies` block with `setup_docker`, as in:
21
22 ```yaml
23 dependencies:
24 - setup_docker
25 ```
26
27 In your integration test target, add to the beginning of the `tasks/main.yml` something like (example from `mssql_script`):
28
29 ```yaml
30 - name: Start container
31 community.docker.docker_container:
32 name: mssql-test
33 image: "mcr.microsoft.com/mssql/server:2019-latest"
34 env:
35 ACCEPT_EULA: "Y"
36 SA_PASSWORD: "{{ mssql_login_password }}"
37 MSSQL_PID: Developer
38 ports:
39 - "{{ mssql_port }}:1433"
40 detach: true
41 auto_remove: true
42 memory: 2200M
43 ```
44
45 That's it! Your integration test will be using a docker container to support the test.
46
47
48 What it does
49 ------------
50
51 The role will install `docker` on the test target, allowing the test to run a container to support its execution.
52
53 The installation of the package sends a notification to an Ansible handler that will remove `docker` from the system after the integration test target is done.
54
55 This role assumes that developers will use the collection `community.docker` to manage the containers used in the test. To support that assumption, this role will install the `requests` package in the Python runtime environment used, usually a *virtualenv* used for the test. That package is **not removed** from that environment after the test.
56
57 The most common use case is to use `community.docker.docker_container` to start a container, as in the example above. It is likely that `community.docker.docker_compose` can be used as well, although this has **not been tested** yet.
58
59
60 Recommendations
61 ---------------
62
63 * Don't forget to publish the service ports when starting the container
64 * Take into consideration that the services inside the container will take a while to get started. Use both/either `ansible.builtin.wait_for` to check for the availability of the network port and/or `retries` on the first task effectively using those services
65 * As a precautionary measure, start using the role in a test that is marked either `disabled` or `unsupported`, and move forward from there.
66
67
68 Known Issues & Caveats
69 ----------------------
70
71 * Support only Ubuntu and Fedora, having been tested in Ubuntu Jammy and Fedora 37, respectively
72 * Lack mechanism to choose or constraint the `docker` version to be used
73 * Lack option to prevent `docker` from being removed at the end of the integration test