- name: create temporary build directory
  shell: mktemp -d
  register: tempdir

- name: copy the Dockerfile
  template: src=Dockerfile dest="{{ tempdir.stdout }}/"

- name: copy the logback configuration
  template: src=logback.xml.j2 dest="{{ tempdir.stdout }}/logback.xml"

- name: copy the startup script
  copy: src=smartgears_run.sh dest="{{ tempdir.stdout }}/" mode=0755

- name: copy the pacthed common-scope-maps jar
  copy: src=common-scope-maps-patched.jar dest="{{ tempdir.stdout }}/" mode=0755
  when: patch_common_scope != 0

- name: copy the pacthed common-authorization jar
  copy: src=common-authorization-patched.jar dest="{{ tempdir.stdout }}/" mode=0755
  when: patch_common_authorization != 0

- name: Build the docker image
  docker_image:
    path: "{{ tempdir.stdout }}"
    name: "{{ image_name }}"
    tag: "{{ image_tag }}"
    state: present
    force: yes
    rm: True
    push: "{{ push_to_repo }}"

- name: remove the temporary build directory
  file: path="{{ tempdir.stdout }}" state=absent