From 0896a5468f74c76fe548b301bbb3b4619e1686c3 Mon Sep 17 00:00:00 2001 From: Zhao Xiaojie <1450685+LinuxSuRen@users.noreply.github.com> Date: Wed, 28 Apr 2021 22:25:55 +0800 Subject: [PATCH 1/5] Create Jenkinsfile-kustomize.groovy --- Jenkinsfile-kustomize.groovy | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Jenkinsfile-kustomize.groovy diff --git a/Jenkinsfile-kustomize.groovy b/Jenkinsfile-kustomize.groovy new file mode 100644 index 0000000..5e7db99 --- /dev/null +++ b/Jenkinsfile-kustomize.groovy @@ -0,0 +1,64 @@ +pipeline { + agent { + kubernetes { + label 'jenkins-agent' + defaultContainer 'jnlp' + yaml """ +apiVersion: v1 +kind: Pod +spec: + containers: + - name: dind + image: docker:18.09-dind + securityContext: + privileged: true + - name: docker + env: + - name: DOCKER_HOST + value: 127.0.0.1 + image: docker:18.09 + command: + - cat + tty: true +""" + } + } + stages { + + stage('Build') { + environment { + DOCKERHUB_CREDS = credentials('dockerhub') + } + steps { + container('docker') { + // Build new image + sh "docker build -f Dockerfile.multiStage -t devopsws/go-server:${env.GIT_COMMIT} ." + + // Publish new image + sh ''' + docker login --username $DOCKERHUB_CREDS_USR --password $DOCKERHUB_CREDS_PSW + docker push devopsws/go-server:${env.GIT_COMMIT} + ''' + } + } + } + + stage('Deploy E2E') { + environment { + GIT_CREDS = credentials('git') + } + steps { + container('tools') { + sh "git clone https://$GIT_CREDS_USR:$GIT_CREDS_PSW@gitee.com/devops-workspace/learn-kustomize.git" + sh "git config --global user.email 'ci@ci.com'" + + dir("argocd-demo-deploy") { + sh "kustomize edit set image devopsws/go-server:${env.GIT_COMMIT}" + sh "git commit -am 'Publish new version' && git push || echo 'no changes'" + } + } + } + } + + } +} From 6a98705037b8292336614f7ecf7fb83b835c94c6 Mon Sep 17 00:00:00 2001 From: Zhao Xiaojie <1450685+LinuxSuRen@users.noreply.github.com> Date: Wed, 28 Apr 2021 22:27:05 +0800 Subject: [PATCH 2/5] Update Jenkinsfile-kustomize.groovy --- Jenkinsfile-kustomize.groovy | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Jenkinsfile-kustomize.groovy b/Jenkinsfile-kustomize.groovy index 5e7db99..f72c32c 100644 --- a/Jenkinsfile-kustomize.groovy +++ b/Jenkinsfile-kustomize.groovy @@ -20,6 +20,11 @@ spec: command: - cat tty: true + - name: tools + image: argoproj/argo-cd-ci-builder:v0.13.1 + command: + - cat + tty: true """ } } From d16cd0fc90fe85cdf350ad72c74f5bda5137ba00 Mon Sep 17 00:00:00 2001 From: Zhao Xiaojie <1450685+LinuxSuRen@users.noreply.github.com> Date: Thu, 29 Apr 2021 11:39:12 +0800 Subject: [PATCH 3/5] Update Jenkinsfile-kustomize.groovy --- Jenkinsfile-kustomize.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile-kustomize.groovy b/Jenkinsfile-kustomize.groovy index f72c32c..3e43a32 100644 --- a/Jenkinsfile-kustomize.groovy +++ b/Jenkinsfile-kustomize.groovy @@ -21,7 +21,7 @@ spec: - cat tty: true - name: tools - image: argoproj/argo-cd-ci-builder:v0.13.1 + image: argoproj/argo-cd-ci-builder:v1.0.0 command: - cat tty: true From 82c6d310ea187cccb128d406cd461435d88653bc Mon Sep 17 00:00:00 2001 From: rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Thu, 29 Apr 2021 11:49:08 +0800 Subject: [PATCH 4/5] Use a specific tag of golang image --- Dockerfile.multiStage | 2 +- Jenkinsfile-kustomize.groovy | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile.multiStage b/Dockerfile.multiStage index 5414ee3..32440ba 100644 --- a/Dockerfile.multiStage +++ b/Dockerfile.multiStage @@ -1,4 +1,4 @@ -FROM golang AS builder +FROM golang:1.16.3 AS builder WORKDIR /work COPY . . diff --git a/Jenkinsfile-kustomize.groovy b/Jenkinsfile-kustomize.groovy index 3e43a32..cc45052 100644 --- a/Jenkinsfile-kustomize.groovy +++ b/Jenkinsfile-kustomize.groovy @@ -40,10 +40,10 @@ spec: sh "docker build -f Dockerfile.multiStage -t devopsws/go-server:${env.GIT_COMMIT} ." // Publish new image - sh ''' + sh """ docker login --username $DOCKERHUB_CREDS_USR --password $DOCKERHUB_CREDS_PSW docker push devopsws/go-server:${env.GIT_COMMIT} - ''' + """ } } } From 962dd6c55c9cc23e9e0d98964cd314db32de3432 Mon Sep 17 00:00:00 2001 From: rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Thu, 29 Apr 2021 14:15:42 +0800 Subject: [PATCH 5/5] Fix the wrong dir --- Jenkinsfile-kustomize.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile-kustomize.groovy b/Jenkinsfile-kustomize.groovy index cc45052..663fadd 100644 --- a/Jenkinsfile-kustomize.groovy +++ b/Jenkinsfile-kustomize.groovy @@ -54,10 +54,11 @@ spec: } steps { container('tools') { - sh "git clone https://$GIT_CREDS_USR:$GIT_CREDS_PSW@gitee.com/devops-workspace/learn-kustomize.git" + sh "git clone https://$GIT_CREDS_USR:$GIT_CREDS_PSW@github.com/devops-ws/learn-kustomize.git" sh "git config --global user.email 'ci@ci.com'" - dir("argocd-demo-deploy") { + dir("learn-kustomize") { + sh "ls -ahl" sh "kustomize edit set image devopsws/go-server:${env.GIT_COMMIT}" sh "git commit -am 'Publish new version' && git push || echo 'no changes'" }