From d2acdf4a91eb165611f0324d7902b23a50d8e2c5 Mon Sep 17 00:00:00 2001
From: Taylor Christie <business@minesql.me>
Date: Tue, 9 Apr 2019 10:57:53 -0600
Subject: [PATCH 1/4] added jenkinsfile for CI

---
 Jenkinsfile | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 Makefile    | 28 ++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 Jenkinsfile
 create mode 100644 Makefile

diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000..8cfd137
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,47 @@
+def label = "node-${UUID.randomUUID().toString()}"
+
+podTemplate(label: label, inheritFrom: 'base', , containers: [
+  containerTemplate(name: 'base', image: 'taylorchristieyardstick/build-base:node')
+]) {
+  node(label) {
+    stage('Checkout Project') {
+      container('base') {
+          checkout scm
+      }
+    }
+    stage('Install Dependencies') {
+      container('base') {
+        sh "npm ci"
+        sh "npm install -g typescript"
+      }
+    }
+    stage('Run unit tests') {
+      container('base') {
+        sh "npm test"
+      }
+    }
+    stage('Build the Project') {
+      container('base') {
+        sh "tsc"
+      }
+    }
+    stage('Login to Dockerhub') {
+        withCredentials([usernamePassword(credentialsId: 'DockerHubAccessYardstick', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
+            container('base') {
+                sh "docker login --username ${USER} --password ${PASS}"
+            }
+        }
+    }
+    stage('Build the Docker Image') {
+      container('base') {
+        sh "make build"
+      }
+    }
+
+    stage('Push the Docker Image') {
+      container('base') {
+        sh "make push"
+      }
+    }
+  }
+}
\ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..1880968
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,28 @@
+.PHONY: help
+# from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
+help:
+	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n\n", $$1, $$2}'
+
+repo=yardstick
+project=braid
+tag=$(shell git rev-parse --short=7 HEAD)
+branch=$(shell git rev-parse --abbrev-ref HEAD)
+version=$(shell git describe --exact-match --tags $(git log -n1 --pretty='%h'))
+
+
+full: build push ## build the docker container completely
+
+
+build: ## build the production dockerfile
+	docker build -t $(repo)/$(project):$(tag) \
+		-t $(repo)/$(project):$(branch) \
+		.
+	if git describe --exact-match --tags $(shell git log -n1 --pretty='%h'); then \
+		docker tag $(repo)/$(project):$(tag) $(repo)/$(project):$(version); \
+	fi 
+push: ## push the production dockerfile
+	docker push $(repo)/$(project):$(tag)
+	docker push $(repo)/$(project):$(branch)
+	if git describe --exact-match --tags $(shell git log -n1 --pretty='%h'); then \
+		docker push $(repo)/$(project):$(version); \
+	fi
\ No newline at end of file

From ff31d98a519aa2fe0df8a82f16085dd9d49e78cc Mon Sep 17 00:00:00 2001
From: Taylor Christie <business@minesql.me>
Date: Tue, 9 Apr 2019 11:04:52 -0600
Subject: [PATCH 2/4] fixed ordering in steps, optimized npm install

---
 Jenkinsfile | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 8cfd137..0ab0ddb 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -11,20 +11,20 @@ podTemplate(label: label, inheritFrom: 'base', , containers: [
     }
     stage('Install Dependencies') {
       container('base') {
-        sh "npm ci"
+        sh "npm ci --only=production"
         sh "npm install -g typescript"
       }
     }
-    stage('Run unit tests') {
-      container('base') {
-        sh "npm test"
-      }
-    }
     stage('Build the Project') {
       container('base') {
         sh "tsc"
       }
     }
+    stage('Run unit tests') {
+      container('base') {
+        sh "npm test"
+      }
+    }
     stage('Login to Dockerhub') {
         withCredentials([usernamePassword(credentialsId: 'DockerHubAccessYardstick', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
             container('base') {
@@ -34,13 +34,13 @@ podTemplate(label: label, inheritFrom: 'base', , containers: [
     }
     stage('Build the Docker Image') {
       container('base') {
-        sh "make build"
+        sh "make build branch=${BRANCH_NAME}"
       }
     }
 
     stage('Push the Docker Image') {
       container('base') {
-        sh "make push"
+        sh "make push branch=${BRANCH_NAME}"
       }
     }
   }

From a8603a912146bbe7afa50b564c3bec25448e56d2 Mon Sep 17 00:00:00 2001
From: Taylor Christie <business@minesql.me>
Date: Tue, 9 Apr 2019 11:06:52 -0600
Subject: [PATCH 3/4] ensure types are being installed

---
 Jenkinsfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 0ab0ddb..077cc49 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -11,7 +11,7 @@ podTemplate(label: label, inheritFrom: 'base', , containers: [
     }
     stage('Install Dependencies') {
       container('base') {
-        sh "npm ci --only=production"
+        sh "npm install"
         sh "npm install -g typescript"
       }
     }

From 7da90d90fb81009c13e2603ce43dbd9544c24f32 Mon Sep 17 00:00:00 2001
From: Taylor Christie <business@minesql.me>
Date: Tue, 9 Apr 2019 11:09:20 -0600
Subject: [PATCH 4/4] remove build file stopping makefile execution

---
 build | 8 --------
 1 file changed, 8 deletions(-)
 delete mode 100755 build

diff --git a/build b/build
deleted file mode 100755
index 37a36a0..0000000
--- a/build
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env bash
-
-SHA=$(git rev-parse --short=7 HEAD)
-docker build -t yardstick/braid:$SHA .
-docker push yardstick/braid:$SHA
-
-echo "Your new docker tag: yardstick/braid:$SHA"
-