CORD-1000 Build and publish XOS images on corddev

Change-Id: I6491b43e518abb8a56aec98b5a71e8d293fc7ef9
diff --git a/roles/build-images/tasks/main.yml b/roles/build-images/tasks/main.yml
new file mode 100644
index 0000000..6563ab2
--- /dev/null
+++ b/roles/build-images/tasks/main.yml
@@ -0,0 +1,43 @@
+---
+# build-images/tasks/main.yml
+
+- name: Clean up chameleon temp directory
+  file:
+    path: "{{ cord_dir }}/orchestration/xos/containers/chameleon/tmp.chameleon"
+    state: absent
+  with_items: "{{ chameleon_dirs }}"
+
+- name: Populate chameleon temp directory
+  shell: cp -a "{{ cord_dir }}/component/chameleon" "{{ item }}"
+  with_items: "{{ chameleon_dirs }}"
+  tags:
+    - skip_ansible_lint # docker can't access files outside of build context, so we must copy
+
+# If an image was previously pulled it won't get built
+- name: Build images
+  docker_image:
+    name: "{{ item.name }}"
+    path: "{{ item.path }}"
+    tag: "{{ build_docker_tag }}"
+    dockerfile: "{{ item.dockerfile }}"
+    pull: False
+  with_items: "{{ docker_images }}"
+
+- name: Build optional images
+  docker_image:
+    name: "{{ item.name }}"
+    path: "{{ item.path }}"
+    tag: "{{ build_docker_tag }}"
+    dockerfile: "{{ item.dockerfile }}"
+    pull: False
+  with_items: "{{ docker_optional_images }}"
+  when: build_optional_images
+
+# Build extensions images
+- name: Build xos-gui-extensions docker images
+  docker_image:
+    name: "xosproject/gui-extension-{{ item.name }}"
+    path: "{{ cord_dir }}/{{ item.path }}"
+    tag: "{{ build_docker_tag }}"
+    pull: False
+  with_items: "{{ enabled_gui_extensions }}"
diff --git a/roles/publish-images/tasks/main.yml b/roles/publish-images/tasks/main.yml
new file mode 100644
index 0000000..ca22035
--- /dev/null
+++ b/roles/publish-images/tasks/main.yml
@@ -0,0 +1,45 @@
+---
+# publish-xos-docker-images/tasks/main.yml
+
+# Remove the old local images to force them to be re-pushed
+- name: Remove old local XOS images
+  docker_image:
+    name: "{{ deploy_docker_registry }}/{{ item.name }}:{{ deploy_docker_tag }}"
+    state: absent
+  with_items: "{{ docker_images | selectattr('publish') | list }}"
+
+- name: Tag and push locally built images to docker registry
+  docker_image:
+    name: "{{ item.name }}:{{ deploy_docker_tag }}"
+    repository: "{{ deploy_docker_registry }}/{{ item.name }}:{{ deploy_docker_tag }}"
+    push: True
+  with_items: "{{ docker_images | selectattr('publish') | list }}"
+
+# Remove the old local images to force them to be re-pushed
+- name: Remove old local XOS GUI extension images
+  docker_image:
+    name: "{{ deploy_docker_registry }}/xosproject/gui-extension-{{ item.name }}:{{ deploy_docker_tag }}"
+    state: absent
+  with_items: "{{ enabled_gui_extensions }}"
+
+- name: Tag and push locally built images to docker registry
+  docker_image:
+    name: "xosproject/gui-extension-{{ item.name }}:{{ deploy_docker_tag }}"
+    repository: "{{ deploy_docker_registry }}/xosproject/gui-extension-{{ item.name }}:{{ deploy_docker_tag }}"
+    push: True
+  with_items: "{{ enabled_gui_extensions }}"
+
+# Remove the old local images to force them to be re-pushed
+- name: Remove old local miscellaneous images
+  docker_image:
+    name: "{{ deploy_docker_registry }}/{{ item }}"
+    state: absent
+  with_items: "{{ misc_docker_images }}"
+
+# Just needed for onboarding, will go away
+- name: Tag and push miscellaneous images
+  docker_image:
+    name: "{{ item }}"
+    repository: "{{ deploy_docker_registry }}/{{ item }}"
+    push: True
+  with_items: "{{ misc_docker_images }}"
diff --git a/roles/pull-images/tasks/main.yml b/roles/pull-images/tasks/main.yml
new file mode 100644
index 0000000..84d1c1f
--- /dev/null
+++ b/roles/pull-images/tasks/main.yml
@@ -0,0 +1,8 @@
+---
+# pull-images/tasks/main.yml
+
+- name: Pull latest versions of images if not present
+  docker_image:
+    name: "{{ item.name }}"
+    repository: "{{ item.name }}:{{ build_docker_tag }}"
+  with_items: "{{ docker_images | selectattr('pull') | list }}"