版權說明:本文僅代表作者的個人觀點。
跑在Openshift上的車-CHE,指的是Eclipse CHE。
Eclipse Che是一個現代的、開放源代碼的軟件開發環境。它是一個通過提供結構化的工作區、項目輸入、模塊化擴展插件來支持Codenvy的引擎。Che可以用作桌面IDE,RESTful工作空間服務器,或作爲一個創建新的工具SDK。我們現在支持一個有標籤的Docker images啓動一個默認Eclipse Che。
- 源代碼從Gogs克隆、構建、測試,然後分析bug和錯誤的patterns
- WAR工件被推送到Nexus Repository
- 基於WildFly,部署Tasks應用程序WAR(tasks:latest)
- 任務容器映像部署在DEV項目中的新容器中
- 如果測試成功,則管道暫停,以便發佈經理批准向STAGE發佈
- 如果獲得批准,DEV image將在STAGE項目中標記。
- image 部署在STAGE項目中的新容器中
首先,在環境中,有三個項目:
其中CI/CD項目中是整個CI/CD工具鏈:
而 DEV project和 STAGE project分別是應用的兩個階段。
應用是一個是一個war包,運行到wildfly上。
1.登錄到Gogs上,查看源碼:
查看pom.xml
瀏覽器登錄運行在CI/CD項目中的CHE:
首先創建一個workspace:
import項目:
在源碼中加一點內容,造成源碼修改的現實:
提交代碼以後,觸發Pipeline的啓動:
我們看一下pipeline的內容:
def version, mvnCmd = "mvn -s configuration/cicd-settings-nexus3.xml"
pipeline {
agent {
label 'maven'
}
stages {
stage('Build App') {
steps {
git branch: 'eap-7', url: 'http://gogs:3000/gogs/openshift-tasks.git'
script {
def pom = readMavenPom file: 'pom.xml'
version = pom.version
}
sh "${mvnCmd} install -DskipTests=true"
}
}
stage('Test') {
steps {
sh "${mvnCmd} test"
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
}
}
stage('Code Analysis') {
steps {
script {
sh "${mvnCmd} sonar:sonar -Dsonar.host.url=http://sonarqube:9000 -DskipTests=true"
}
}
}
stage('Archive App') {
steps {
sh "${mvnCmd} deploy -DskipTests=true -P nexus3"
}
}
stage('Create Image Builder') {
when {
expression {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
return !openshift.selector("bc", "tasks").exists();
}
}
}
}
steps {
script {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
openshift.newBuild("--name=tasks", "--image-stream=jboss-eap70-openshift:1.5", "--binary=true")
}
}
}
}
}
stage('Build Image') {
steps {
sh "rm -rf oc-build && mkdir -p oc-build/deployments"
sh "cp target/openshift-tasks.war oc-build/deployments/ROOT.war"
script {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
openshift.selector("bc", "tasks").startBuild("--from-dir=oc-build", "--wait=true")
}
}
}
}
}
stage('Create DEV') {
when {
expression {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
return !openshift.selector('dc', 'tasks').exists()
}
}
}
}
steps {
script {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
def app = openshift.newApp("tasks:latest")
app.narrow("svc").expose();
openshift.set("probe dc/tasks --readiness --get-url=http://:8080/ws/demo/healthcheck --initial-delay-seconds=30 --failure-threshold=10 --period-seconds=10")
openshift.set("probe dc/tasks --liveness --get-url=http://:8080/ws/demo/healthcheck --initial-delay-seconds=180 --failure-threshold=10 --period-seconds=10")
def dc = openshift.selector("dc", "tasks")
while (dc.object().spec.replicas != dc.object().status.availableReplicas) {
sleep 10
}
openshift.set("triggers", "dc/tasks", "--manual")
}
}
}
}
}
stage('Deploy DEV') {
steps {
script {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
openshift.selector("dc", "tasks").rollout().latest();
}
}
}
}
}
stage('Promote to STAGE?') {
steps {
timeout(time:15, unit:'MINUTES') {
input message: "Promote to STAGE?", ok: "Promote"
}
script {
openshift.withCluster() {
openshift.tag("${env.DEV_PROJECT}/tasks:latest", "${env.STAGE_PROJECT}/tasks:${version}")
}
}
}
}
stage('Deploy STAGE') {
steps {
script {
openshift.withCluster() {
openshift.withProject(env.STAGE_PROJECT) {
if (openshift.selector('dc', 'tasks').exists()) {
openshift.selector('dc', 'tasks').delete()
openshift.selector('svc', 'tasks').delete()
openshift.selector('route', 'tasks').delete()
}
openshift.newApp("tasks:${version}").narrow("svc").expose()
openshift.set("probe dc/tasks --readiness --get-url=http://:8080/ws/demo/healthcheck --initial-delay-seconds=30 --failure-threshold=10 --period-seconds=10")
openshift.set("probe dc/tasks --liveness --get-url=http://:8080/ws/demo/healthcheck --initial-delay-seconds=180 --failure-threshold=10 --period-seconds=10")
}
}
}
}
}
}
}
登錄到Jenkins裏,查看進度:
登錄SonarQube,查看代碼review結果:
查看Rating爲C的代碼內容:
並給出了語法建議:
查看第二個bug代碼:
並給出了語法建議:
Nexcus中查看war:
批准部署到Stage:
Pileline走完,部署成功:
驗證部署的應用:
最後,驗證一下我在源碼中的變更:
這個對應源碼中的:
參考鏈接:
https://github.com/siamaksade/openshift-cd-demo