diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..077cc49 --- /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 install" + sh "npm install -g typescript" + } + } + 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') { + sh "docker login --username ${USER} --password ${PASS}" + } + } + } + stage('Build the Docker Image') { + container('base') { + sh "make build branch=${BRANCH_NAME}" + } + } + + stage('Push the Docker Image') { + container('base') { + sh "make push branch=${BRANCH_NAME}" + } + } + } +} \ 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 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" -