---
# xos-core-build/tasks/main.yml

- name: Intialize recipe list
  set_fact:
    recipes: ['/opt/cord/orchestration/xos/xos/core/core-onboard.yaml']

- name: Generate list of recipes
  set_fact:
    recipes: "{{ recipes }} + [ '/opt/cord/{{ item.path }}/xos/{{ item.name }}-{{ item.operation | default('onboard') }}.yaml']"
  with_items: "{{ xos_services }}"

- name: Generate list of libraries
  set_fact:
    recipes: "{{ recipes }} + [ '/opt/cord/orchestration/xos_libraries/{{ item }}/{{ item }}-onboard.yaml']"
  with_items: "{{ xos_libraries }}"

- name: Add in the profile library
  set_fact:
    recipes: "{{ recipes }} + [ '/opt/cord/orchestration/profiles/{{ profile_library }}/xos/{{ profile_library }}-onboard.yaml']"
  when:
    profile_library != ""

- name: Join the list of recipes
  set_fact:
    recipes_string: "{{ recipes | join(' ') }}"

- debug:
    msg: "{{ recipes }}"

- name: Create the BUILD directory
  file:
    path: "{{ build_cord_dir | realpath }}/orchestration/xos/containers/xos/BUILD"
    state: directory
    mode: 0755

# Run the corebuilder tool -- we can't do this using a docker ansible command,
# as we have to wait for the tool to complete before continuing.

- name: Run the corebuilder tool
  shell: >
    docker run
    --rm
    -v {{ build_cord_dir | realpath }}:/opt/cord
    -v {{ build_cord_dir ~ "/orchestration/xos/containers/xos/BUILD" | realpath }}:/opt/xos_corebuilder/BUILD
    xosproject/xos-corebuilder:{{ build_docker_tag }}
    {{ recipes_string }}
  tags:
   - skip_ansible_lint # running a build task

- name: Build UI image
  docker_image:
    name: "xosproject/xos-ui"
    path: "{{ build_cord_dir | realpath }}/orchestration/xos"
    tag: "{{ build_docker_tag }}"
    dockerfile: "containers/xos/Dockerfile.UI"
    pull: False
    force: True
