diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..8c323b55 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,28 @@ +pipeline { + agent any + + stages{ + stage("one"){ + steps{ + echo 'step 1' + } + } + stage("two"){ + steps{ + echo 'step 2' + } + } + stage("three"){ + steps{ + echo 'step 3' + } + } + } + post{ + + always{ + + echo 'This pipeline is completed.' + } + } +} diff --git a/gists/Continuous-Deploy-Stage-Jenkinsfile b/gists/Continuous-Deploy-Stage-Jenkinsfile new file mode 100644 index 00000000..2c6843cc --- /dev/null +++ b/gists/Continuous-Deploy-Stage-Jenkinsfile @@ -0,0 +1,12 @@ +stage('Trigger deployment') { + agent any + environment{ + def GIT_COMMIT = "${env.GIT_COMMIT}" + } + steps{ + echo "${GIT_COMMIT}" + echo "triggering deployment" + // passing variables to job deployment run by vote-deploy repository Jenkinsfile + build job: 'deployment', parameters: [string(name: 'DOCKERTAG', value: GIT_COMMIT)] + } + } diff --git a/gists/LFS261ArgoDeployJenkinsfile b/gists/LFS261ArgoDeployJenkinsfile new file mode 100644 index 00000000..e1971307 --- /dev/null +++ b/gists/LFS261ArgoDeployJenkinsfile @@ -0,0 +1,26 @@ +node { + def app + + stage('Clone repository') { + + + checkout scm + } + + stage('Update GIT') { + script { + catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { + withCredentials([usernamePassword(credentialsId: 'JenkinsGithubCreds', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { + sh "git config user.email yourGitHubEmail@email.com" + sh "git config user.name yourGitHubUsername" + sh "cat vote-ui-deployment.yaml" + sh "sed -i 's+dockerHubUserName/vote.*+dockerHubUsername/vote:${DOCKERTAG}+g' vote-ui-deployment.yaml" + sh "cat vote-ui-deployment.yaml" + sh "git add ." + sh "git commit -m 'Done by Jenkins Job deployment: ${env.BUILD_NUMBER}'" + sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${GIT_USERNAME}/vote-deploy.git HEAD:master" + } + } + } +} +} diff --git a/gists/lab-8-docker-compose-yaml b/gists/lab-8-docker-compose-yaml index 392ebcac..e47bb38f 100644 --- a/gists/lab-8-docker-compose-yaml +++ b/gists/lab-8-docker-compose-yaml @@ -35,8 +35,7 @@ services: image: docker:dind ports: - 2376:2376 - - 5000:5000 - - 5001:5001 + environment: - DOCKER_TLS_CERTDIR=/certs networks: diff --git a/gists/lab5.1_worker_jenkinsfile_slack_integration b/gists/lab5.1_worker_jenkinsfile_slack_integration new file mode 100644 index 00000000..4e2ab904 --- /dev/null +++ b/gists/lab5.1_worker_jenkinsfile_slack_integration @@ -0,0 +1,52 @@ +pipeline { + agent any + tools{ + maven 'maven 3.9.8' + } + stages{ + stage(build){ + when{ + changeset "**/worker/**" + } + steps{ + echo 'Compiling worker app..' + dir('worker'){ + sh 'mvn compile' + } + } + } + stage(test){ + when{ + changeset "**/worker/**" + } + steps{ + echo 'Running Unit Tests on worker app..' + dir('worker'){ + sh 'mvn clean test' + } + } + } + stage(package){ + when{ + branch 'master' + changeset "**/worker/**" + } + steps{ + echo 'Packaging worker app' + dir('worker'){ + sh 'mvn package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true } + } + } + } + post{ + always{ + echo 'Building multibranch pipeline for worker is completed..' + } + failure{ + slackSend (channel: "instavote-cd", message: "Build Failed - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)") } + success{ + slackSend (channel: "instavote-cd", message: "Build Succeeded - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)") + } + } +} diff --git a/gists/lab7_per_stage_jenkinsfile b/gists/lab7_per_stage_jenkinsfile new file mode 100644 index 00000000..dc5d77af --- /dev/null +++ b/gists/lab7_per_stage_jenkinsfile @@ -0,0 +1,89 @@ +pipeline { + + agent none + + stages{ + stage("build"){ + when{ + changeset "**/worker/**" + } + + agent{ + docker{ + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } + } + + steps{ + echo 'Compiling worker app..' + dir('worker'){ + sh 'mvn compile' + } + } + } + stage("test"){ + when{ + changeset "**/worker/**" + } + agent{ + docker{ + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } + } + steps{ + echo 'Running Unit Tets on worker app..' + dir('worker'){ + sh 'mvn clean test' + } + + } + } + stage("package"){ + when{ + branch 'master' + changeset "**/worker/**" + } + agent{ + docker{ + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } + } + steps{ + echo 'Packaging worker app' + dir('worker'){ + sh 'mvn package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + } + + } + } + + stage('docker-package'){ + agent any + when{ + changeset "**/worker/**" + branch 'master' + } + steps{ + echo 'Packaging worker app with docker' + script{ + docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { + def workerImage = docker.build("xxxxx/worker:v${env.BUILD_ID}", "./worker") + workerImage.push() + workerImage.push("${env.BRANCH_NAME}") + workerImage.push("latest") + } + } + } + } + } + + post{ + always{ + echo 'Building multibranch pipeline for worker is completed..' + } + } +} diff --git a/gists/lab8_DockerComposespecwithBackingServices b/gists/lab8_DockerComposespecwithBackingServices new file mode 100644 index 00000000..e38fd3d9 --- /dev/null +++ b/gists/lab8_DockerComposespecwithBackingServices @@ -0,0 +1,19 @@ +services: + vote: + image: xxxxx/vote:latest + ports: + - 5000:80 + + redis: + image: redis:alpine + + db: + image: postgres:9.4 + + result: + image: xxxxx/result:latest + ports: + - 5001:4000 + + worker: + image: xxxxx/worker:latest diff --git a/gists/lab8_first_docker_compose_yaml b/gists/lab8_first_docker_compose_yaml new file mode 100644 index 00000000..61582e5b --- /dev/null +++ b/gists/lab8_first_docker_compose_yaml @@ -0,0 +1,13 @@ +services: + vote: + image: xxxxx/vote:latest + ports: + - 5000:80 + + result: + image: xxxxx/result:latest + ports: + - 5001:80 + + worker: + image: xxxxx/worker:latest diff --git a/gists/lab9-sonarqube-stage-snippet b/gists/lab9-sonarqube-stage-snippet new file mode 100644 index 00000000..f82997bd --- /dev/null +++ b/gists/lab9-sonarqube-stage-snippet @@ -0,0 +1,31 @@ + stage('Sonarqube') { + agent any + when{ + branch 'master' + } + // tools { + // jdk "JDK11" // the name you have given the JDK installation in Global Tool Configuration + // } + + environment{ + sonarpath = tool 'SonarScanner' + } + + steps { + echo 'Running Sonarqube Analysis..' + withSonarQubeEnv('sonar-instavote') { + sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=sonar-project.properties -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=86400" + } + } + } + + + stage("Quality Gate") { + steps { + timeout(time: 1, unit: 'HOURS') { + // Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails + // true = set pipeline to UNSTABLE, false = don't + waitForQualityGate abortPipeline: true + } + } + } diff --git a/result/Dockerfile b/gists/result-dockerfile similarity index 95% rename from result/Dockerfile rename to gists/result-dockerfile index 4fb74e8c..b688d7be 100644 --- a/result/Dockerfile +++ b/gists/result-dockerfile @@ -1,4 +1,4 @@ -FROM node:18-slim +FROM node:22.4.0-slim # add curl for healthcheck RUN apt-get update && \ diff --git a/vote/Dockerfile b/gists/vote-dockerfile similarity index 100% rename from vote/Dockerfile rename to gists/vote-dockerfile diff --git a/gists/vote-ui-deployment.yaml b/gists/vote-ui-deployment.yaml new file mode 100644 index 00000000..cfb2557d --- /dev/null +++ b/gists/vote-ui-deployment.yaml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vote-ui +spec: + replicas: 1 + revisionHistoryLimit: 3 + selector: + matchLabels: + app: vote-ui + template: + metadata: + labels: + app: vote-ui + spec: + containers: + - image: docker.io/xxxx/vote + name: vote-ui + ports: + - containerPort: 80 diff --git a/gists/vote-ui-svc.yaml b/gists/vote-ui-svc.yaml new file mode 100644 index 00000000..7b13888e --- /dev/null +++ b/gists/vote-ui-svc.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: vote-ui +spec: + type: NodePort + ports: + - port: 80 + targetPort: 80 + protocol: TCP + name: http + selector: + app: vote-ui diff --git a/gists/worker-dockerfile b/gists/worker-dockerfile new file mode 100644 index 00000000..bb6e0f79 --- /dev/null +++ b/gists/worker-dockerfile @@ -0,0 +1,6 @@ +FROM maven:3.9.8-sapmachine-21 +WORKDIR /app +COPY . . +RUN mvn package && \ + mv target/worker-jar-with-dependencies.jar /run/worker.jar && rm -rf /app/* +CMD ["java", "-jar", "/run/worker.jar"] diff --git a/worker/Dockerfile b/worker/Dockerfile deleted file mode 100644 index 2b152eab..00000000 --- a/worker/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM maven:3.9.8-sapmachine-21 -WORKDIR /app -COPY . . -RUN mvn package && \ - mv target/worker-jar-with-dependencies.jar /run/worker.jar &&\ - rm -rf /app/* - CMD ["java", "-jar", "/run/worker.jar"]