Merge pull request #6 from yardstick/ci-integration

Ci integration
This commit is contained in:
brmnjsh 2019-04-10 15:21:21 -04:00 committed by GitHub
commit a08ab06ab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 8 deletions

47
Jenkinsfile vendored Normal file
View File

@ -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}"
}
}
}
}

28
Makefile Normal file
View File

@ -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

8
build
View File

@ -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"