From 5eb4621cc2c71c89ccf5b4ec452fca48001565b5 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Mon, 23 Apr 2018 21:43:09 -0400 Subject: [PATCH 01/28] Refactor docker pipeline --- Jenkins/docker/Jenkinsfile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Jenkins/docker/Jenkinsfile b/Jenkins/docker/Jenkinsfile index a4076c7..9113ca9 100644 --- a/Jenkins/docker/Jenkinsfile +++ b/Jenkins/docker/Jenkinsfile @@ -31,8 +31,15 @@ stages { } dir('docker') { // sh 'ls -al' - sh 'docker version' + // sh 'docker version' sh "docker build --file Dockerfile_Jenkins --no-cache --tag ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG} ." + } + } + } + stage('Push Image') { + steps { + dir('docker') { + // sh 'ls -al' sh "docker push ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG}" } } From 58766e4d84eb587bfe5742d3749947b5a633b685 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Tue, 24 Apr 2018 18:19:47 -0400 Subject: [PATCH 02/28] Adding Istio install script --- Jenkins/create-gke-cluster/Jenkinsfile | 28 ++++++++++++++++++++++++++ Jenkins/install_istio.sh | 13 ++++++++++++ minikube_db_local/part2-deploy-v2.sh | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 Jenkins/create-gke-cluster/Jenkinsfile create mode 100644 Jenkins/install_istio.sh diff --git a/Jenkins/create-gke-cluster/Jenkinsfile b/Jenkins/create-gke-cluster/Jenkinsfile new file mode 100644 index 0000000..2b83d78 --- /dev/null +++ b/Jenkins/create-gke-cluster/Jenkinsfile @@ -0,0 +1,28 @@ +#!groovy + +def PROJECT_NAME = "spring-postgresql-demo" + +pipeline { + agent any + tools { + gradle 'gradle' + } + stages { + stage('Checkout GitHub') { + steps { + git changelog: true, poll: true, + branch: 'h2', + url: "https://github.com/garystafford/${PROJECT_NAME}" + } + } + stage('Create GKE Cluster') { + steps { + withCredentials([string(credentialsId: 'GIT_TOKEN', variable: 'GIT_TOKEN')]) { + dir('kubernetes/') { + sh 'sh part1-create-gke-cluster.sh' + } + } + } + } + } +} diff --git a/Jenkins/install_istio.sh b/Jenkins/install_istio.sh new file mode 100644 index 0000000..79c451f --- /dev/null +++ b/Jenkins/install_istio.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Install Istio + + +ISTIO_VERSION="0.7.1" + +# install Istio +RUN set +x \ + && curl -O "https://github.com/istio/istio/releases/download/${ISTIO_VERSION}/istio-${ISTIO_VERSION}-linux.tar.gz" \ + && unzip istio-${ISTIO_VERSION}-linux.tar.gz \ + && rm -rf istio-${ISTIO_VERSION}-linux.tar.gz \ + && mv istio-${ISTIO_VERSION} /usr/bin diff --git a/minikube_db_local/part2-deploy-v2.sh b/minikube_db_local/part2-deploy-v2.sh index 8d8bb84..6c68df5 100644 --- a/minikube_db_local/part2-deploy-v2.sh +++ b/minikube_db_local/part2-deploy-v2.sh @@ -2,6 +2,8 @@ # part 2: deploy v2 to minimkube local dev +kubectl config use-context minikube + # election v2 deployment with manual sidecar injection istioctl kube-inject –kubeconfig "~/.kube/config" \ -f ./resources/election-deployment-v2.yaml \ From 87f786043bebf99116214a65d0874953ec8cfd92 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Tue, 24 Apr 2018 19:11:35 -0400 Subject: [PATCH 03/28] Adding Istio install script --- Jenkins/create-gke-cluster/Jenkinsfile | 40 ++++++++++++-------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Jenkins/create-gke-cluster/Jenkinsfile b/Jenkins/create-gke-cluster/Jenkinsfile index 2b83d78..44aff36 100644 --- a/Jenkins/create-gke-cluster/Jenkinsfile +++ b/Jenkins/create-gke-cluster/Jenkinsfile @@ -3,26 +3,24 @@ def PROJECT_NAME = "spring-postgresql-demo" pipeline { - agent any - tools { - gradle 'gradle' - } - stages { - stage('Checkout GitHub') { - steps { - git changelog: true, poll: true, - branch: 'h2', - url: "https://github.com/garystafford/${PROJECT_NAME}" - } - } - stage('Create GKE Cluster') { - steps { - withCredentials([string(credentialsId: 'GIT_TOKEN', variable: 'GIT_TOKEN')]) { - dir('kubernetes/') { - sh 'sh part1-create-gke-cluster.sh' - } + agent any + tools { + gradle 'gradle' + } + stages { + stage('Checkout GitHub') { + steps { + git changelog: true, poll: true, + branch: 'h2', + url: "https://github.com/garystafford/${PROJECT_NAME}" + } + } + stage('Create GKE Cluster') { + steps { + dir('jenkins/') { + sh 'sh install-istio.sh' + } + } + } } - } - } - } } From 77893fd806351176affd54bebce3ae78c661366c Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Tue, 24 Apr 2018 21:12:19 -0400 Subject: [PATCH 04/28] Adding Istio install script --- Jenkins/create-gke-cluster/Jenkinsfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Jenkins/create-gke-cluster/Jenkinsfile b/Jenkins/create-gke-cluster/Jenkinsfile index 44aff36..6f72db1 100644 --- a/Jenkins/create-gke-cluster/Jenkinsfile +++ b/Jenkins/create-gke-cluster/Jenkinsfile @@ -4,9 +4,6 @@ def PROJECT_NAME = "spring-postgresql-demo" pipeline { agent any - tools { - gradle 'gradle' - } stages { stage('Checkout GitHub') { steps { @@ -18,7 +15,7 @@ pipeline { stage('Create GKE Cluster') { steps { dir('jenkins/') { - sh 'sh install-istio.sh' + sh 'sh ./install-istio.sh' } } } From 5b285ade4885f95cfda3c3675f0db42ce022f09e Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Tue, 24 Apr 2018 21:15:40 -0400 Subject: [PATCH 05/28] Adding Istio install script --- Jenkins/{install_istio.sh => install-istio.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Jenkins/{install_istio.sh => install-istio.sh} (100%) diff --git a/Jenkins/install_istio.sh b/Jenkins/install-istio.sh similarity index 100% rename from Jenkins/install_istio.sh rename to Jenkins/install-istio.sh From 7c6574c240c0e633fdc9f591ec64b99e593165a2 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 12:02:04 -0400 Subject: [PATCH 06/28] Refactor Jenkinsfile for new Jenkins instance --- .idea/modules/spring-postgresql-demo_test.iml | 1 - Jenkins/ci/Jenkinsfile | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.idea/modules/spring-postgresql-demo_test.iml b/.idea/modules/spring-postgresql-demo_test.iml index fa1e4be..5d57bb7 100644 --- a/.idea/modules/spring-postgresql-demo_test.iml +++ b/.idea/modules/spring-postgresql-demo_test.iml @@ -16,7 +16,6 @@ - diff --git a/Jenkins/ci/Jenkinsfile b/Jenkins/ci/Jenkinsfile index 8c9e06f..12b5728 100644 --- a/Jenkins/ci/Jenkinsfile +++ b/Jenkins/ci/Jenkinsfile @@ -31,7 +31,7 @@ pipeline { } stage('SonarQube Analysis') { steps { - withSonarQubeEnv('Local SonarQube') { + withSonarQubeEnv('sonarqube') { sh "./gradlew sonarqube -Dsonar.projectName=${PROJECT_NAME}" } } From e6f74da2c174cfedb594a9e1c38f3d51f7cff4c4 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 14:51:16 -0400 Subject: [PATCH 07/28] Adding gcloud to Jenkins --- Jenkins/create-gke-cluster/Jenkinsfile | 4 ++-- kubernetes/part1B-get-cluster-creds.sh | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 kubernetes/part1B-get-cluster-creds.sh diff --git a/Jenkins/create-gke-cluster/Jenkinsfile b/Jenkins/create-gke-cluster/Jenkinsfile index 6f72db1..205a5ce 100644 --- a/Jenkins/create-gke-cluster/Jenkinsfile +++ b/Jenkins/create-gke-cluster/Jenkinsfile @@ -14,8 +14,8 @@ pipeline { } stage('Create GKE Cluster') { steps { - dir('jenkins/') { - sh 'sh ./install-istio.sh' + dir('kubernetes/') { + sh 'sh ./part1B-get-cluster-creds.sh' } } } diff --git a/kubernetes/part1B-get-cluster-creds.sh b/kubernetes/part1B-get-cluster-creds.sh new file mode 100644 index 0000000..8e923bf --- /dev/null +++ b/kubernetes/part1B-get-cluster-creds.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# part 1B: get gke/istio cluster creds + +# change to match your environment +GCP_PROJECT="springdemo-199819" +GKE_CLUSTER="election-nonprod-cluster" +GCP_ZONE="us-east1-b" + +# get creds for cluster +gcloud container clusters get-credentials $GKE_CLUSTER \ + --zone $GCP_ZONE --project $GCP_PROJECT From 50a58f2741d391de486e21c7e27f540fc4eba5e3 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 21:04:27 -0400 Subject: [PATCH 08/28] Adding local Postgres instance secrets --- kubernetes/secrets/secret-postgresql-conn-info-dev.yaml | 6 +++--- kubernetes/secrets/secret-postgresql-conn-info-test.yaml | 6 +++--- kubernetes/secrets/secret-postgresql-conn-info-uat.yaml | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kubernetes/secrets/secret-postgresql-conn-info-dev.yaml b/kubernetes/secrets/secret-postgresql-conn-info-dev.yaml index c6a6406..eada282 100644 --- a/kubernetes/secrets/secret-postgresql-conn-info-dev.yaml +++ b/kubernetes/secrets/secret-postgresql-conn-info-dev.yaml @@ -8,6 +8,6 @@ metadata: namespace: dev type: Opaque data: - url: - username: - password: + url: amRiYzpwb3N0Z3Jlc3FsOi8vcG9zdGdyZXM6NTQzMi9lbGVjdGlvbnM= + username: cG9zdGdyZXM= + password: cG9zdGdyZXMxMjM0 diff --git a/kubernetes/secrets/secret-postgresql-conn-info-test.yaml b/kubernetes/secrets/secret-postgresql-conn-info-test.yaml index 41eb5d6..fc29f36 100644 --- a/kubernetes/secrets/secret-postgresql-conn-info-test.yaml +++ b/kubernetes/secrets/secret-postgresql-conn-info-test.yaml @@ -8,6 +8,6 @@ metadata: namespace: test type: Opaque data: - url: - username: - password: + url: amRiYzpwb3N0Z3Jlc3FsOi8vcG9zdGdyZXM6NTQzMi9lbGVjdGlvbnM= + username: cG9zdGdyZXM= + password: cG9zdGdyZXMxMjM0 diff --git a/kubernetes/secrets/secret-postgresql-conn-info-uat.yaml b/kubernetes/secrets/secret-postgresql-conn-info-uat.yaml index b7fb9b6..f89489b 100644 --- a/kubernetes/secrets/secret-postgresql-conn-info-uat.yaml +++ b/kubernetes/secrets/secret-postgresql-conn-info-uat.yaml @@ -8,6 +8,6 @@ metadata: namespace: uat type: Opaque data: - url: - username: - password: + url: amRiYzpwb3N0Z3Jlc3FsOi8vcG9zdGdyZXM6NTQzMi9lbGVjdGlvbnM= + username: cG9zdGdyZXM= + password: cG9zdGdyZXMxMjM0 From 7362c359b1cf578b42dce026f8562dc3e7a9e5fc Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 21:09:52 -0400 Subject: [PATCH 09/28] Adding local Postgres instance --- .../postgres-local/postgres-deployment.yaml | 35 +++++++++++++++++++ .../postgres-local/postgres-service.yaml | 14 ++++++++ 2 files changed, 49 insertions(+) create mode 100644 kubernetes/postgres-local/postgres-deployment.yaml create mode 100644 kubernetes/postgres-local/postgres-service.yaml diff --git a/kubernetes/postgres-local/postgres-deployment.yaml b/kubernetes/postgres-local/postgres-deployment.yaml new file mode 100644 index 0000000..107ea45 --- /dev/null +++ b/kubernetes/postgres-local/postgres-deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + istio-injection: enabled + app: postgres + name: postgres +spec: + selector: + matchLabels: + app: postgres + replicas: 1 + strategy: {} + template: + metadata: + labels: + istio-injection: enabled + app: postgres + spec: + containers: + - image: postgres:10.3-alpine + env: + - name: POSTGRES_DB + value: elections + - name: PGDATA + value: /var/lib/postgresql/data/pgdata + - name: POSTGRES_PASSWORD + value: postgres1234 + - name: POSTGRES_USERNAME + value: postgres + name: postgres + ports: + - containerPort: 5432 + restartPolicy: Always +status: {} diff --git a/kubernetes/postgres-local/postgres-service.yaml b/kubernetes/postgres-local/postgres-service.yaml new file mode 100644 index 0000000..e49ef68 --- /dev/null +++ b/kubernetes/postgres-local/postgres-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + istio-injection: enabled + app: postgres + name: postgres +spec: + ports: + - name: http + port: 5432 + selector: + app: postgres +status: {} From ce155cb2e546657360aed234e3770fe6915dec7c Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 21:13:33 -0400 Subject: [PATCH 10/28] Adding local Postgres instance --- kubernetes/deploy-local-postgres.sh | 10 ++++++++ kubernetes/postgres-deployment.yaml | 36 +++++++++++++++++++++++++++++ kubernetes/postgres-service.yaml | 15 ++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 kubernetes/deploy-local-postgres.sh create mode 100644 kubernetes/postgres-deployment.yaml create mode 100644 kubernetes/postgres-service.yaml diff --git a/kubernetes/deploy-local-postgres.sh b/kubernetes/deploy-local-postgres.sh new file mode 100644 index 0000000..a8eb1ac --- /dev/null +++ b/kubernetes/deploy-local-postgres.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# deploy postgres within cluster vs. external postgres (i.e. AWS) + +# set -x + +# postgresql in a pod +kubectl apply -f ./postgres-local/postgres-deployment.yaml -n dev + +kubectl apply -f ./postgres-local/postgres-service.yaml -n dev diff --git a/kubernetes/postgres-deployment.yaml b/kubernetes/postgres-deployment.yaml new file mode 100644 index 0000000..2b555cb --- /dev/null +++ b/kubernetes/postgres-deployment.yaml @@ -0,0 +1,36 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: dev + labels: + istio-injection: enabled + app: postgres + name: postgres +spec: + selector: + matchLabels: + app: postgres + replicas: 1 + strategy: {} + template: + metadata: + labels: + istio-injection: enabled + app: postgres + spec: + containers: + - image: postgres:10.3-alpine + env: + - name: POSTGRES_DB + value: elections + - name: PGDATA + value: /var/lib/postgresql/data/pgdata + - name: POSTGRES_PASSWORD + value: postgres1234 + - name: POSTGRES_USERNAME + value: postgres + name: postgres + ports: + - containerPort: 5432 + restartPolicy: Always +status: {} diff --git a/kubernetes/postgres-service.yaml b/kubernetes/postgres-service.yaml new file mode 100644 index 0000000..7131349 --- /dev/null +++ b/kubernetes/postgres-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + istio-injection: enabled + app: postgres + name: postgres + namespace: dev +spec: + ports: + - name: http + port: 5432 + selector: + app: postgres +status: {} From e6c221751ca91ea241d6831b9aef699963c61fdc Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 21:15:20 -0400 Subject: [PATCH 11/28] Adding local Postgres instance --- kubernetes/{deploy-local-postgres.sh => deploy-postgres-local.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename kubernetes/{deploy-local-postgres.sh => deploy-postgres-local.sh} (100%) diff --git a/kubernetes/deploy-local-postgres.sh b/kubernetes/deploy-postgres-local.sh similarity index 100% rename from kubernetes/deploy-local-postgres.sh rename to kubernetes/deploy-postgres-local.sh From aa41d1641896459b1b17066aa29f69cd955f4350 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 21:17:52 -0400 Subject: [PATCH 12/28] Adding local Postgres instance --- kubernetes/deploy-postgres-local.sh | 2 ++ kubernetes/part3-deploy-v1-all-envs.sh | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kubernetes/deploy-postgres-local.sh b/kubernetes/deploy-postgres-local.sh index a8eb1ac..515876c 100644 --- a/kubernetes/deploy-postgres-local.sh +++ b/kubernetes/deploy-postgres-local.sh @@ -8,3 +8,5 @@ kubectl apply -f ./postgres-local/postgres-deployment.yaml -n dev kubectl apply -f ./postgres-local/postgres-service.yaml -n dev + +kubectl get pods -dev diff --git a/kubernetes/part3-deploy-v1-all-envs.sh b/kubernetes/part3-deploy-v1-all-envs.sh index db7444a..6012589 100644 --- a/kubernetes/part3-deploy-v1-all-envs.sh +++ b/kubernetes/part3-deploy-v1-all-envs.sh @@ -36,6 +36,6 @@ kubectl apply -f ./routerules/routerule-election-v1.yaml -n test kubectl apply -f ./routerules/routerule-election-v1.yaml -n uat # kubectl describe routerule -n dev -# kubectl get pods -n dev -# kubectl get pods -n test -# kubectl get pods -n uat +kubectl get pods -n dev +kubectl get pods -n test +kubectl get pods -n uat From ea77be81ce593cc5f5e2af9e5e613a23462a3209 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 21:28:52 -0400 Subject: [PATCH 13/28] Adding local Postgres instance, refactor all Jenkinsfiles --- Jenkins/ci/Jenkinsfile | 118 ++++++++++++------------- Jenkins/create-gke-cluster/Jenkinsfile | 23 ----- Jenkins/docker/Jenkinsfile | 76 ++++++++-------- Jenkins/integration/Jenkinsfile | 56 ++++++------ Jenkins/k8s-demo-deploy/Jenkinsfile | 34 +++++++ kubernetes/deploy-postgres-local.sh | 2 +- 6 files changed, 160 insertions(+), 149 deletions(-) delete mode 100644 Jenkins/create-gke-cluster/Jenkinsfile create mode 100644 Jenkins/k8s-demo-deploy/Jenkinsfile diff --git a/Jenkins/ci/Jenkinsfile b/Jenkins/ci/Jenkinsfile index 12b5728..293a39c 100644 --- a/Jenkins/ci/Jenkinsfile +++ b/Jenkins/ci/Jenkinsfile @@ -3,67 +3,67 @@ def PROJECT_NAME = "spring-postgresql-demo" pipeline { - agent any - tools { - gradle 'gradle' - } - stages { - stage('Checkout GitHub') { - steps { - git changelog: true, poll: true, - branch: 'h2', - url: "https://github.com/garystafford/${PROJECT_NAME}" - } - } - stage('Build') { - steps { - sh 'gradle wrapper' - sh './gradlew clean build -x test' - } - } - stage('Unit Test') { - steps { - withEnv(['SPRING_DATASOURCE_URL=jdbc:h2:file:~/elections']) { - sh './gradlew cleanTest test' - } - junit '**/build/test-results/test/*.xml' - } - } - stage('SonarQube Analysis') { - steps { - withSonarQubeEnv('sonarqube') { - sh "./gradlew sonarqube -Dsonar.projectName=${PROJECT_NAME}" + agent any + tools { + gradle 'gradle' } - } - } - stage('Archive Artifact') { - steps { - archiveArtifacts 'build/libs/*.jar' - } - } - stage('Publish Artifact') { - steps { - withCredentials([string(credentialsId: 'GIT_TOKEN', variable: 'GIT_TOKEN')]) { - dir('build/libs/') { - sh "git init \ - && git config user.name \"jenkins-ci\" \ - && git config user.email \"jenkins-ci@jenkins-ci.com\" \ - && git add *.jar \ + stages { + stage('Checkout GitHub') { + steps { + git changelog: true, poll: true, + branch: 'h2', + url: "https://github.com/garystafford/${PROJECT_NAME}" + } + } + stage('Build') { + steps { + sh 'gradle wrapper' + sh './gradlew clean build -x test' + } + } + stage('Unit Test') { + steps { + withEnv(['SPRING_DATASOURCE_URL=jdbc:h2:file:~/elections']) { + sh './gradlew cleanTest test' + } + junit '**/build/test-results/test/*.xml' + } + } + stage('SonarQube Analysis') { + steps { + withSonarQubeEnv('sonarqube') { + sh "./gradlew sonarqube -Dsonar.projectName=${PROJECT_NAME}" + } + } + } + stage('Archive Artifact') { + steps { + archiveArtifacts 'build/libs/*.jar' + } + } + stage('Publish Artifact') { + steps { + withCredentials([string(credentialsId: 'GIT_TOKEN', variable: 'GIT_TOKEN')]) { + dir('build/libs/') { + sh "git init \ + && git config user.name \"jenkins-ci\" \ + && git config user.email \"jenkins-ci@jenkins-ci.com\" \ + && git add *.jar \ && git commit -m \"Publish build artifact\" \ - && git push --force --quiet --progress \ + && git push --force --quiet --progress \ \"https://x-access-token:${GIT_TOKEN}@github.com/garystafford/${PROJECT_NAME}.git\" \ - master:build-artifacts-gke" - } + master:build-artifacts-gke" + } + } + } + } + } + post { + success { + slackSend(color: '#008000', message: "SUCCESS: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + } + failure { + slackSend(color: '#FF0000', message: "FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + } } - } - } - } - post { - success { - slackSend(color: '#008000', message: "SUCCESS: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") - } - failure { - slackSend(color: '#FF0000', message: "FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") - } - } } diff --git a/Jenkins/create-gke-cluster/Jenkinsfile b/Jenkins/create-gke-cluster/Jenkinsfile deleted file mode 100644 index 205a5ce..0000000 --- a/Jenkins/create-gke-cluster/Jenkinsfile +++ /dev/null @@ -1,23 +0,0 @@ -#!groovy - -def PROJECT_NAME = "spring-postgresql-demo" - -pipeline { - agent any - stages { - stage('Checkout GitHub') { - steps { - git changelog: true, poll: true, - branch: 'h2', - url: "https://github.com/garystafford/${PROJECT_NAME}" - } - } - stage('Create GKE Cluster') { - steps { - dir('kubernetes/') { - sh 'sh ./part1B-get-cluster-creds.sh' - } - } - } - } -} diff --git a/Jenkins/docker/Jenkinsfile b/Jenkins/docker/Jenkinsfile index 9113ca9..8db469c 100644 --- a/Jenkins/docker/Jenkinsfile +++ b/Jenkins/docker/Jenkinsfile @@ -5,44 +5,44 @@ def PROJECT_NAME = "spring-postgresql-demo" // def IMAGE_TAG = "2.1.0" pipeline { - agent any - parameters { - string defaultValue: 'latest', - description: 'Tag applied to new Docker Image', - name: 'IMAGE_TAG', trim: true -} -stages { - stage('Checkout GitHub') { - steps { - git changelog: true, poll: true, - branch: 'h2', - url: "https://github.com/garystafford/${PROJECT_NAME}" - } - } - stage('Build Image') { - steps { - copyArtifacts filter: 'build/libs/*.jar', fingerprintArtifacts: true, - flatten: true, projectName: 'election-ci', selector: lastSuccessful(), - target: 'docker/' - withCredentials([usernamePassword(credentialsId: 'DOCKER_HUB', - usernameVariable: 'DOCKER_HUB_USERNAME', - passwordVariable: 'DOCKER_HUB_PASSWORD')]) { - sh "docker login --username ${DOCKER_HUB_USERNAME} --password ${DOCKER_HUB_PASSWORD}" - } - dir('docker') { - // sh 'ls -al' - // sh 'docker version' - sh "docker build --file Dockerfile_Jenkins --no-cache --tag ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG} ." + agent any + parameters { + string defaultValue: 'latest', + description: 'Tag applied to new Docker Image', + name: 'IMAGE_TAG', trim: true } - } - } - stage('Push Image') { - steps { - dir('docker') { - // sh 'ls -al' - sh "docker push ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG}" + stages { + stage('Checkout GitHub') { + steps { + git changelog: true, poll: true, + branch: 'h2', + url: "https://github.com/garystafford/${PROJECT_NAME}" + } + } + stage('Build Image') { + steps { + copyArtifacts filter: 'build/libs/*.jar', fingerprintArtifacts: true, + flatten: true, projectName: 'election-ci', selector: lastSuccessful(), + target: 'docker/' + withCredentials([usernamePassword(credentialsId: 'DOCKER_HUB', + usernameVariable: 'DOCKER_HUB_USERNAME', + passwordVariable: 'DOCKER_HUB_PASSWORD')]) { + sh "docker login --username ${DOCKER_HUB_USERNAME} --password ${DOCKER_HUB_PASSWORD}" + } + dir('docker') { + // sh 'ls -al' + // sh 'docker version' + sh "docker build --file Dockerfile_Jenkins --no-cache --tag ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG} ." + } + } + } + stage('Push Image') { + steps { + dir('docker') { + // sh 'ls -al' + sh "docker push ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG}" + } + } + } } - } - } - } } diff --git a/Jenkins/integration/Jenkinsfile b/Jenkins/integration/Jenkinsfile index 6e74b7c..e6bc92c 100644 --- a/Jenkins/integration/Jenkinsfile +++ b/Jenkins/integration/Jenkinsfile @@ -3,33 +3,33 @@ def PROJECT_NAME = "spring-postgresql-demo" pipeline { - agent any - stages { - stage('Checkout SCM') { - steps { - git changelog: true, poll: false, - url: "https://github.com/garystafford/${PROJECT_NAME}" - } - } - stage('Smoke Tests') { - steps { - dir('postman') { - nodejs('nodejs') { - sh 'sh newman-smoke-tests-minikube.sh' - } - junit '**/newman/*.xml' + agent any + stages { + stage('Checkout SCM') { + steps { + git changelog: true, poll: false, + url: "https://github.com/garystafford/${PROJECT_NAME}" + } + } + stage('Smoke Tests') { + steps { + dir('postman') { + nodejs('nodejs') { + sh 'sh newman-smoke-tests-minikube.sh' + } + junit '**/newman/*.xml' + } + } + } + stage('Integration Tests') { + steps { + dir('postman') { + nodejs('nodejs') { + sh 'sh newman-integration-tests-minikube.sh' + } + junit '**/newman/*.xml' + } + } + } } - } - } - stage('Integration Tests') { - steps { - dir('postman') { - nodejs('nodejs') { - sh 'sh newman-integration-tests-minikube.sh' - } - junit '**/newman/*.xml' - } - } - } - } } diff --git a/Jenkins/k8s-demo-deploy/Jenkinsfile b/Jenkins/k8s-demo-deploy/Jenkinsfile new file mode 100644 index 0000000..568ef1b --- /dev/null +++ b/Jenkins/k8s-demo-deploy/Jenkinsfile @@ -0,0 +1,34 @@ +#!groovy + +def PROJECT_NAME = "spring-postgresql-demo" + +pipeline { + agent any + stages { + stage('Checkout GitHub') { + steps { + git changelog: true, poll: true, + branch: 'h2', + url: "https://github.com/garystafford/${PROJECT_NAME}" + } + } + dir('kubernetes') { + stage('Build Environments') { + steps { + sh 'sh ./part2-create-environments.sh' + sh 'sh ./get-cluster-ip-ranges.sh' + } + } + stage('Deploy Postgres to dev') { + steps { + sh 'sh ./deploy-postgres-local.sh' + } + } + stage('Deploy Election v1') { + steps { + sh 'sh ./part3-deploy-v1-all-envs.sh' + } + } + } + } +} diff --git a/kubernetes/deploy-postgres-local.sh b/kubernetes/deploy-postgres-local.sh index 515876c..7d67e92 100644 --- a/kubernetes/deploy-postgres-local.sh +++ b/kubernetes/deploy-postgres-local.sh @@ -9,4 +9,4 @@ kubectl apply -f ./postgres-local/postgres-deployment.yaml -n dev kubectl apply -f ./postgres-local/postgres-service.yaml -n dev -kubectl get pods -dev +kubectl get pods -n dev From c98e719635b5b1ab0aa1eb8f329c287f7ba4fa29 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 22:09:57 -0400 Subject: [PATCH 14/28] Update from v1.0.0 to v1.1.0 for demo --- Jenkins/k8s-demo-deploy/Jenkinsfile | 18 +++++++++++------- docker/docker-build-push-v1.0.0.sh | 9 --------- docker/docker-build-push-v1.1.0.sh | 6 ++++++ .../election-deployment-v1-dev.yaml | 2 +- .../election-deployment-v1-test.yaml | 2 +- .../election-deployment-v1-uat.yaml | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 docker/docker-build-push-v1.0.0.sh create mode 100644 docker/docker-build-push-v1.1.0.sh diff --git a/Jenkins/k8s-demo-deploy/Jenkinsfile b/Jenkins/k8s-demo-deploy/Jenkinsfile index 568ef1b..ada203b 100644 --- a/Jenkins/k8s-demo-deploy/Jenkinsfile +++ b/Jenkins/k8s-demo-deploy/Jenkinsfile @@ -12,20 +12,24 @@ pipeline { url: "https://github.com/garystafford/${PROJECT_NAME}" } } - dir('kubernetes') { - stage('Build Environments') { - steps { + stage('Build Environments') { + steps { + dir('kubernetes') { sh 'sh ./part2-create-environments.sh' sh 'sh ./get-cluster-ip-ranges.sh' } } - stage('Deploy Postgres to dev') { - steps { + } + stage('Deploy Postgres to dev') { + steps { + dir('kubernetes') { sh 'sh ./deploy-postgres-local.sh' } } - stage('Deploy Election v1') { - steps { + } + stage('Deploy Election v1') { + steps { + dir('kubernetes') { sh 'sh ./part3-deploy-v1-all-envs.sh' } } diff --git a/docker/docker-build-push-v1.0.0.sh b/docker/docker-build-push-v1.0.0.sh deleted file mode 100644 index 63085eb..0000000 --- a/docker/docker-build-push-v1.0.0.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -# docker login --username --password - -# docker build -t spring-postgresql-demo:$(git rev-parse --short HEAD) . -# docker build --no-cache -t garystafford/spring-postgresql-demo:latest . - -docker build --no-cache -t garystafford/spring-postgresql-demo:1.0.0 . -docker push garystafford/spring-postgresql-demo:1.0.0 diff --git a/docker/docker-build-push-v1.1.0.sh b/docker/docker-build-push-v1.1.0.sh new file mode 100644 index 0000000..50cd7ad --- /dev/null +++ b/docker/docker-build-push-v1.1.0.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# docker login --username --password + +docker build --no-cache -t garystafford/spring-postgresql-demo:1.1.0 . +docker push garystafford/spring-postgresql-demo:1.1.0 diff --git a/kubernetes/deployments/election-deployment-v1-dev.yaml b/kubernetes/deployments/election-deployment-v1-dev.yaml index b7a2b2b..ca1e3a4 100644 --- a/kubernetes/deployments/election-deployment-v1-dev.yaml +++ b/kubernetes/deployments/election-deployment-v1-dev.yaml @@ -19,7 +19,7 @@ spec: spec: containers: - name: election-v1 - image: garystafford/spring-postgresql-demo:1.0.0 + image: garystafford/spring-postgresql-demo:1.1.0 env: - name: SPRING_PROFILES_ACTIVE value: dev diff --git a/kubernetes/deployments/election-deployment-v1-test.yaml b/kubernetes/deployments/election-deployment-v1-test.yaml index a8e9ced..7282f1a 100644 --- a/kubernetes/deployments/election-deployment-v1-test.yaml +++ b/kubernetes/deployments/election-deployment-v1-test.yaml @@ -19,7 +19,7 @@ spec: spec: containers: - name: election-v1 - image: garystafford/spring-postgresql-demo:1.0.0 + image: garystafford/spring-postgresql-demo:1.1.0 env: - name: SPRING_PROFILES_ACTIVE value: test diff --git a/kubernetes/deployments/election-deployment-v1-uat.yaml b/kubernetes/deployments/election-deployment-v1-uat.yaml index d8f24dc..e3bf0a7 100644 --- a/kubernetes/deployments/election-deployment-v1-uat.yaml +++ b/kubernetes/deployments/election-deployment-v1-uat.yaml @@ -19,7 +19,7 @@ spec: spec: containers: - name: election-v1 - image: garystafford/spring-postgresql-demo:1.0.0 + image: garystafford/spring-postgresql-demo:1.1.0 env: - name: SPRING_PROFILES_ACTIVE value: uat From 26693aad631d49ccc7a7830d6331acc9549c8e74 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 22:50:14 -0400 Subject: [PATCH 15/28] Refactor Postgres DB --- kubernetes/postgres-local/postgres-deployment.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kubernetes/postgres-local/postgres-deployment.yaml b/kubernetes/postgres-local/postgres-deployment.yaml index 107ea45..5e6b36a 100644 --- a/kubernetes/postgres-local/postgres-deployment.yaml +++ b/kubernetes/postgres-local/postgres-deployment.yaml @@ -2,7 +2,6 @@ apiVersion: apps/v1 kind: Deployment metadata: labels: - istio-injection: enabled app: postgres name: postgres spec: @@ -14,7 +13,6 @@ spec: template: metadata: labels: - istio-injection: enabled app: postgres spec: containers: @@ -22,8 +20,6 @@ spec: env: - name: POSTGRES_DB value: elections - - name: PGDATA - value: /var/lib/postgresql/data/pgdata - name: POSTGRES_PASSWORD value: postgres1234 - name: POSTGRES_USERNAME From 11b7f6d7157b437ee153c58fcbc67af9559ff4ef Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 23:22:04 -0400 Subject: [PATCH 16/28] Fixing k8s deployment Jenkinsfile --- Jenkins/docker/Jenkinsfile | 4 ---- Jenkins/k8s-demo-deploy/Jenkinsfile | 8 +++++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Jenkins/docker/Jenkinsfile b/Jenkins/docker/Jenkinsfile index 8db469c..f04738e 100644 --- a/Jenkins/docker/Jenkinsfile +++ b/Jenkins/docker/Jenkinsfile @@ -2,7 +2,6 @@ def DOCKER_HUB_ACCOUNT = "garystafford" def PROJECT_NAME = "spring-postgresql-demo" -// def IMAGE_TAG = "2.1.0" pipeline { agent any @@ -30,8 +29,6 @@ pipeline { sh "docker login --username ${DOCKER_HUB_USERNAME} --password ${DOCKER_HUB_PASSWORD}" } dir('docker') { - // sh 'ls -al' - // sh 'docker version' sh "docker build --file Dockerfile_Jenkins --no-cache --tag ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG} ." } } @@ -39,7 +36,6 @@ pipeline { stage('Push Image') { steps { dir('docker') { - // sh 'ls -al' sh "docker push ${DOCKER_HUB_ACCOUNT}/${PROJECT_NAME}:${params.IMAGE_TAG}" } } diff --git a/Jenkins/k8s-demo-deploy/Jenkinsfile b/Jenkins/k8s-demo-deploy/Jenkinsfile index ada203b..39eeaf6 100644 --- a/Jenkins/k8s-demo-deploy/Jenkinsfile +++ b/Jenkins/k8s-demo-deploy/Jenkinsfile @@ -16,7 +16,13 @@ pipeline { steps { dir('kubernetes') { sh 'sh ./part2-create-environments.sh' - sh 'sh ./get-cluster-ip-ranges.sh' + } + } + } + stage('Get Cluster CIDRs') { + steps { + dir('kubernetes') { + sh 'export IP_RANGES=$(sh ./get-cluster-ip-ranges.sh)' } } } From a80577809abb47717700ef66e832411812a03eb2 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 23:26:08 -0400 Subject: [PATCH 17/28] Fixing k8s deployment Jenkinsfile --- kubernetes/part3-deploy-v1-all-envs.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kubernetes/part3-deploy-v1-all-envs.sh b/kubernetes/part3-deploy-v1-all-envs.sh index 6012589..ce0c6df 100644 --- a/kubernetes/part3-deploy-v1-all-envs.sh +++ b/kubernetes/part3-deploy-v1-all-envs.sh @@ -2,6 +2,8 @@ # part 3: deploy v1 to all environments +echo $IP_RANGES + # election v1 deployment with manual sidecar injection istioctl kube-inject –kubeconfig "~/.kube/config" \ -f ./deployments/election-deployment-v1-dev.yaml \ From 132b8c89c93b3f06a249a9fbc1d148e639b3bdfe Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Wed, 25 Apr 2018 23:27:40 -0400 Subject: [PATCH 18/28] Fixing k8s deployment Jenkinsfile --- kubernetes/part3-deploy-v1-all-envs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes/part3-deploy-v1-all-envs.sh b/kubernetes/part3-deploy-v1-all-envs.sh index ce0c6df..745f3d9 100644 --- a/kubernetes/part3-deploy-v1-all-envs.sh +++ b/kubernetes/part3-deploy-v1-all-envs.sh @@ -2,7 +2,7 @@ # part 3: deploy v1 to all environments -echo $IP_RANGES +env | sort # election v1 deployment with manual sidecar injection istioctl kube-inject –kubeconfig "~/.kube/config" \ From 4cd9dda4283837f0de0281a9c69146a4dbae5aa5 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Thu, 26 Apr 2018 09:45:54 -0400 Subject: [PATCH 19/28] Refactor k8s deploy pipeline and scripts --- Jenkins/k8s-demo-deploy/Jenkinsfile | 14 ++++++---- kubernetes/part1B-get-cluster-creds.sh | 2 +- kubernetes/part3a-deploy-v1-dev.sh | 19 ++++++++++++++ kubernetes/postgres-deployment.yaml | 36 -------------------------- kubernetes/postgres-service.yaml | 15 ----------- 5 files changed, 29 insertions(+), 57 deletions(-) create mode 100644 kubernetes/part3a-deploy-v1-dev.sh delete mode 100644 kubernetes/postgres-deployment.yaml delete mode 100644 kubernetes/postgres-service.yaml diff --git a/Jenkins/k8s-demo-deploy/Jenkinsfile b/Jenkins/k8s-demo-deploy/Jenkinsfile index 39eeaf6..4871d00 100644 --- a/Jenkins/k8s-demo-deploy/Jenkinsfile +++ b/Jenkins/k8s-demo-deploy/Jenkinsfile @@ -12,17 +12,17 @@ pipeline { url: "https://github.com/garystafford/${PROJECT_NAME}" } } - stage('Build Environments') { + stage('Get Cluster Creds') { steps { dir('kubernetes') { - sh 'sh ./part2-create-environments.sh' + sh 'sh ./part1B-get-cluster-creds' } } } - stage('Get Cluster CIDRs') { + stage('Build Environments') { steps { dir('kubernetes') { - sh 'export IP_RANGES=$(sh ./get-cluster-ip-ranges.sh)' + sh 'sh ./part2-create-environments.sh' } } } @@ -34,9 +34,13 @@ pipeline { } } stage('Deploy Election v1') { + environment { // get cluster ip ranges for deploy script + IP_RANGE = sh(returnStdout: true, script: 'sh ./kubernetes/get-cluster-ip-ranges.sh') + } steps { dir('kubernetes') { - sh 'sh ./part3-deploy-v1-all-envs.sh' + sh 'env | sort' + sh 'sh ./part3A-deploy-v1-dev.sh' } } } diff --git a/kubernetes/part1B-get-cluster-creds.sh b/kubernetes/part1B-get-cluster-creds.sh index 8e923bf..cc6524f 100644 --- a/kubernetes/part1B-get-cluster-creds.sh +++ b/kubernetes/part1B-get-cluster-creds.sh @@ -1,6 +1,6 @@ #!/bin/bash -# part 1B: get gke/istio cluster creds +# part 1b: get gke/istio cluster creds # change to match your environment GCP_PROJECT="springdemo-199819" diff --git a/kubernetes/part3a-deploy-v1-dev.sh b/kubernetes/part3a-deploy-v1-dev.sh new file mode 100644 index 0000000..ed7ab5a --- /dev/null +++ b/kubernetes/part3a-deploy-v1-dev.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# apply resources part 3a: v1 to dev + +# election v1 deployment with manual sidecar injection +istioctl kube-inject –kubeconfig "~/.kube/config" \ + -f ./deployments/election-deployment-v1-dev.yaml \ + --includeIPRanges=$IP_RANGES > \ + election-deployment-istio.yaml \ + && kubectl apply -f election-deployment-istio.yaml \ + && rm election-deployment-istio.yaml + +# services +kubectl apply -f ./services/election-service.yaml -n dev + +# route rules +kubectl apply -f ./routerules/routerule-election-v1.yaml -n dev + +kubectl get pods -n dev diff --git a/kubernetes/postgres-deployment.yaml b/kubernetes/postgres-deployment.yaml deleted file mode 100644 index 2b555cb..0000000 --- a/kubernetes/postgres-deployment.yaml +++ /dev/null @@ -1,36 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - namespace: dev - labels: - istio-injection: enabled - app: postgres - name: postgres -spec: - selector: - matchLabels: - app: postgres - replicas: 1 - strategy: {} - template: - metadata: - labels: - istio-injection: enabled - app: postgres - spec: - containers: - - image: postgres:10.3-alpine - env: - - name: POSTGRES_DB - value: elections - - name: PGDATA - value: /var/lib/postgresql/data/pgdata - - name: POSTGRES_PASSWORD - value: postgres1234 - - name: POSTGRES_USERNAME - value: postgres - name: postgres - ports: - - containerPort: 5432 - restartPolicy: Always -status: {} diff --git a/kubernetes/postgres-service.yaml b/kubernetes/postgres-service.yaml deleted file mode 100644 index 7131349..0000000 --- a/kubernetes/postgres-service.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - labels: - istio-injection: enabled - app: postgres - name: postgres - namespace: dev -spec: - ports: - - name: http - port: 5432 - selector: - app: postgres -status: {} From b1dafc80e8bf858ccca358ad141763665feef104 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Thu, 26 Apr 2018 09:55:20 -0400 Subject: [PATCH 20/28] Refactor k8s deploy pipeline and scripts --- Jenkins/k8s-demo-deploy/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkins/k8s-demo-deploy/Jenkinsfile b/Jenkins/k8s-demo-deploy/Jenkinsfile index 4871d00..bf87cf1 100644 --- a/Jenkins/k8s-demo-deploy/Jenkinsfile +++ b/Jenkins/k8s-demo-deploy/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { stage('Get Cluster Creds') { steps { dir('kubernetes') { - sh 'sh ./part1B-get-cluster-creds' + sh 'sh ./part1b-get-cluster-creds' } } } @@ -40,7 +40,7 @@ pipeline { steps { dir('kubernetes') { sh 'env | sort' - sh 'sh ./part3A-deploy-v1-dev.sh' + sh 'sh ./part3a-deploy-v1-dev.sh' } } } From 509f4a2a56efbff6f0a2bd7e5138f868c3643200 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Thu, 26 Apr 2018 09:59:49 -0400 Subject: [PATCH 21/28] Refactor k8s deploy pipeline and scripts --- Jenkins/k8s-demo-deploy/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkins/k8s-demo-deploy/Jenkinsfile b/Jenkins/k8s-demo-deploy/Jenkinsfile index bf87cf1..31d7834 100644 --- a/Jenkins/k8s-demo-deploy/Jenkinsfile +++ b/Jenkins/k8s-demo-deploy/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { stage('Get Cluster Creds') { steps { dir('kubernetes') { - sh 'sh ./part1b-get-cluster-creds' + sh 'sh ./part1b-get-cluster-creds.sh' } } } From 46212a6bebca03c42dfcacb5cef6b253443e9ef3 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Thu, 26 Apr 2018 10:19:07 -0400 Subject: [PATCH 22/28] Change IP_RANGE to IP_RANGES --- Jenkins/k8s-demo-deploy/Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkins/k8s-demo-deploy/Jenkinsfile b/Jenkins/k8s-demo-deploy/Jenkinsfile index 31d7834..0475de0 100644 --- a/Jenkins/k8s-demo-deploy/Jenkinsfile +++ b/Jenkins/k8s-demo-deploy/Jenkinsfile @@ -33,9 +33,10 @@ pipeline { } } } - stage('Deploy Election v1') { + stage('Deploy Election v1 to dev') { environment { // get cluster ip ranges for deploy script - IP_RANGE = sh(returnStdout: true, script: 'sh ./kubernetes/get-cluster-ip-ranges.sh') + IP_RANGES = sh(returnStdout: true, + script: 'sh ./kubernetes/get-cluster-ip-ranges.sh') } steps { dir('kubernetes') { From f8408268b74bab80233802bf3888f6285717e089 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Thu, 26 Apr 2018 11:38:22 -0400 Subject: [PATCH 23/28] Fixing Postgres connection --- .../deployments/election-deployment-v1-dev.yaml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/kubernetes/deployments/election-deployment-v1-dev.yaml b/kubernetes/deployments/election-deployment-v1-dev.yaml index ca1e3a4..d4fe697 100644 --- a/kubernetes/deployments/election-deployment-v1-dev.yaml +++ b/kubernetes/deployments/election-deployment-v1-dev.yaml @@ -26,20 +26,7 @@ spec: - name: SPRING_DATASOURCE_HIKARI_MAXIMUM-POOL-SIZE value: 2 - name: SPRING_DATASOURCE_URL - valueFrom: - secretKeyRef: - name: postgresql-conn-info - key: url - - name: SPRING_DATASOURCE_USERNAME - valueFrom: - secretKeyRef: - name: postgresql-conn-info - key: username - - name: SPRING_DATASOURCE_PASSWORD - valueFrom: - secretKeyRef: - name: postgresql-conn-info - key: password + value: jdbc:postgresql://postgres:5432/elections ports: - containerPort: 8080 restartPolicy: Always From d7332c8263053cff49f95740234440bcb9a5b352 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Thu, 26 Apr 2018 12:30:27 -0400 Subject: [PATCH 24/28] Fixing Postgres connection --- kubernetes/README.md | 4 ++++ .../deployments/election-deployment-v1-dev.yaml | 15 ++++++++++++++- kubernetes/part3a-deploy-v1-dev.sh | 7 +------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/kubernetes/README.md b/kubernetes/README.md index b34352e..281e532 100644 --- a/kubernetes/README.md +++ b/kubernetes/README.md @@ -15,3 +15,7 @@ aws rds delete-db-instance \ --db-instance-identifier elections-dev \ --skip-final-snapshot ``` + +```bash +kubectl -n dev run curl --image=radial/busyboxplus:curl -i --tty +``` diff --git a/kubernetes/deployments/election-deployment-v1-dev.yaml b/kubernetes/deployments/election-deployment-v1-dev.yaml index d4fe697..ca1e3a4 100644 --- a/kubernetes/deployments/election-deployment-v1-dev.yaml +++ b/kubernetes/deployments/election-deployment-v1-dev.yaml @@ -26,7 +26,20 @@ spec: - name: SPRING_DATASOURCE_HIKARI_MAXIMUM-POOL-SIZE value: 2 - name: SPRING_DATASOURCE_URL - value: jdbc:postgresql://postgres:5432/elections + valueFrom: + secretKeyRef: + name: postgresql-conn-info + key: url + - name: SPRING_DATASOURCE_USERNAME + valueFrom: + secretKeyRef: + name: postgresql-conn-info + key: username + - name: SPRING_DATASOURCE_PASSWORD + valueFrom: + secretKeyRef: + name: postgresql-conn-info + key: password ports: - containerPort: 8080 restartPolicy: Always diff --git a/kubernetes/part3a-deploy-v1-dev.sh b/kubernetes/part3a-deploy-v1-dev.sh index ed7ab5a..a986e41 100644 --- a/kubernetes/part3a-deploy-v1-dev.sh +++ b/kubernetes/part3a-deploy-v1-dev.sh @@ -3,12 +3,7 @@ # apply resources part 3a: v1 to dev # election v1 deployment with manual sidecar injection -istioctl kube-inject –kubeconfig "~/.kube/config" \ - -f ./deployments/election-deployment-v1-dev.yaml \ - --includeIPRanges=$IP_RANGES > \ - election-deployment-istio.yaml \ - && kubectl apply -f election-deployment-istio.yaml \ - && rm election-deployment-istio.yaml +kubectl apply -f ./deployments/election-deployment-v1-dev.yaml # services kubectl apply -f ./services/election-service.yaml -n dev From 3da5a996cff4046f2a90a989f828c74587407484 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Thu, 26 Apr 2018 12:51:52 -0400 Subject: [PATCH 25/28] Fixing Postgres connection --- kubernetes/deployments/election-deployment-v1-dev.yaml | 2 +- kubernetes/part3-deploy-v1-all-envs.sh | 2 -- kubernetes/part3a-deploy-v1-dev.sh | 8 +++++++- kubernetes/postgres-local/postgres-service.yaml | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/kubernetes/deployments/election-deployment-v1-dev.yaml b/kubernetes/deployments/election-deployment-v1-dev.yaml index ca1e3a4..5240078 100644 --- a/kubernetes/deployments/election-deployment-v1-dev.yaml +++ b/kubernetes/deployments/election-deployment-v1-dev.yaml @@ -24,7 +24,7 @@ spec: - name: SPRING_PROFILES_ACTIVE value: dev - name: SPRING_DATASOURCE_HIKARI_MAXIMUM-POOL-SIZE - value: 2 + value: '2' - name: SPRING_DATASOURCE_URL valueFrom: secretKeyRef: diff --git a/kubernetes/part3-deploy-v1-all-envs.sh b/kubernetes/part3-deploy-v1-all-envs.sh index 745f3d9..6012589 100644 --- a/kubernetes/part3-deploy-v1-all-envs.sh +++ b/kubernetes/part3-deploy-v1-all-envs.sh @@ -2,8 +2,6 @@ # part 3: deploy v1 to all environments -env | sort - # election v1 deployment with manual sidecar injection istioctl kube-inject –kubeconfig "~/.kube/config" \ -f ./deployments/election-deployment-v1-dev.yaml \ diff --git a/kubernetes/part3a-deploy-v1-dev.sh b/kubernetes/part3a-deploy-v1-dev.sh index a986e41..398ae7c 100644 --- a/kubernetes/part3a-deploy-v1-dev.sh +++ b/kubernetes/part3a-deploy-v1-dev.sh @@ -3,7 +3,13 @@ # apply resources part 3a: v1 to dev # election v1 deployment with manual sidecar injection -kubectl apply -f ./deployments/election-deployment-v1-dev.yaml +# kubectl apply -f ./deployments/election-deployment-v1-dev.yaml +istioctl kube-inject –kubeconfig "~/.kube/config" \ + -f ./deployments/election-deployment-v1-dev.yaml \ + --includeIPRanges=$IP_RANGES > \ + election-deployment-istio.yaml \ + && kubectl apply -f election-deployment-istio.yaml \ + && rm election-deployment-istio.yaml # services kubectl apply -f ./services/election-service.yaml -n dev diff --git a/kubernetes/postgres-local/postgres-service.yaml b/kubernetes/postgres-local/postgres-service.yaml index e49ef68..555742a 100644 --- a/kubernetes/postgres-local/postgres-service.yaml +++ b/kubernetes/postgres-local/postgres-service.yaml @@ -7,7 +7,7 @@ metadata: name: postgres spec: ports: - - name: http + - name: foo port: 5432 selector: app: postgres From 5a41cdb9e671dd86a85fb2813306d0a17f058211 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Thu, 26 Apr 2018 13:39:12 -0400 Subject: [PATCH 26/28] Fixing Postgres connection --- kubernetes/part3a-deploy-v1-dev.sh | 3 +-- kubernetes/postgres-local/postgres-service.yaml | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kubernetes/part3a-deploy-v1-dev.sh b/kubernetes/part3a-deploy-v1-dev.sh index 398ae7c..b918e5b 100644 --- a/kubernetes/part3a-deploy-v1-dev.sh +++ b/kubernetes/part3a-deploy-v1-dev.sh @@ -5,8 +5,7 @@ # election v1 deployment with manual sidecar injection # kubectl apply -f ./deployments/election-deployment-v1-dev.yaml istioctl kube-inject –kubeconfig "~/.kube/config" \ - -f ./deployments/election-deployment-v1-dev.yaml \ - --includeIPRanges=$IP_RANGES > \ + -f ./deployments/election-deployment-v1-dev.yaml > \ election-deployment-istio.yaml \ && kubectl apply -f election-deployment-istio.yaml \ && rm election-deployment-istio.yaml diff --git a/kubernetes/postgres-local/postgres-service.yaml b/kubernetes/postgres-local/postgres-service.yaml index 555742a..2231cf7 100644 --- a/kubernetes/postgres-local/postgres-service.yaml +++ b/kubernetes/postgres-local/postgres-service.yaml @@ -7,8 +7,9 @@ metadata: name: postgres spec: ports: - - name: foo + - protocol: TCP port: 5432 + targetPort: 5432 selector: app: postgres status: {} From 2f5038176d95fb9d9ce0ee5a92523e5555a7a631 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Thu, 26 Apr 2018 13:48:45 -0400 Subject: [PATCH 27/28] Fixing Postgres connection --- kubernetes/part3a-deploy-v1-dev.sh | 3 ++- kubernetes/postgres-local/postgres-service.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kubernetes/part3a-deploy-v1-dev.sh b/kubernetes/part3a-deploy-v1-dev.sh index b918e5b..398ae7c 100644 --- a/kubernetes/part3a-deploy-v1-dev.sh +++ b/kubernetes/part3a-deploy-v1-dev.sh @@ -5,7 +5,8 @@ # election v1 deployment with manual sidecar injection # kubectl apply -f ./deployments/election-deployment-v1-dev.yaml istioctl kube-inject –kubeconfig "~/.kube/config" \ - -f ./deployments/election-deployment-v1-dev.yaml > \ + -f ./deployments/election-deployment-v1-dev.yaml \ + --includeIPRanges=$IP_RANGES > \ election-deployment-istio.yaml \ && kubectl apply -f election-deployment-istio.yaml \ && rm election-deployment-istio.yaml diff --git a/kubernetes/postgres-local/postgres-service.yaml b/kubernetes/postgres-local/postgres-service.yaml index 2231cf7..1a5e3df 100644 --- a/kubernetes/postgres-local/postgres-service.yaml +++ b/kubernetes/postgres-local/postgres-service.yaml @@ -7,7 +7,8 @@ metadata: name: postgres spec: ports: - - protocol: TCP + - name: tcp + protocol: TCP port: 5432 targetPort: 5432 selector: From 4866380128fbbf99902124986428f2b1318406f0 Mon Sep 17 00:00:00 2001 From: "Gary A. Stafford" Date: Fri, 27 Apr 2018 08:25:01 -0400 Subject: [PATCH 28/28] Script and Jenkinsfile rectoring, project cleanup --- Jenkins/ci/Jenkinsfile | 8 ++++---- Jenkins/docker/Jenkinsfile | 6 +++--- Jenkins/install-istio.sh | 13 ------------ Jenkins/integration/Jenkinsfile | 1 + Jenkins/k8s-demo-deploy/Jenkinsfile | 20 ++++++++++++++----- kubernetes/README.md | 2 +- ...es-local.sh => deploy-postgres-gke-dev.sh} | 0 kubernetes/get-cluster-ip-ranges.sh | 13 ++++++++---- kubernetes/part1-create-gke-cluster.sh | 4 +++- kubernetes/part1B-get-cluster-creds.sh | 2 +- kubernetes/part3a-deploy-v1-dev.sh | 2 +- postman/newman-smoke-tests-dev.sh | 12 +++++++++++ 12 files changed, 50 insertions(+), 33 deletions(-) delete mode 100644 Jenkins/install-istio.sh rename kubernetes/{deploy-postgres-local.sh => deploy-postgres-gke-dev.sh} (100%) create mode 100644 postman/newman-smoke-tests-dev.sh diff --git a/Jenkins/ci/Jenkinsfile b/Jenkins/ci/Jenkinsfile index 293a39c..12afe82 100644 --- a/Jenkins/ci/Jenkinsfile +++ b/Jenkins/ci/Jenkinsfile @@ -11,7 +11,7 @@ pipeline { stage('Checkout GitHub') { steps { git changelog: true, poll: true, - branch: 'h2', + branch: 'master', url: "https://github.com/garystafford/${PROJECT_NAME}" } } @@ -21,7 +21,7 @@ pipeline { sh './gradlew clean build -x test' } } - stage('Unit Test') { + stage('Unit Test') { // unit test against h2 steps { withEnv(['SPRING_DATASOURCE_URL=jdbc:h2:file:~/elections']) { sh './gradlew cleanTest test' @@ -36,12 +36,12 @@ pipeline { } } } - stage('Archive Artifact') { + stage('Archive Artifact') { // option 1 to build Dockerfile in next pipeline steps { archiveArtifacts 'build/libs/*.jar' } } - stage('Publish Artifact') { + stage('Publish Artifact') { // option 2 to build Dockerfile in next pipeline steps { withCredentials([string(credentialsId: 'GIT_TOKEN', variable: 'GIT_TOKEN')]) { dir('build/libs/') { diff --git a/Jenkins/docker/Jenkinsfile b/Jenkins/docker/Jenkinsfile index f04738e..7d0a153 100644 --- a/Jenkins/docker/Jenkinsfile +++ b/Jenkins/docker/Jenkinsfile @@ -13,12 +13,12 @@ pipeline { stages { stage('Checkout GitHub') { steps { - git changelog: true, poll: true, - branch: 'h2', + git changelog: true, poll: false, + branch: 'master', url: "https://github.com/garystafford/${PROJECT_NAME}" } } - stage('Build Image') { + stage('Build Image') { // uses option 1 from ci job to build Dockerfile steps { copyArtifacts filter: 'build/libs/*.jar', fingerprintArtifacts: true, flatten: true, projectName: 'election-ci', selector: lastSuccessful(), diff --git a/Jenkins/install-istio.sh b/Jenkins/install-istio.sh deleted file mode 100644 index 79c451f..0000000 --- a/Jenkins/install-istio.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Install Istio - - -ISTIO_VERSION="0.7.1" - -# install Istio -RUN set +x \ - && curl -O "https://github.com/istio/istio/releases/download/${ISTIO_VERSION}/istio-${ISTIO_VERSION}-linux.tar.gz" \ - && unzip istio-${ISTIO_VERSION}-linux.tar.gz \ - && rm -rf istio-${ISTIO_VERSION}-linux.tar.gz \ - && mv istio-${ISTIO_VERSION} /usr/bin diff --git a/Jenkins/integration/Jenkinsfile b/Jenkins/integration/Jenkinsfile index e6bc92c..afea43d 100644 --- a/Jenkins/integration/Jenkinsfile +++ b/Jenkins/integration/Jenkinsfile @@ -8,6 +8,7 @@ pipeline { stage('Checkout SCM') { steps { git changelog: true, poll: false, + branch: 'master', url: "https://github.com/garystafford/${PROJECT_NAME}" } } diff --git a/Jenkins/k8s-demo-deploy/Jenkinsfile b/Jenkins/k8s-demo-deploy/Jenkinsfile index 0475de0..c732804 100644 --- a/Jenkins/k8s-demo-deploy/Jenkinsfile +++ b/Jenkins/k8s-demo-deploy/Jenkinsfile @@ -7,8 +7,8 @@ pipeline { stages { stage('Checkout GitHub') { steps { - git changelog: true, poll: true, - branch: 'h2', + git changelog: true, poll: false, + branch: 'master', url: "https://github.com/garystafford/${PROJECT_NAME}" } } @@ -19,17 +19,17 @@ pipeline { } } } - stage('Build Environments') { + stage('Build Environments') { // dev, test, uat steps { dir('kubernetes') { sh 'sh ./part2-create-environments.sh' } } } - stage('Deploy Postgres to dev') { + stage('Deploy Postgres to dev') { // doesn't work with istio! steps { dir('kubernetes') { - sh 'sh ./deploy-postgres-local.sh' + sh 'sh ./deploy-postgres-gke-dev.sh' } } } @@ -45,5 +45,15 @@ pipeline { } } } + stage('Smoke Test') { // assumes 'api.dev.voter-demo.com' reachable + steps { + dir('postman') { + nodejs('nodejs') { + sh 'sh newman-smoke-tests-minikube.sh' + } + junit '**/newman/*.xml' + } + } + } } } diff --git a/kubernetes/README.md b/kubernetes/README.md index 281e532..7cb4965 100644 --- a/kubernetes/README.md +++ b/kubernetes/README.md @@ -1,4 +1,4 @@ -# Kubernetes Installation +# Kubernetes Installation Notes ## Amazon RDS diff --git a/kubernetes/deploy-postgres-local.sh b/kubernetes/deploy-postgres-gke-dev.sh similarity index 100% rename from kubernetes/deploy-postgres-local.sh rename to kubernetes/deploy-postgres-gke-dev.sh diff --git a/kubernetes/get-cluster-ip-ranges.sh b/kubernetes/get-cluster-ip-ranges.sh index ccf501a..25ec9ee 100644 --- a/kubernetes/get-cluster-ip-ranges.sh +++ b/kubernetes/get-cluster-ip-ranges.sh @@ -4,12 +4,17 @@ # capture the clusterIpv4Cidr and servicesIpv4Cidr values # required for manual sidecar injection with kube-inject -CLUSTER_IPV4_CIDR=$(gcloud container clusters describe election-nonprod-cluster \ - --zone us-east1-b --project springdemo-199819 \ +# change to match your environment +GCP_PROJECT="springdemo-199819" +GKE_CLUSTER="election-nonprod-cluster" +GCP_ZONE="us-east1-b" + +CLUSTER_IPV4_CIDR=$(gcloud container clusters describe ${GKE_CLUSTER} \ + --zone ${GCP_ZONE} --project ${GCP_PROJECT} \ | egrep clusterIpv4Cidr | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\/[0-9]{2}\b") -SERVICES_IPV4_CIDR=$(gcloud container clusters describe election-nonprod-cluster \ - --zone us-east1-b --project springdemo-199819 \ +SERVICES_IPV4_CIDR=$(gcloud container clusters describe ${GKE_CLUSTER} \ + --zone ${GCP_ZONE} --project ${GCP_PROJECT} \ | egrep servicesIpv4Cidr | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\/[0-9]{2}\b") export IP_RANGES="$CLUSTER_IPV4_CIDR,$SERVICES_IPV4_CIDR" diff --git a/kubernetes/part1-create-gke-cluster.sh b/kubernetes/part1-create-gke-cluster.sh index ef64504..f78a7c8 100644 --- a/kubernetes/part1-create-gke-cluster.sh +++ b/kubernetes/part1-create-gke-cluster.sh @@ -5,10 +5,12 @@ # change to match your environment ISTIO_HOME="/Applications/istio-0.7.1" GCP_DEPLOYMENT_MANAGER="$ISTIO_HOME/install/gcp/deployment_manager" + GCP_PROJECT="springdemo-199819" GKE_CLUSTER="election-nonprod-cluster" -ISTIO_VER="0.7.1" GCP_ZONE="us-east1-b" + +ISTIO_VER="0.7.1" NODE_COUNT="1" INSTANCE_TYPE="n1-standard-1" diff --git a/kubernetes/part1B-get-cluster-creds.sh b/kubernetes/part1B-get-cluster-creds.sh index cc6524f..b18f454 100644 --- a/kubernetes/part1B-get-cluster-creds.sh +++ b/kubernetes/part1B-get-cluster-creds.sh @@ -1,6 +1,6 @@ #!/bin/bash -# part 1b: get gke/istio cluster creds +# part 1b: just get gke/istio cluster creds # change to match your environment GCP_PROJECT="springdemo-199819" diff --git a/kubernetes/part3a-deploy-v1-dev.sh b/kubernetes/part3a-deploy-v1-dev.sh index 398ae7c..519525d 100644 --- a/kubernetes/part3a-deploy-v1-dev.sh +++ b/kubernetes/part3a-deploy-v1-dev.sh @@ -1,6 +1,6 @@ #!/bin/bash -# apply resources part 3a: v1 to dev +# apply resources part 3a: just v1 to dev # election v1 deployment with manual sidecar injection # kubectl apply -f ./deployments/election-deployment-v1-dev.yaml diff --git a/postman/newman-smoke-tests-dev.sh b/postman/newman-smoke-tests-dev.sh new file mode 100644 index 0000000..8d7977b --- /dev/null +++ b/postman/newman-smoke-tests-dev.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +COLLECTION="election-k8s-smoke.postman_collection.json" +ENVIRONMENT="spring-postgresql-demo_gke_dev.postman_environment.json" +ITERATIONS=1 +DELAY=250 + +newman run $COLLECTION \ + --environment $ENVIRONMENT \ + --iteration-count $ITERATIONS \ + --no-color \ + --reporters cli,junit