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 new file mode 100644 index 0000000..663fadd --- /dev/null +++ b/Jenkinsfile-kustomize.groovy @@ -0,0 +1,70 @@ +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 + - name: tools + image: argoproj/argo-cd-ci-builder:v1.0.0 + 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@github.com/devops-ws/learn-kustomize.git" + sh "git config --global user.email 'ci@ci.com'" + + 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'" + } + } + } + } + + } +}