Some notes for setting up a ci/cd with nexus, sonarq and jenkins.
Jenkins enables developers around the world to reliably build, test, and deploy their software.
SonarQube catches bugs and vulnerabilities in your app, with thousands of automated Static Code Analysis rules.
Nexus manages binaries and builds artifacts across your software supply chain.
- Official docker image
sonatype/nexus3:latest
- Create a new project for nexus-service
oc new-project nexus-service --display-name "nexus service"
- Deploy nexus container image
oc new-app sonatype/nexus3:latest --name=nexus-service --as-deployment-config=true
- Expose nexus service
oc expose svc nexus-service
oc rollout pause dc nexus-service
- Set enough resources to your nexus-service (memory, volume and cpu)
oc set resources dc nexus-service --requests=memory=1Gi,cpu=1
- Create a PVC for nexus-service
oc set volume dc/nexus-service --add --overwrite --name=nexus-service-volume --mount-path=/nexus-data/ --type persistentVolumeClaim --claim-name=nexus-service-pvc --claim-size=5Gi
- Rollout deployment
oc rollout resume dc nexus-service
- Fetch admin password from
/nexus-data/admin.password
and use it to access and configure your Nexus service.
- Create a new project for sonarqube
oc new-project sonarqube-service --display-name "sonarqube service"
- Deploy a persitent postgresql database using the template
postgresql-persistent
oc new-app --template=postgresql-persistent --param POSTGRESQL_USER=sonar --param POSTGRESQL_PASSOWRD=sonar --param POSTGRESQL_DATABASE=sonar --param VOLUME_CAPACITY=4Gi --labels=app=sonar-database --as-deployment-config=true
- Deploy SonarQube using
sonarqube:lts
from dockerhub
oc new-app --docker-image=sonarqube:lts --env=SONARQUBE_JDBC_USERNAME=sonar --env=SONARQUBE_JDBC_PASSWORD=sonar --env=SONARQUBE_JDBC_URL=jdbc:postgresql://postgresql/sonar --as-deployment-config=true
oc rollout pause dc sonarqube
- Expose SonarQube by creating a route for it
oc expose service sonarqube-service
- Set enough resources to your sonarqube-service (memory, volume and cpu)
oc set resources dc sonarqube-service --requests=memory=1Gi,cpu=1
- Create a PVC
oc set volume dc/sonarqube-service --add --overwrite --name=sonarqube-service-volume --mount-path=/opt/sonarqube/data/ --type persistentVolumeClaim --claim-name=sonarqube-service-pvc --claim-size=3Gi
- Rollout deployment
oc rollout resume dc sonarqube-service
- Create new jenkins-service project
oc new-project jenkins-service --display-name "Jenkins Service"
- Create new application from the template
jenkins-persistent
with pvc
oc new-app --template=jenkins-persistent --VOLUME_CAPACITY=2Gi --as-deployment-config=true
oc rollout pause dc jenkins-service
- Set enough resources to your sonarqube-service (memory, volume and cpu)
oc set resources dc jenkins-service --requests=memory=1Gi,cpu=1
- Rollout deployment
oc rollout resume dc jenkins-service
- Persistent Volume Claim is a request object for creating Storage on OpenShift.
apiVersion: "v1"
kind: "Pod"
metadata:
name: "mypod"
labels:
name: "frontendhttp"
spec:
containers:
-
name: "myfrontend"
image: "nginx"
ports:
-
containerPort: 80
name: "http-server"
volumeMounts:
-
mountPath: "/var/www/html"
name: "pvol"
volumes:
-
name: "pvol"
persistentVolumeClaim:
claimName: "claim1"
- https://docs.openshift.com/enterprise/3.1/dev_guide/persistent_volumes.html
- https://docs.openshift.com/container-platform/4.1/openshift_images/using_images/images-other-jenkins-agent.html#images-other-jenkins-agent-pod-retention_images-other-jenkins-agent
- https://github.com/openshift/origin/blob/master/examples/jenkins/jenkins-persistent-template.json
- https://github.com/openshift
- https://github.com/openshift/openshift-docs
- https://www.openshift.com/blog/deploy-jenkins-pipelines-in-openshift-4-with-openshift-container-storage-4
- https://github.com/openshift/origin/blob/master/examples/jenkins/README.md