# Steps are the ansible adaptation of the official Docker guide for installation:
# https://docs.docker.com/engine/install/ubuntu/
#
# NOTE: This requires the Docker repo to be added in 'apt-sources' role to run

- block:

  - name: Install Docker packages
    apt:
      name:
        - "docker-ce"
        - "docker-ce-cli"
        - "containerd.io"
      cache_valid_time: "{{ apt_cache_valid_time }}"

  - name: Add zoox user to the Docker group
    user:
      name: zoox
      groups: docker
      append: yes

  # This is usually initialized by Docker, but we need to create it in order to
  # copy in the preferences file in the next step
  - name: Create Docker preferences directory
    file:
      path: "/etc/docker/"
      state: directory
      owner: root
      group: root

  # This settings file will make Docker use our custom docker partition, which is
  # not an overlay partition
  - name: Setup Docker mount point
    copy:
      src: daemon.json
      dest: /etc/docker/daemon.json
      owner: root
      group: root
      mode: '644'

  - name: Enable Docker and Containerd service
    zoox_systemctl:
      name: "{{ item }}"
      enabled: yes
      live: "{{ is_live_update }}"
    with_items:
      - docker.socket
      - docker.service
      - containerd.service

  become: yes
