├── Dockerfile ├── Jenkinsfile ├── README.md ├── main.js └── pipeline.png /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:10.15.3-stretch 2 | 3 | ADD main.js /app/main.js 4 | 5 | ENTRYPOINT [ "node", "/app/main.js" ] 6 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent { 3 | kubernetes { 4 | label 'jenkins-slave' 5 | defaultContainer 'jnlp' 6 | yaml """ 7 | apiVersion: v1 8 | kind: Pod 9 | spec: 10 | containers: 11 | - name: dind 12 | image: docker:18.09-dind 13 | securityContext: 14 | privileged: true 15 | - name: docker 16 | env: 17 | - name: DOCKER_HOST 18 | value: 127.0.0.1 19 | image: docker:18.09 20 | command: 21 | - cat 22 | tty: true 23 | - name: tools 24 | image: argoproj/argo-cd-ci-builder:v0.13.1 25 | command: 26 | - cat 27 | tty: true 28 | """ 29 | } 30 | } 31 | stages { 32 | 33 | stage('Build') { 34 | environment { 35 | DOCKERHUB_CREDS = credentials('dockerhub') 36 | } 37 | steps { 38 | container('docker') { 39 | // Build new image 40 | sh "until docker ps; do sleep 3; done && docker build -t alexmt/argocd-demo:${env.GIT_COMMIT} ." 41 | // Publish new image 42 | sh "docker login --username $DOCKERHUB_CREDS_USR --password $DOCKERHUB_CREDS_PSW && docker push alexmt/argocd-demo:${env.GIT_COMMIT}" 43 | } 44 | } 45 | } 46 | 47 | stage('Deploy E2E') { 48 | environment { 49 | GIT_CREDS = credentials('git') 50 | } 51 | steps { 52 | container('tools') { 53 | sh "git clone https://$GIT_CREDS_USR:$GIT_CREDS_PSW@github.com/alexmt/argocd-demo-deploy.git" 54 | sh "git config --global user.email 'ci@ci.com'" 55 | 56 | dir("argocd-demo-deploy") { 57 | sh "cd ./e2e && kustomize edit set image alexmt/argocd-demo:${env.GIT_COMMIT}" 58 | sh "git commit -am 'Publish new version' && git push || echo 'no changes'" 59 | } 60 | } 61 | } 62 | } 63 | 64 | stage('Deploy to Prod') { 65 | steps { 66 | input message:'Approve deployment?' 67 | container('tools') { 68 | dir("argocd-demo-deploy") { 69 | sh "cd ./prod && kustomize edit set image alexmt/argocd-demo:${env.GIT_COMMIT}" 70 | sh "git commit -am 'Publish new version' && git push || echo 'no changes'" 71 | } 72 | } 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Argo CD Demo 2 | 3 | Repository demonstrates an application deployment using Jenkins and Argo CD. 4 | 5 | The application deployment manifests are located in https://github.com/alexmt/argocd-demo-deploy. The 6 | application has `e2e` and `prod` environment. The deployment process is implemented using using GitOps methodology and automated using Jenkins pipeline. 7 | 8 | ![pipeline](./pipeline.png) 9 | 10 | The pipeline is responsible for building the Docker image and updating deployment repository. The deployment changes are pushed to the Kubernetes cluster by [Argo CD](https://cd.apps.argoproj.io) 11 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | const hostname = '0.0.0.0'; 4 | const port = 8080; 5 | 6 | console.log(process.env.ENVIRONMENT || 'e2e'); 7 | 8 | if (process.env.ENVIRONMENT === 'prod') { 9 | process.exit(1); 10 | } 11 | 12 | const server = http.createServer((_, res) => { 13 | res.statusCode = 200; 14 | res.setHeader('Content-Type', 'text/plain'); 15 | res.end('Hello, Jenkins World!\n'); 16 | }); 17 | 18 | 19 | server.listen(port, hostname, () => { 20 | console.log(`Server running at http://${hostname}:${port}/`); 21 | }); 22 | -------------------------------------------------------------------------------- /pipeline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexmt/argocd-demo/3824e3ce01af4947d4375c2d8fb22159d12e5c04/pipeline.png --------------------------------------------------------------------------------