Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
def APPS = []
pipeline {
// If you are running jenkins in a container use "agent { docker { image 'docker:18.09.0-git' }}"
agent {
kubernetes {
label 'docker'
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
app: jenkins-docker
spec:
containers:
- name: docker
image: docker:18.09.0-git
command:
- cat
tty: true
volumeMounts:
- mountPath: /var/run/docker.sock
name: docker-sock
volumes:
- name: docker-sock
hostPath:
path: /var/run/docker.sock
"""
}
}

environment {
GITHUB_HOOK_SECRET = "github-webhook-token-app-mono"
//DOCKERHUB = credentials('dockerhub-credentials')
DOCKERHUB_USR = ""
DOCKERHUB_PSW = ""
}

stages {
stage('configure webook') {
steps {
script {
setupWebhook()
}
}
}

stage('Find app name to build') {
steps {
script {
if (REF != "") {
VALUESFILE = sh(returnStdout: true, script:'git show --name-only --pretty=""')
LIST = VALUESFILE.split('\n')
def MAP = [:]
for(String file in LIST) {
MAP.put(file.split('/')[0], "build");
}
APPS = MAP.keySet()
echo "${APPS}"
}
}
echo "Changes in:${VALUESFILE}"
echo "application to build:${APPS}"
}
}

stage('Build and push docker image') {
steps {
container('docker') {
script {
sh 'docker login -u $DOCKERHUB_USR -p $DOCKERHUB_PSW'
for(String app in APPS) {
TO_BUILD = sh (
script: "ls ${app}/Dockerfile",
returnStatus: true
)
if (TO_BUILD == 0) {
env.APP = app
env.GIT_SHA = sh(returnStdout: true, script: "git rev-parse --short HEAD")
sh '''docker build -t infracloud/app-mono-${APP}:${GIT_SHA} ./${APP}/
docker push infracloud/app-mono-${APP}:${GIT_SHA}
docker rmi infracloud/app-mono-${APP}:${GIT_SHA}
'''
}
}
sh 'docker logout'
}
}
}
}
}
post {
cleanup {
deleteDir()
}
}
}

def setupWebhook() {
properties([
pipelineTriggers([
[$class: 'GenericTrigger',
genericVariables: [
[key: 'REF', value: '$.ref'],
],
causeString: 'Triggered on github push',
token: env.GITHUB_HOOK_SECRET,
printContributedVariables: true,
printPostContent: true,
regexpFilterText: '$REF',
regexpFilterExpression: 'refs/heads/master'
]
])
])
}
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
This sample app demonstrates the use of Shippable CI/CD with a mono repo
approach, i.e. code for all services managed within a single repository. It
features top-level folders for services grouped by language with shared
components within each language-specific folder.
# Monorepo - Kubernetes


This is a working example of using Monorepo and deploying to Kubernetes using Helm. For details check the post: http://www.infracloud.io/monorepo-ci-cd-helm-kubernetes

There are 5 repositories involved:

- [Application Source Code - this repo](https://github.com/infracloudio/app-mono)
- [Helm charts for applications](https://github.com/infracloudio/app-mono-helmcharts)
- [Helm values/state for applicatiopns](https://github.com/infracloudio/app-mono-helmstate)
- [Orchestrator job](https://github.com/infracloudio/app-mono-orchestrator)
- [Jenkins Setup for end to end example](https://github.com/infracloudio/app-mono-jenkins-setup)

For details on setup [check the repo](https://github.com/infracloudio/app-mono-jenkins-setup)
1 change: 1 addition & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# docker build -t infracloud/app-mono-api .
FROM drydock/u14nod:prod

# this folder must be created in the base images
Expand Down
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# API microservice readme.
# API microservice README.

API micro service written in Node.js..

Expand Down
1 change: 1 addition & 0 deletions www/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#docker build -t infracloud/app-mono-www .
FROM drydock/u14nod:prod

# this folder must be created in the base images
Expand Down
34 changes: 34 additions & 0 deletions www/_global/package-service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
install_node_modules() {
npm install
}

execute_tests_and_code_coverage() {
if [ -f ./Gruntfile.js ]; then
grunt --force
./node_modules/.bin/istanbul cover grunt --force --dir $SHIPPABLE_BUILD_DIR/shippable/codecoverage
./node_modules/.bin/istanbul report cobertura --dir $SHIPPABLE_BUILD_DIR/shippable/codecoverage/
fi
}

tag_and_push_image() {
ACCOUNT_NAME='679404489841.dkr.ecr.us-east-1.amazonaws.com'

echo "building image $1"
sudo docker build -t $ACCOUNT_NAME/$1:$BRANCH.$SHIPPABLE_BUILD_NUMBER .
echo "pushing image $1"
sudo docker push $ACCOUNT_NAME/$1:$BRANCH.$SHIPPABLE_BUILD_NUMBER

# We trigger the manifest and subsequently the deploy jobs downstream by posting a new version to the image resource.
# Since the image resource is an INPUT to the manifest job, the manifest job will get scheduled to run after these steps.
echo "posting the version of the image resource for $1"
shipctl put_resource_state $1"_img" "SHIPPABLE_BUILD_NUMBER" $SHIPPABLE_BUILD_NUMBER
shipctl put_resource_state $1"_img" "versionName" $BRANCH.$SHIPPABLE_BUILD_NUMBER
}

main() {
install_node_modules
execute_tests_and_code_coverage
tag_and_push_image "$@"
}

main "$@"
4 changes: 4 additions & 0 deletions www/_global/placeholder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

var placeholder = false;
var test = true;