# Copyright (C) The Arvados Authors. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# build-docker-image.yml - Ansible playbook to build a Docker image from a
# playbook

- name: Start container(s)
  hosts: all
  gather_facts: no
  tasks:
    - name: Start container
      delegate_to: localhost
      community.docker.docker_container:
        name: "{{ inventory_hostname }}"
        image: "{{ arvados_docker_from }}"
        pull: missing
        entrypoint:
          - sleep
          - 1h

- name: Run playbook
  ansible.builtin.import_playbook: "{{ arvados_build_playbook }}"
        
- name: Commit image(s)
  hosts: all
  tasks:
    - name: Commit container
      delegate_to: localhost
      ansible.builtin.command:
        argv:
          - docker
          - container
          - commit
          - "{{ inventory_hostname }}"
          - "{{ arvados_docker_tag }}"
    - name: Remove container
      delegate_to: localhost
      community.docker.docker_container:
        state: absent
        name: "{{ inventory_hostname }}"
