---
- name: Rebuild service
  ansible.builtin.command:
    cmd: docker compose build --pull
    chdir: "{{ service_path }}"
  when:
    - docker_rebuild
  register: cmd_result
  changed_when: true

- name: Build service
  ansible.builtin.command:
    cmd: docker compose build --pull
    chdir: "{{ service_path }}"
  when:
    - "'local-dev' != inventory_hostname"
    - docker_update is defined
    - docker_update
  register: cmd_result
  changed_when: true

- name: Pull service
  ansible.builtin.command:
    cmd: docker compose pull --ignore-buildable
    chdir: "{{ service_path }}"
  when:
    - "'local-dev' != inventory_hostname"
    - docker_update is defined
    - docker_update
  register: cmd_result
  changed_when: true

- name: Start service
  ansible.builtin.command:
    cmd: docker compose up -d {{ docker_force_recreate }}
    chdir: "{{ service_path }}"
  when: "'local-dev' != inventory_hostname"
  register: cmd_result
  changed_when: cmd_result.stderr | regex_search('Started$')