]> git.arvados.org - arvados.git/blob - tools/ansible/build-docker-image.yml
23044: Add integration test for ContainerWebServices.
[arvados.git] / tools / ansible / build-docker-image.yml
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4 #
5 # build-docker-image.yml - Build a Docker image from another playbook
6 #
7 # Typical usage looks like:
8 #
9 #   ansible-playbook -i files/development-docker-images.yml \
10 #     -e arvados_build_playbook=FILENAME.yml \
11 #     [--limit=...] build-docker-image.yml
12 #
13 # `arvados_build_playbook` is the name of the playbook that turns a base image
14 # into a new image. The inventory defines container names, base images,
15 # and built image tags.
16
17 - name: Start container(s)
18   hosts: all
19   gather_facts: no
20   tasks:
21     - name: Start container
22       delegate_to: localhost
23       community.docker.docker_container:
24         name: "{{ inventory_hostname }}"
25         state: "{{ arvados_docker_startstate|default('healthy') }}"
26         image: "{{ arvados_docker_from }}"
27         pull: "{{ arvados_docker_pull|default('missing') }}"
28         command: "{{ arvados_docker_command|default(['sleep', 'infinity']) }}"
29
30 - name: Run playbook
31   ansible.builtin.import_playbook: "{{ arvados_build_playbook }}"
32
33 - name: Commit image(s)
34   hosts: all
35   tasks:
36     - name: Commit container
37       delegate_to: localhost
38       vars:
39         argv_start:
40           - docker
41           - container
42           - commit
43           - "--author={{ arvados_docker_author|default('Arvados Package Maintainers <packaging@arvados.org>') }}"
44           - '--change=CMD ["bash"]'
45         # `map` just adds the option flag to the start of each string.
46         argv_changes: "{{ arvados_docker_changes|default([])|map('replace', '', '--change=', 1)|list }}"
47         argv_args:
48           - "{{ inventory_hostname }}"
49           - "{{ arvados_docker_tag }}"
50       ansible.builtin.command:
51         argv: "{{ argv_start + argv_changes + argv_args }}"
52
53     - name: Clean up container
54       delegate_to: localhost
55       community.docker.docker_container:
56         name: "{{ inventory_hostname }}"
57         state: "{{ arvados_docker_endstate|default('absent') }}"