From 5aebf87fc2fef8310f797cc5330245d5a84d2d56 Mon Sep 17 00:00:00 2001
From: Drew Walters <andrew.walters@att.com>
Date: Wed, 12 Feb 2020 13:00:35 -0600
Subject: [PATCH] [#33] Add image build gate

This change adds a voting job that builds the airshipctl docker image on
each patch set. The same job will be updated in a later commit to
publish the image to the quay.io/airshipit/airshipctl repository.

Related #33

Change-Id: I202da62c77ec277312518fead09f0f3ef32ccde8
Signed-off-by: Drew Walters <andrew.walters@att.com>
---
 .../airship-airshipctl-build-images.yaml      | 17 +++++++++++++++
 roles/airshipctl-build-images/tasks/main.yaml | 21 +++++++++++++++++++
 zuul.d/jobs.yaml                              | 10 +++++++++
 zuul.d/projects.yaml                          |  2 ++
 4 files changed, 50 insertions(+)
 create mode 100644 playbooks/airship-airshipctl-build-images.yaml
 create mode 100644 roles/airshipctl-build-images/tasks/main.yaml

diff --git a/playbooks/airship-airshipctl-build-images.yaml b/playbooks/airship-airshipctl-build-images.yaml
new file mode 100644
index 000000000..017e9c503
--- /dev/null
+++ b/playbooks/airship-airshipctl-build-images.yaml
@@ -0,0 +1,17 @@
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+- hosts: all
+  become: yes
+  roles:
+    - install-docker
+    - airshipctl-build-images
diff --git a/roles/airshipctl-build-images/tasks/main.yaml b/roles/airshipctl-build-images/tasks/main.yaml
new file mode 100644
index 000000000..65b5b6a73
--- /dev/null
+++ b/roles/airshipctl-build-images/tasks/main.yaml
@@ -0,0 +1,21 @@
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+- name: Buid airshipctl Image
+  make:
+    chdir: "{{ zuul.project.src_dir }}"
+    target: images
+
+- name: Verify Image Exists
+  shell: docker image inspect "$(make print-docker-image-tag)"
+  args:
+    chdir: "{{ zuul.project.src_dir }}"
diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml
index 4eafc4c62..4b2e0659c 100644
--- a/zuul.d/jobs.yaml
+++ b/zuul.d/jobs.yaml
@@ -16,6 +16,16 @@
     run: playbooks/airship-airshipctl-lint-unit.yaml
     nodeset: airship-airshipctl-single-node
 
+- job:
+    name: airship-airshipctl-build-image
+    nodeset: airship-airshipctl-single-node
+    run: playbooks/airship-airshipctl-build-images.yaml
+    roles:
+      - zuul: openstack/openstack-helm-infra
+    irrelevant-files:
+      - ^.*\.md$
+      - ^docs/.*$
+
 - job:
     name: airship-airshipctl-functional-existing-k8s
     pre-run: playbooks/airship-airshipctl-deploy-existing-k8s.yaml
diff --git a/zuul.d/projects.yaml b/zuul.d/projects.yaml
index 3d7df475e..f62ae4ba2 100644
--- a/zuul.d/projects.yaml
+++ b/zuul.d/projects.yaml
@@ -14,11 +14,13 @@
     check:
       jobs:
         - airship-airshipctl-lint-unit
+        - airship-airshipctl-build-image
         - airship-airshipctl-functional-existing-k8s
         - airship-airshipctl-gate-test
     gate:
       jobs:
         - airship-airshipctl-lint-unit
+        - airship-airshipctl-build-image
         - airship-airshipctl-functional-existing-k8s
         - airship-airshipctl-gate-test
     post: