**Project description**
14 JAVA eureka microservices
5 Node projects
A Node project VUE generates a static page as the front end
pgsql
redis
rabbitmq
emqx
Project mind map
**Build process:**
Jenkins (pull gitlab code -- > Maven package java project / npm package node project / gradle package Android -- > check the quality of sonarqube code at the same time of packaging -- > package Docker image according to Dockerfile -- > push image to private image warehouse Harbor -- > script calls pull Harbor image deploy / service to K8S system according to Yaml file)
I. project software construction
1. K8S construction (refer to the deployment document of Alain: kubeadmin installation single master K8S cluster)
2. jenkins building
https://jenkins.io/doc/book/installing/#fedora
3. Harbor building
https://github.com/goharbor/harbor/blob/master/docs/installation_guide.md
4. Sonarqube construction
sonarqube detects java projects: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven
sonarqube detection node project: https://www.npmjs.com/package/sonarqube-scanner
II. Materials used in CICD system
1. jenkins pipeline (JAVA service)
node { def mvnHome = tool 'Maven' REGISTRY = 'hb.shubing.vip/k12soft' //environment { //REGISTRY = 'hb.shubing.vip/k12soft' //} stage('Pull Code from Gitlab.') { git branch: 'test_4', credentialsId: '1', url: 'http://10.0.0.82:9999/k12soft/bepf_web_apiGetway.git' } stage('Maven Package and Sonar.') { withMaven(jdk:'JDK'){ // def JAVA_HOME = "/usr/lib/jdk1.8.0_121" sh "'${mvnHome}/bin/mvn' clean package -e -U -Dmaven.test.skip=true sonar:sonar" //sh "'${mvnHome}/bin/mvn' -f ebase-api/pom.xml clean package sonar:sonar" } } stage('Build Docker Image.') { sh "sudo docker build -t $REGISTRY/${JOB_BASE_NAME}:${BUILD_ID} ." } stage('Push Docker Image to Harbor.') { sh "sudo docker push $REGISTRY/${JOB_BASE_NAME}:${BUILD_ID}" } stage('Deploy K8S Service.') { sh "sudo ssh 'root@10.0.0.102' 'cd /root/xtcloud && sh apply-config.sh ${BUILD_ID} ${JOB_BASE_NAME}'" dingTalk accessToken: 'https://oapi.dingtalk.com/robot/send?access_token=8241e530e0f2e68f74da6b78f893e2f526db4086a88e76de7348ddda101f13e1 ', imageUrl:', 'jenkinsUrl:', 'message:', build & K8S successfully published! ", notifyPeople: '' } }
2. jenkins pipeline (for Node service)
node { REGISTRY = 'hb.shubing.vip/k12soft' stage('Pull Code from Gitlab.') { git branch: 'zangyunji', credentialsId: '1', url: 'http://10.0.0.82:9999/k12soft/2018-12-22-node-apigateway.git' } //stage('Node Install Modules.') { // sh "source /etc/profile.d/node.sh && npm i" //} stage('Node Build and Sonar.') { sh "source /etc/profile.d/node.sh && sonar-scanner" sh "source /etc/profile.d/node.sh && npm run tsc" } stage('Build Docker Image.') { sh "sudo docker build -t $REGISTRY/${JOB_BASE_NAME}:${BUILD_ID} ." } stage('Push Docker Image to Harbor.') { sh "sudo docker push $REGISTRY/${JOB_BASE_NAME}:${BUILD_ID}" } stage('Deploy K8S Service.') { sh "sudo ssh 'root@10.0.0.102' 'cd /root/xtcloud && sh apply-config.sh ${BUILD_ID} ${JOB_BASE_NAME}'" dingTalk accessToken: 'https://oapi.dingtalk.com/robot/send?access_token=8241e530e0f2e68f74da6b78f893e2f526db4086a88e76de7348ddda101f13e1 ', imageUrl:', 'jenkinsUrl:', 'message:', build & K8S successfully published! ", notifyPeople: '' } }
3. dockerfile (JAVA service)
FROM java:8u111 MAINTAINER gongshubing@weds.com.cn #Define variables ENV WORK_DIR /opt ENV LOG_DIR /data/logs EXPOSE 8086 #copy from host to container COPY target/bepf_archives.jar $WORK_DIR WORKDIR $WORK_DIR ENTRYPOINT ["sh", "-c"] CMD ["java -server -Dspring.profiles.active=ops -Xmx512m -Xms256m -Xmn256m -XX:+UseG1GC -XX:+DisableExplicitGC -Duser.timezone=GMT+8 -jar *.jar > /dev/null" ]
4. dockerfile (for NODE service)
FROM node:10.15.3 MAINTAINER gongshubing@weds.com.cn #Define variables ENV WORK_DIR /opt ENV LOG_DIR /data/logs ENV EGG_SERVER_ENV ops EXPOSE 8086 #copy from host to container COPY ./ $WORK_DIR/ RUN sed -i 's/\-\-daemon//g' $WORK_DIR/package.json WORKDIR $WORK_DIR ENTRYPOINT ["sh", "-c"] CMD ["npm start"]
5. K8S arranges yaml file
# deployment --- apiVersion: apps/v1 kind: Deployment metadata: name: xtcloud-appgateway-deployment labels: app: xtcloud-appgateway spec: replicas: 1 selector: matchLabels: app: xtcloud-appgateway template: metadata: labels: app: xtcloud-appgateway spec: containers: - name: xtcloud-appgateway image: hb.shubing.vip/k12soft/xtcloud-appgateway:latest ports: - containerPort: 8097 volumeMounts: - name: xtcloud-logs-persistent-storage mountPath: /data/logs volumes: - name: xtcloud-logs-persistent-storage nfs: path: /nfs server: 10.0.60.67 imagePullSecrets: - name: weds-harbor-secret # service --- kind: Service apiVersion: v1 metadata: name: xtcloud-appgateway-service spec: clusterIP: 192.168.1.15 selector: app: xtcloud-appgateway ports: - protocol: TCP port: 8097 targetPort: 8097
II. Renderings