From 7db73424b015ebc38e148cb4cb3c804177a1c77a Mon Sep 17 00:00:00 2001
From: Nick White <git@njw.name>
Date: Thu, 5 Sep 2019 09:52:44 +0100
Subject: Build go tools for pipeline on host machine

---
 roles/pipeliner/tasks/pipeline.yml | 44 ++++++++++++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 4 deletions(-)

(limited to 'roles/pipeliner')

diff --git a/roles/pipeliner/tasks/pipeline.yml b/roles/pipeliner/tasks/pipeline.yml
index f3ca30d..e39bbcc 100644
--- a/roles/pipeliner/tasks/pipeline.yml
+++ b/roles/pipeliner/tasks/pipeline.yml
@@ -1,11 +1,47 @@
 ---
 
-# TODO: check out and build from repo, and copy into the right place
-- name: Install pipeline tools
+# Needed for stretch as we need golang >= 1.9 (for x/draw dependency), and stretch
+# only has 1.8 available
+- name: Install debian backports
+  lineinfile:
+    path: /etc/apt/sources.list.d/backports.list
+    line: deb http://deb.debian.org/debian stretch-backports main
+    create: yes
+
+# This shouldn't be needed due to update_cache line in the below install rule,
+# however that doesn't seem to trigger for some reason
+- name: Update apt
+  apt:
+    update_cache: yes
+
+- name: Install golang
+  apt:
+    name: golang-go
+    state: present
+    default_release: stretch-backports
+    update_cache: yes
+
+# Do this manually rather than relying on go get so that step can
+# be skipped if nothing has been changed
+- name: Get go repo
+  git: dest=/home/{{ ansible_user }}/src/go/src/rescribe.xyz/go.git repo=https://rescribe.xyz/go.git
+  become: no
+  register: gorepo
+
+- name: Get and build bookpipeline and dependencies
+  command: go get rescribe.xyz/go.git/bookpipeline/...
+  environment:
+    GOPATH: /home/{{ ansible_user }}/src/go
+  become: no
+  when: gorepo.changed
+  register: gobuilt
+
+- name: Install bookpipeline binary
   copy:
-    src: /home/nick/rescribe/2018-natphil/src/go/src/rescribe.xyz/go.git/bookpipeline/cmd/bookpipeline/bookpipeline
+    remote_src: true
+    src: /home/{{ ansible_user }}/src/go/bin/bookpipeline
     dest: /usr/local/bin/
-    mode: 0755
+  when: gobuilt
 
 - name: Install systemd unit file
   copy: src=bookpipeline.service dest=/etc/systemd/system
-- 
cgit v1.2.1-24-ge1ad