- Every component is deployed with Helm (Kubernetes)
- On every pull request, GitHub will trigger Jenkins via a webhook and Jenkins will start the SonarQube code quality checks.
- After every new release (on GitHub), Jenkins will build the new Docker images, push them to Docker Hub and upgrade the app to a new version.
- Elastic stack is used for monitoring the logs.
-
Kubernetes cluster
-
Helm v2.1x.x with tiller already deployed
-
curl (optional)
# Clone the repository
git clone https://github.com/DKSadx/demo-app.git && cd demo-app/
# Checkout v1 branch
git checkout v1
Run the install.sh
script and all the components will be installed
./install.sh
cd helm-charts/
NOTE: You can change the default chart values inside the helm-charts/CHART_NAME/values.yaml
file
Install the demo-app chart
helm install -f demo-app/values.yaml ./demo-app --name demo-app --namespace demo-app
Change the read and write permissions for docker.sock (required if using Jenkins with Docker)
chmod 666 /var/run/docker.sock
Set hosts $HOME path as an environment variable inside Jenkins slave container (required for .m2 caching)
sed -i 's@<HOST_HOME_PATH>@'"$HOME"'@' ./jenkins/values.yaml
Create ClusterRoleBinding for Jenkins (required if using kubectl or helm with Jenkins)
kubectl create clusterrolebinding permissive-binding --clusterrole=cluster-admin --user=admin --user=kubelet --group=system:serviceaccounts:jenkins
Install Jenkins chart with custom values
helm install -f jenkins/values.yaml stable/jenkins --name jenkins --namespace jenkins
Required plugin: Generic Webhook Trigger Plugin
Pull the build image:
docker pull dkabh/build:v1
Create a Jenkins pipeline and use this repository as SCM for the Jenkinsfile
Define these parameters inside the pipeline job:
Parameters | Example |
---|---|
MS_NAME | admin |
FOLDER_NAME | demo-app |
GITHUB_REPO | https://github.com/DKSadx/demo-app.git |
MICROSERVICE | admin-application |
BRANCH_NAME | v1 |
BUILD_IMAGE_NAME | build |
BUILD_IMAGE_TAG | v1 |
BUILD_CONTAINER_NAME | buildA |
DEPLOY_IMAGE_NAME | admin-deploy |
JAR_FILE | admin-application-0.0.1-SNAPSHOT |
DOCKER_HUB_USER | [username or repo] |
DOCKER_HUB_CREDENTIALS | [jenkins credentials id] |
CHART_NAME | demo-app |
CHART_PATH | ./helm-charts/demo-app |
Required plugin: GitHub Pull Request Builder
Pull the SonarQube build image:
docker pull dkabh/sq:v1
Create a freestyle job, add a new build step (execute shell) and paste the code from ./helm-charts/sonarqube/jenkinsJob
into the input field
Parameters | Example |
---|---|
FOLDER_NAME | demo-app |
BUILD_CONTAINER_NAME | buildSQ |
BUILD_IMAGE_NAME | dkabh/sq |
BUILD_IMAGE_TAG | v1 |
PROJECT_NAME | [SQ_PROJECT_NAME] |
PROJECT_URL | [SQ_URL] |
PROJECT_LOGIN | [SQ_LOGIN_TOKEN] |
1. For releases
Add a new webhook in the github repository settings and point it to the Jenkins public ip
JENKINS_PUBLIC_IP/generic-webhook-trigger/invoke?token=TOKEN_HERE
2. For pull requests
Add a new webhook in the github repository settings and point it to the Jenkins public ip
JENKINS_PUBLIC_IP/ghprbhook/
Plugins installed:
- SonarJava
- Java I18n Rules
Add SonarQube repository (stable/sonarqube is deprecated)
helm repo add oteemocharts https://oteemo.github.io/charts
Install SonarQube with custom values
helm install -f sonarqube/values.yaml oteemocharts/sonarqube --name sonarqube --namespace sonarqube
Add elastic repository:
helm repo add elastic https://helm.elastic.co
Install Elasticsearch, Filebeat and Kibana
helm install -f elasticsearch/values.yaml elastic/elasticsearch --name elasticsearch --namespace monitoring
helm install -f filebeat/values.yaml elastic/filebeat --name filebeat --namespace monitoring
helm install -f kibana/values.yaml elastic/kibana --name kibana --namespace monitoring