---

- name: Prepare web admin application
  hosts: localhost
  connection: local
  vars_files:
    - config.build.yaml
    - config.defaults.yaml
    - ../config.yaml

  tasks:
    - name: Prepare Python 3
      import_tasks: tasks_python.yaml

    - name: Get builder image for web-admin
      docker_image:
        name: "{{ node_gulp_builder_image_publisher }}/{{ node_gulp_builder_image_name }}:{{ node_gulp_builder_image_tag }}"
        source: pull

    - name: Start build web-admin
      docker_container:
        image: "{{ node_gulp_builder_image_publisher }}/{{ node_gulp_builder_image_name }}:{{ node_gulp_builder_image_tag }}"
        name: "{{ node_gulp_builder_image_name }}-container"
        state: started
        volumes:
          - ../web-admin:/app

    - name: Waiting until web-admin is ready
      wait_for:
        path: ../web-admin/dist/js/app.min.js
        state: present
        delay: 5

    - name: Remove builder
      docker_container:
        name: "{{ node_gulp_builder_image_name }}-container"
        state: absent

    - name: Release web-admin assets
      copy: src={{ item.src }} dest={{ item.dest }}
      with_items:
        - { src: '../web-admin/dist', dest: './dist/web-admin/' }
        - { src: '../web-admin/static', dest: './dist/web-admin/' }
        - { src: '../web-admin/index.html', dest: './dist/web-admin/' }
