CI/CD is realized based on pipeline and GitOps¶
This paper introduces how to implement CI/CD based on pipeline of Workbench and GitOps function.
Overall process¶
prerequisite¶
Based on the overall process, we need to prepare the following information:
-
Prepare two code repositories on gitlab, one as a repository for business code and one as a repository for application configuration files (yaml).
-
Prepare a Harbor mirror warehouse
-
Prepare the pipeline credentials, named git-credentials, git-app-credentials, and harbor-credentials
Create pipeline¶
This example includes the following steps: pull the service code, build an image, and update the application configuration file
After the Update app profile step is successfully executed, Argo CD detects the change and triggers the update to synchronize the latest configuration file and deploy it to the cluster.
-
For details about how to create a pipeline, see crate pipeline.
-
After successful creation, select the pipeline operation: Edit Jenkinsfile
The following Jenkinsfile parameters can be updated as required
pipeline { agent { node { label 'maven' } } parameters { string(name: 'DOCKER_REPO', defaultValue: 'release-ci.daocloud.io/test-jzh/dao-2048', description: 'Image-name') string(name: 'DOCKER_IMAGE_VERSION', defaultValue: 'v2.0', description: 'Image-version') } stages { stage('git clone') { agent none steps { git(branch: 'main', credentialsId: ' git-credentials', url: '<http://172.30.40.32:9980/gitlab-instance-facdd89d/dao-2048.git>') } } stage('docker build & push') { agent none steps { container('maven') { withCredentials([usernamePassword(passwordVariable:'PASS',usernameVariable:'USER',credentialsId:'harbor-credentials')]) { sh 'docker login ${DOCKER_REPO} -u $USER -p $PASS' sh 'docker build -f Dockerfile -t ${DOCKER_REPO}:${DOCKER_IMAGE_VERSION} .' sh 'docker push ${DOCKER_REPO}:${DOCKER_IMAGE_VERSION}' } } } } stage('update config') { agent none steps { withCredentials([usernamePassword(passwordVariable:'password',usernameVariable:'username',credentialsId:'git-app-credentials')]) { sh """ git config --global user.name "root" git config --global user.email "test@gmail.com" git clone <http://${username}:${password}@172.30.40.32:9980/gitlab-instance-facdd89d/argocd-example-apps.git> cd ./argocd-example-apps sed -i "s#${DOCKER_REPO}.*#${DOCKER_REPO}:${DOCKER_IMAGE_VERSION}#g" guestbook/dao-2048.yaml git add . && git commit -m "update image" git push <http://${username}:${password}@172.30.40.32:9980/gitlab-instance-facdd89d/argocd-example-apps.git> """ } } } } }
Create continuous deployment applications¶
-
Import argocd-example-apps repository in Http mode, refer to steps.
-
Create a continuously deployed application
-
After the creation is complete, a record is generated, and the synchronization status is displayed Not synced
-
Click Synchronize to complete application deployment
Run pipeline to trigger CI/CD¶
-
Select the pipeline created above and click Run Now
-
Viewing Run Logs
-
After the pipeline runs successfully, verify that the image is uploaded to Harbor and the tag defined in Jenkinsfile is v2.0.
-
Continue to verify the continuous deployment application and find that the status is Not synced . See that Deployment resources are not synchronized and jump to Container Management to confirm the current image version.
-
Click Sync , wait until the synchronization is successful, view Deployment resources and confirm the current image version.