---
# Creates the c3infodesk-app docker image

- name: APP | Check if the image already exists on the system
  community.docker.docker_image_info:
    name: "{{ c3infodesk_printer_docker_img_app_name }}"
  register: result_check_image

- name: APP | Check image exists answer
  ansible.builtin.debug:
    msg: "Image already exists on target"
  when: result_check_image.images | length > 0

- name: APP | Build the docker image
  ansible.builtin.command:
    cmd: docker build . -t "{{ c3infodesk_printer_docker_img_app_name }}":"{{ c3infodesk_printer_docker_img_app_tag }}" -f docker/app/Dockerfile
  args:
    chdir: "{{ c3infodesk_printer_folder }}"
  register: build_img_result
  when: result_check_image.images | length <= 0
  changed_when: build_img_result.rc != 0

- name: APP | DEBUG -> Output from creating the docker image
  ansible.builtin.debug:
    msg: "{{ build_img_result }}"
  when:
  - c3infodesk_printer_debug_create_image_app | bool
  - build_img_result is defined
