From 1c0b806161a49631fb207391bce65e5ccd1a994f Mon Sep 17 00:00:00 2001 From: Bryan Kribbs Date: Thu, 15 Aug 2019 15:14:49 -0500 Subject: [PATCH 1/3] Removed Jenkins --- Jenkinsfile | 132 --------------------------- scripts/api_tests.sh | 44 --------- scripts/health_check.sh | 29 ------ scripts/install_minikube_and_helm.sh | 37 -------- scripts/push.sh | 33 ------- 5 files changed, 275 deletions(-) delete mode 100644 Jenkinsfile delete mode 100644 scripts/api_tests.sh delete mode 100644 scripts/health_check.sh delete mode 100644 scripts/install_minikube_and_helm.sh delete mode 100644 scripts/push.sh diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index e0ca75e..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,132 +0,0 @@ -def cloud = env.CLOUD ?: "openshift" -def servicePort = env.SERVICE_PORT ?: "8080" -def imageName = env.IMAGE_NAME ?: "greeting" -def podLabel = "sample" -podTemplate( - label: podLabel, - cloud: cloud, - envVars: [ - envVar(key: 'SERVICE_PORT', value: servicePort), - envVar(key: 'IMAGE_NAME', value: imageName), - envVar(key: 'BUILD_NUMBER', value: "${env.BUILD_NUMBER}") - ], - containers: [ - containerTemplate( - name: 'maven', - image: 'maven:3-alpine', - ttyEnabled: true, - command: '/bin/bash', - workingDir: '/home/jenkins' - ), - containerTemplate( - name: 'ibmcloud', - image: 'docker.io/garagecatalyst/ibmcloud-dev:1.0.5', - ttyEnabled: true, - command: '/bin/bash', - workingDir: '/home/jenkins', - envVars: [ - envVar(key: 'DOCKER_CONFIG', value: '/home/jenkins/.docker/'), - envVar(key: 'APIURL', value: 'https://cloud.ibm.com'), - envVar(key: 'HOME', value: '/home/devops') - ] - ) - ] -) { - node(podLabel) { - checkout scm - - container(name:'maven', shell:'/bin/bash') { - stage('Local - Build') { - sh 'mvn -B -DskipTests clean package' - } - stage('Local - Test') { - sh 'mvn test' - } - stage('Local - Run') { - sh """ - #!/bin/bash - java -jar ./target/cloudnativesampleapp-1.0-SNAPSHOT.jar & - PID=`echo \$!` - # Wait for the app to start - sleep 20 - sh scripts/health_check.sh - sh scripts/api_tests.sh 127.0.0.1 ${SERVICE_PORT} - # Kill process - kill \${PID} - """ - } - } - - container(name: 'ibmcloud', shell: '/bin/bash') { - stage('Build and Push Image') { - withCredentials( - [string(credentialsId: 'registry_url', variable: 'REGISTRY_URL'), - string(credentialsId: 'registry_namespace', variable: 'REGISTRY_NAMESPACE'), - string(credentialsId: 'ibm_cloud_region', variable: 'REGION'), - string(credentialsId: 'ibm_cloud_api_key', variable: 'APIKEY')]) { - sh '''#!/bin/bash - set -x - - ibmcloud login -r ${REGION} --apikey ${APIKEY} - - ibmcloud cr login - - echo "Checking registry namespace: ${REGISTRY_NAMESPACE}" - NS=$( ibmcloud cr namespaces | grep ${REGISTRY_NAMESPACE} ||: ) - if [[ -z "${NS}" ]]; then - echo -e "Registry namespace ${REGISTRY_NAMESPACE} not found, creating it." - ibmcloud cr namespace-add ${REGISTRY_NAMESPACE} - else - echo -e "Registry namespace ${REGISTRY_NAMESPACE} found." - fi - - echo -e "Existing images in registry" - ibmcloud cr images --restrict "${REGISTRY_NAMESPACE}/${IMAGE_NAME}" - - - echo -e "==========================================================================================" - echo -e "BUILDING CONTAINER IMAGE: ${REGISTRY_URL}/${REGISTRY_NAMESPACE}/${IMAGE_NAME}:${BUILD_NUMBER}" - set -x - ibmcloud cr build -f Dockerfile.multistage -t ${REGISTRY_URL}/${REGISTRY_NAMESPACE}/${IMAGE_NAME}:${BUILD_NUMBER} . - - echo -e "Available images in registry" - ibmcloud cr images --restrict ${REGISTRY_NAMESPACE}/${IMAGE_NAME} - - ''' - } - } - stage('Push to Deploy repo') { - sh "mkdir -p deploy" - - dir ('deploy') { - git url: "https://github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy.git", - branch: "master", - credentialsId: "github-credentials-id" - - sh "find ." - - withCredentials( - [string(credentialsId: 'git-account', variable: 'GIT_USER_ACCOUNT'), - string(credentialsId: 'github-token', variable: 'GITHUB_API_TOKEN')]) { - - sh """ - git config user.email "jenkins@jenkins.com" - git config user.name "jenkins" - cd chart/cloudnativesampleapp - sed -i.bak '/^image/,/^service/ s/\\(\\s*tag\\s*:\\s*\\).*/\\ \\ tag: '${BUILD_NUMBER}'/g' values.yaml - rm values.yaml.bak - git add . *.yaml - git commit -m "Jenkins commit: ${BUILD_NUMBER}" - git remote rm origin - git remote add origin https://${GIT_USER_ACCOUNT}:${GITHUB_API_TOKEN}@github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy.git > /dev/null 2>&1 - git push origin master - """ - } - } - - } - - } - - } -} diff --git a/scripts/api_tests.sh b/scripts/api_tests.sh deleted file mode 100644 index 7600d52..0000000 --- a/scripts/api_tests.sh +++ /dev/null @@ -1,44 +0,0 @@ -function parse_arguments() { - # MICROSERVICE_HOST - if [ -z "${MICROSERVICE_HOST}" ]; then - echo "MICROSERVICE_HOST not set. Using parameter \"$1\""; - MICROSERVICE_HOST=$1; - fi - - if [ -z "${MICROSERVICE_HOST}" ]; then - echo "MICROSERVICE_HOST not set. Using default key"; - MICROSERVICE_HOST=127.0.0.1; - fi - - # MICROSERVICE_PORT - if [ -z "${MICROSERVICE_PORT}" ]; then - echo "MICROSERVICE_PORT not set. Using parameter \"$2\""; - MICROSERVICE_PORT=$2; - fi - - if [ -z "${MICROSERVICE_PORT}" ]; then - echo "MICROSERVICE_PORT not set. Using default key"; - MICROSERVICE_PORT=8080; - fi - - echo "Using http://${MICROSERVICE_HOST}:${MICROSERVICE_PORT}" -} - -function greeting() { - CURL=$(curl -s --max-time 5 http://${MICROSERVICE_HOST}:${MICROSERVICE_PORT}/greeting?name=John); - echo "Greeting service returns \"${CURL}\" message" - - if [ -z "${CURL}" ] || [ ! "${CURL}" -gt "0" ]; then - echo "greeting: ❌ could not get any message"; - exit 1; - else - echo "greeting received: ✅"; - fi -} - -# Setup -parse_arguments $1 $2 - -# API Tests -echo "Starting Tests" -greeting diff --git a/scripts/health_check.sh b/scripts/health_check.sh deleted file mode 100644 index 6099502..0000000 --- a/scripts/health_check.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -function is_healthy { - curl -s ${HEALTH_URL} | awk -F'"' '/status/{ print $(NF-1) }'; -} - -URL="$1"; -HEALTH_CHECK="health"; - -if [ -z "$URL" ]; then - URL="http://localhost:8080" - echo "No URL provided! Using ${URL}" -fi - -HEALTH_URL="${URL}/${HEALTH_CHECK}" - -echo "Health Check on \"${HEALTH_URL}\""; - -HEALTHY=$(is_healthy) - -echo -n "Waiting for service to be ready" - -until [ -n "$HEALTHY" ] && [ "${HEALTHY}" == 'UP' ]; do - HEALTHY=$(is_healthy); - echo -n .; - sleep 1; -done - -printf "\nService is ready\n" diff --git a/scripts/install_minikube_and_helm.sh b/scripts/install_minikube_and_helm.sh deleted file mode 100644 index 8cf570b..0000000 --- a/scripts/install_minikube_and_helm.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -# Install socat, which is needed for port-forwarding -sudo apt-get update -sudo apt-get install socat - -# Download kubectl, which is a requirement for using minikube. -curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ - -# Download minikube. -curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.35.0/minikube-linux-amd64 && chmod +x minikube && sudo cp minikube /usr/local/bin/ && rm minikube -# Start Minikube -sudo minikube start --vm-driver=none --kubernetes-version=v1.13.0 -# Update minikube directory permissions -sudo chown -R travis: /home/travis/.minikube/ -# Fix the kubectl context, as it's often stale. -minikube update-context -# Getting ip for testing -minikube ip -# Wait for Minikube to be up and ready. -JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done - -# Download helm -curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh && chmod 700 get_helm.sh && ./get_helm.sh && rm get_helm.sh -# Create Tiller Service Account -kubectl -n kube-system create sa tiller && kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller -# Install Helm on Minikube -helm init --service-account tiller -# Wait for helm to be ready -until helm list; do echo "waiting for helm to be ready"; sleep 1; done - -# Add incubator and bluecompute-charts Helm repos -helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator -helm repo add ibmcase-charts https://raw.githubusercontent.com/ibm-cloud-architecture/refarch-cloudnative-kubernetes/spring/docs/charts - -# Get cluster info -kubectl cluster-info diff --git a/scripts/push.sh b/scripts/push.sh deleted file mode 100644 index 83c31b1..0000000 --- a/scripts/push.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -setup_git() { - git config --global user.email "travis@travis-ci.org" - git config --global user.name "Travis CI" -} - -commit_values_yaml() { - git clone https://github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy.git - git checkout master - cd cloudnative_sample_app_deploy - cd chart/cloudnativesampleapp - sed -i.bak '/^image/,/^service/ s/\(\s*tag\s*:\s*\).*/\ \ tag: '$COMMIT'/g' values.yaml - rm values.yaml.bak - git add . *.yaml - git commit --message "Travis build: $TRAVIS_BUILD_NUMBER" -} - -push_files() { - git remote rm origin - git remote add origin https://${GH_USER}:${GH_TOKEN}@github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy.git > /dev/null 2>&1 - git push origin master --quiet -} - -setup_git -commit_values_yaml - -if [ $? -eq 0 ]; then - echo "Uploading to GitHub" - push_files -else - echo "No changes" -fi From c575d1eeb09b5db3a8f970c8c78ba002cc26d5ab Mon Sep 17 00:00:00 2001 From: Bryan Kribbs Date: Thu, 15 Aug 2019 16:57:26 -0500 Subject: [PATCH 2/3] yaml fixes --- chart/cloudnativesampleapp/Chart.yaml | 4 --- chart/cloudnativesampleapp/deployment.yaml | 21 +++++++++++ chart/cloudnativesampleapp/service.yaml | 11 ++++++ .../templates/basedeployment.yaml | 36 ------------------- .../templates/deployment.yaml | 36 ------------------- chart/cloudnativesampleapp/templates/hpa.yaml | 27 -------------- .../cloudnativesampleapp/templates/istio.yaml | 19 ---------- .../templates/service.yaml | 13 ------- chart/cloudnativesampleapp/values.yaml | 34 ------------------ 9 files changed, 32 insertions(+), 169 deletions(-) delete mode 100644 chart/cloudnativesampleapp/Chart.yaml create mode 100644 chart/cloudnativesampleapp/deployment.yaml create mode 100644 chart/cloudnativesampleapp/service.yaml delete mode 100644 chart/cloudnativesampleapp/templates/basedeployment.yaml delete mode 100644 chart/cloudnativesampleapp/templates/deployment.yaml delete mode 100644 chart/cloudnativesampleapp/templates/hpa.yaml delete mode 100644 chart/cloudnativesampleapp/templates/istio.yaml delete mode 100644 chart/cloudnativesampleapp/templates/service.yaml delete mode 100644 chart/cloudnativesampleapp/values.yaml diff --git a/chart/cloudnativesampleapp/Chart.yaml b/chart/cloudnativesampleapp/Chart.yaml deleted file mode 100644 index 7f389f2..0000000 --- a/chart/cloudnativesampleapp/Chart.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: v1 -description: A Helm chart for Kubernetes -name: cloudnativesampleapp -version: 1.0.0 \ No newline at end of file diff --git a/chart/cloudnativesampleapp/deployment.yaml b/chart/cloudnativesampleapp/deployment.yaml new file mode 100644 index 0000000..bda1064 --- /dev/null +++ b/chart/cloudnativesampleapp/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: "greetings-deployment" +spec: + replicas: 1 + revisionHistoryLimit: 1 + template: + metadata: + labels: + app: "greetings" + spec: + containers: + - name: "greeting" + image: "ibmcase/greeting:1" + imagePullPolicy: "IfNotPresent" + env: + - name: PORT + value: "8080" + - name: APPLICATION_NAME + value: "greetings" \ No newline at end of file diff --git a/chart/cloudnativesampleapp/service.yaml b/chart/cloudnativesampleapp/service.yaml new file mode 100644 index 0000000..c61f97d --- /dev/null +++ b/chart/cloudnativesampleapp/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: "greeting-service" +spec: + type: NodePort + ports: + - name: http + port: 8080 + selector: + app: "greetings" \ No newline at end of file diff --git a/chart/cloudnativesampleapp/templates/basedeployment.yaml b/chart/cloudnativesampleapp/templates/basedeployment.yaml deleted file mode 100644 index 9156ba2..0000000 --- a/chart/cloudnativesampleapp/templates/basedeployment.yaml +++ /dev/null @@ -1,36 +0,0 @@ -{{ if .Values.base.enabled }} -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: "{{ .Chart.Name }}-basedeployment" - labels: - chart: '{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}' -spec: - replicas: {{ .Values.base.replicaCount }} - revisionHistoryLimit: {{ .Values.revisionHistoryLimit }} - template: - metadata: - labels: - app: "{{ .Chart.Name }}-selector" - version: "base" - spec: - containers: - - name: "{{ .Chart.Name }}" - image: "{{ .Values.image.repository }}:{{ .Values.base.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} -{{ if .Values.istio.enabled }} -{{ else }} - readinessProbe: - httpGet: - path: /health - port: 8080 - initialDelaySeconds: 20 -{{ end }} - resources: - requests: - cpu: "{{ .Values.image.resources.requests.cpu }}" - memory: "{{ .Values.image.resources.requests.memory }}" - env: - - name: PORT - value: "{{ .Values.service.servicePort }}" -{{ end }} \ No newline at end of file diff --git a/chart/cloudnativesampleapp/templates/deployment.yaml b/chart/cloudnativesampleapp/templates/deployment.yaml deleted file mode 100644 index c651f0c..0000000 --- a/chart/cloudnativesampleapp/templates/deployment.yaml +++ /dev/null @@ -1,36 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: "{{ .Chart.Name }}-deployment" - labels: - chart: '{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}' -spec: - replicas: {{ .Values.replicaCount }} - revisionHistoryLimit: {{ .Values.revisionHistoryLimit }} - template: - metadata: - labels: - app: "{{ .Chart.Name }}-selector" - version: "current" - spec: - containers: - - name: "{{ .Chart.Name }}" - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} -{{ if .Values.istio.enabled }} -{{ else }} - readinessProbe: - httpGet: - path: /health - port: 8080 - initialDelaySeconds: 20 -{{ end }} - resources: - requests: - cpu: "{{ .Values.image.resources.requests.cpu }}" - memory: "{{ .Values.image.resources.requests.memory }}" - env: - - name: PORT - value: "{{ .Values.service.servicePort }}" - - name: APPLICATION_NAME - value: "{{ .Release.Name }}" diff --git a/chart/cloudnativesampleapp/templates/hpa.yaml b/chart/cloudnativesampleapp/templates/hpa.yaml deleted file mode 100644 index 5fdefe9..0000000 --- a/chart/cloudnativesampleapp/templates/hpa.yaml +++ /dev/null @@ -1,27 +0,0 @@ -{{ if .Values.hpa.enabled }} -{{ if and (eq .Capabilities.KubeVersion.Major "1") (ge .Capabilities.KubeVersion.Minor "8") }} -apiVersion: autoscaling/v2beta1 -{{ else }} -apiVersion: autoscaling/v2alpha1 -{{ end }} -kind: HorizontalPodAutoscaler -metadata: - name: "{{ .Chart.Name }}-hpa-policy" - namespace: default -spec: - scaleTargetRef: - apiVersion: apps/v1beta1 - kind: Deployment - name: "{{ .Chart.Name }}-deployment" - minReplicas: {{ .Values.hpa.minReplicas }} - maxReplicas: {{ .Values.hpa.maxReplicas }} - metrics: - - type: Resource - resource: - name: cpu - targetAverageUtilization: {{ .Values.hpa.metrics.cpu.targetAverageUtilization }} - - type: Resource - resource: - name: memory - targetAverageUtilization: {{ .Values.hpa.metrics.memory.targetAverageUtilization }} -{{ end }} \ No newline at end of file diff --git a/chart/cloudnativesampleapp/templates/istio.yaml b/chart/cloudnativesampleapp/templates/istio.yaml deleted file mode 100644 index 7ee841b..0000000 --- a/chart/cloudnativesampleapp/templates/istio.yaml +++ /dev/null @@ -1,19 +0,0 @@ -{{ if .Values.istio.enabled }} -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: "{{ .Chart.Name }}-default" -spec: - destination: - name: "{{ .Chart.Name }}-service" - precedence: 1 - route: - - labels: - version: "current" - weight: {{ .Values.istio.weight }} -{{ if .Values.base.enabled }} - - labels: - version: "base" - weight: {{ .Values.base.weight }} -{{ end }} -{{ end }} \ No newline at end of file diff --git a/chart/cloudnativesampleapp/templates/service.yaml b/chart/cloudnativesampleapp/templates/service.yaml deleted file mode 100644 index 8e8cdb1..0000000 --- a/chart/cloudnativesampleapp/templates/service.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: "{{ .Chart.Name }}-service" - labels: - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" -spec: - type: {{ .Values.service.type }} - ports: - - name: http - port: {{ .Values.service.servicePort }} - selector: - app: "{{ .Chart.Name }}-selector" \ No newline at end of file diff --git a/chart/cloudnativesampleapp/values.yaml b/chart/cloudnativesampleapp/values.yaml deleted file mode 100644 index 26fb1d2..0000000 --- a/chart/cloudnativesampleapp/values.yaml +++ /dev/null @@ -1,34 +0,0 @@ -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. -replicaCount: 1 -revisionHistoryLimit: 1 -image: - repository: ibmcase/greeting - tag: v1.0.0 - pullPolicy: IfNotPresent - resources: - requests: - cpu: 200m - memory: 300Mi -service: - name: Node - type: NodePort - servicePort: 8080 -hpa: - enabled: false - minReplicas: 1 - maxReplicas: 2 - metrics: - cpu: - targetAverageUtilization: 70 - memory: - targetAverageUtilization: 70 -base: - enabled: false - replicaCount: 1 - image: - tag : v0.9.9 - weight: 100 -istio: - enabled: false - weight: 100 From 6b6db82ba5f5b63174665bfaf775ad463cded843 Mon Sep 17 00:00:00 2001 From: Hemankita Date: Fri, 30 Aug 2019 12:50:39 -0500 Subject: [PATCH 3/3] Updating the app to Springboot 2 --- Jenkinsfile | 133 ------------------ chart/cloudnativesampleapp/Chart.yaml | 4 - chart/cloudnativesampleapp/deployment.yaml | 21 +++ chart/cloudnativesampleapp/service.yaml | 11 ++ .../templates/basedeployment.yaml | 36 ----- .../templates/deployment.yaml | 36 ----- chart/cloudnativesampleapp/templates/hpa.yaml | 27 ---- .../cloudnativesampleapp/templates/istio.yaml | 19 --- .../templates/service.yaml | 13 -- chart/cloudnativesampleapp/values.yaml | 34 ----- scripts/api_tests.sh | 44 ------ scripts/health_check.sh | 29 ---- scripts/install_minikube_and_helm.sh | 37 ----- scripts/push.sh | 33 ----- 14 files changed, 32 insertions(+), 445 deletions(-) delete mode 100644 Jenkinsfile delete mode 100644 chart/cloudnativesampleapp/Chart.yaml create mode 100644 chart/cloudnativesampleapp/deployment.yaml create mode 100644 chart/cloudnativesampleapp/service.yaml delete mode 100644 chart/cloudnativesampleapp/templates/basedeployment.yaml delete mode 100644 chart/cloudnativesampleapp/templates/deployment.yaml delete mode 100644 chart/cloudnativesampleapp/templates/hpa.yaml delete mode 100644 chart/cloudnativesampleapp/templates/istio.yaml delete mode 100644 chart/cloudnativesampleapp/templates/service.yaml delete mode 100644 chart/cloudnativesampleapp/values.yaml delete mode 100644 scripts/api_tests.sh delete mode 100644 scripts/health_check.sh delete mode 100644 scripts/install_minikube_and_helm.sh delete mode 100644 scripts/push.sh diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index cfa356c..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,133 +0,0 @@ -def cloud = env.CLOUD ?: "openshift" -def servicePort = env.SERVICE_PORT ?: "8080" -def imageName = env.IMAGE_NAME ?: "greeting" -def podLabel = "sample" -podTemplate( - label: podLabel, - cloud: cloud, - envVars: [ - envVar(key: 'SERVICE_PORT', value: servicePort), - envVar(key: 'IMAGE_NAME', value: imageName), - envVar(key: 'BUILD_NUMBER', value: "${env.BUILD_NUMBER}") - ], - containers: [ - containerTemplate( - name: 'maven', - image: 'maven:3-alpine', - ttyEnabled: true, - command: '/bin/bash', - workingDir: '/home/jenkins', - envVars: [ - envVar(key: 'HOME', value: '/home/jenkins') - ] - ), - containerTemplate( - name: 'ibmcloud', - image: 'docker.io/garagecatalyst/ibmcloud-dev:1.0.7', - ttyEnabled: true, - command: '/bin/bash', - workingDir: '/home/jenkins', - envVars: [ - envVar(key: 'HOME', value: '/home/devops') - ] - ) - ] -) { - node(podLabel) { - checkout scm - - container(name:'maven', shell:'/bin/bash') { - stage('Local - Build') { - sh 'mvn -B -DskipTests clean package' - } - stage('Local - Test') { - sh 'mvn test' - } - stage('Local - Run') { - sh """ - #!/bin/bash - java -jar ./target/cloudnativesampleapp-1.0-SNAPSHOT.jar & - PID=`echo \$!` - # Wait for the app to start - sleep 20 - sh scripts/health_check.sh - sh scripts/api_tests.sh 127.0.0.1 ${SERVICE_PORT} - # Kill process - kill \${PID} - """ - } - } - - container(name: 'ibmcloud', shell: '/bin/bash') { - stage('Build and Push Image') { - withCredentials( - [string(credentialsId: 'registry_url', variable: 'REGISTRY_URL'), - string(credentialsId: 'registry_namespace', variable: 'REGISTRY_NAMESPACE'), - string(credentialsId: 'ibm_cloud_region', variable: 'REGION'), - string(credentialsId: 'ibm_cloud_api_key', variable: 'APIKEY')]) { - sh '''#!/bin/bash - set -x - - ibmcloud login -r ${REGION} --apikey ${APIKEY} - - ibmcloud cr login - - echo "Checking registry namespace: ${REGISTRY_NAMESPACE}" - NS=$( ibmcloud cr namespaces | grep ${REGISTRY_NAMESPACE} ||: ) - if [[ -z "${NS}" ]]; then - echo -e "Registry namespace ${REGISTRY_NAMESPACE} not found, creating it." - ibmcloud cr namespace-add ${REGISTRY_NAMESPACE} - else - echo -e "Registry namespace ${REGISTRY_NAMESPACE} found." - fi - - echo -e "Existing images in registry" - ibmcloud cr images --restrict "${REGISTRY_NAMESPACE}/${IMAGE_NAME}" - - - echo -e "==========================================================================================" - echo -e "BUILDING CONTAINER IMAGE: ${REGISTRY_URL}/${REGISTRY_NAMESPACE}/${IMAGE_NAME}:${BUILD_NUMBER}" - set -x - ibmcloud cr build -f Dockerfile.multistage -t ${REGISTRY_URL}/${REGISTRY_NAMESPACE}/${IMAGE_NAME}:${BUILD_NUMBER} . - - echo -e "Available images in registry" - ibmcloud cr images --restrict ${REGISTRY_NAMESPACE}/${IMAGE_NAME} - - ''' - } - } - stage('Push to Deploy repo') { - sh "mkdir -p deploy" - - dir ('deploy') { - git url: "https://github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy.git", - branch: "master", - credentialsId: "github-credentials-id" - - sh "find ." - - withCredentials( - [string(credentialsId: 'git-account', variable: 'GIT_USER_ACCOUNT'), - string(credentialsId: 'github-token', variable: 'GITHUB_API_TOKEN')]) { - - sh """ - git config user.email "jenkins@jenkins.com" - git config user.name "jenkins" - cd chart/cloudnativesampleapp - sed -i.bak '/^image/,/^service/ s/\\(\\s*tag\\s*:\\s*\\).*/\\ \\ tag: '${BUILD_NUMBER}'/g' values.yaml - rm values.yaml.bak - git add . *.yaml - git commit -m "Jenkins commit: ${BUILD_NUMBER}" - git remote rm origin - git remote add origin https://${GIT_USER_ACCOUNT}:${GITHUB_API_TOKEN}@github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy.git > /dev/null 2>&1 - git push origin master - """ - } - } - - } - - } - - } -} diff --git a/chart/cloudnativesampleapp/Chart.yaml b/chart/cloudnativesampleapp/Chart.yaml deleted file mode 100644 index 7f389f2..0000000 --- a/chart/cloudnativesampleapp/Chart.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: v1 -description: A Helm chart for Kubernetes -name: cloudnativesampleapp -version: 1.0.0 \ No newline at end of file diff --git a/chart/cloudnativesampleapp/deployment.yaml b/chart/cloudnativesampleapp/deployment.yaml new file mode 100644 index 0000000..a9e17d8 --- /dev/null +++ b/chart/cloudnativesampleapp/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: "greetings-deployment" +spec: + replicas: 1 + revisionHistoryLimit: 1 + template: + metadata: + labels: + app: "greetings" + spec: + containers: + - name: "greeting" + image: "ibmcase/greeting:1" + imagePullPolicy: "IfNotPresent" + env: + - name: PORT + value: "9080" + - name: APPLICATION_NAME + value: "greetings" diff --git a/chart/cloudnativesampleapp/service.yaml b/chart/cloudnativesampleapp/service.yaml new file mode 100644 index 0000000..190253c --- /dev/null +++ b/chart/cloudnativesampleapp/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: "greeting-service" +spec: + type: NodePort + ports: + - name: http + port: 9080 + selector: + app: "greetings" diff --git a/chart/cloudnativesampleapp/templates/basedeployment.yaml b/chart/cloudnativesampleapp/templates/basedeployment.yaml deleted file mode 100644 index 9156ba2..0000000 --- a/chart/cloudnativesampleapp/templates/basedeployment.yaml +++ /dev/null @@ -1,36 +0,0 @@ -{{ if .Values.base.enabled }} -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: "{{ .Chart.Name }}-basedeployment" - labels: - chart: '{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}' -spec: - replicas: {{ .Values.base.replicaCount }} - revisionHistoryLimit: {{ .Values.revisionHistoryLimit }} - template: - metadata: - labels: - app: "{{ .Chart.Name }}-selector" - version: "base" - spec: - containers: - - name: "{{ .Chart.Name }}" - image: "{{ .Values.image.repository }}:{{ .Values.base.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} -{{ if .Values.istio.enabled }} -{{ else }} - readinessProbe: - httpGet: - path: /health - port: 8080 - initialDelaySeconds: 20 -{{ end }} - resources: - requests: - cpu: "{{ .Values.image.resources.requests.cpu }}" - memory: "{{ .Values.image.resources.requests.memory }}" - env: - - name: PORT - value: "{{ .Values.service.servicePort }}" -{{ end }} \ No newline at end of file diff --git a/chart/cloudnativesampleapp/templates/deployment.yaml b/chart/cloudnativesampleapp/templates/deployment.yaml deleted file mode 100644 index c651f0c..0000000 --- a/chart/cloudnativesampleapp/templates/deployment.yaml +++ /dev/null @@ -1,36 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: "{{ .Chart.Name }}-deployment" - labels: - chart: '{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}' -spec: - replicas: {{ .Values.replicaCount }} - revisionHistoryLimit: {{ .Values.revisionHistoryLimit }} - template: - metadata: - labels: - app: "{{ .Chart.Name }}-selector" - version: "current" - spec: - containers: - - name: "{{ .Chart.Name }}" - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} -{{ if .Values.istio.enabled }} -{{ else }} - readinessProbe: - httpGet: - path: /health - port: 8080 - initialDelaySeconds: 20 -{{ end }} - resources: - requests: - cpu: "{{ .Values.image.resources.requests.cpu }}" - memory: "{{ .Values.image.resources.requests.memory }}" - env: - - name: PORT - value: "{{ .Values.service.servicePort }}" - - name: APPLICATION_NAME - value: "{{ .Release.Name }}" diff --git a/chart/cloudnativesampleapp/templates/hpa.yaml b/chart/cloudnativesampleapp/templates/hpa.yaml deleted file mode 100644 index 5fdefe9..0000000 --- a/chart/cloudnativesampleapp/templates/hpa.yaml +++ /dev/null @@ -1,27 +0,0 @@ -{{ if .Values.hpa.enabled }} -{{ if and (eq .Capabilities.KubeVersion.Major "1") (ge .Capabilities.KubeVersion.Minor "8") }} -apiVersion: autoscaling/v2beta1 -{{ else }} -apiVersion: autoscaling/v2alpha1 -{{ end }} -kind: HorizontalPodAutoscaler -metadata: - name: "{{ .Chart.Name }}-hpa-policy" - namespace: default -spec: - scaleTargetRef: - apiVersion: apps/v1beta1 - kind: Deployment - name: "{{ .Chart.Name }}-deployment" - minReplicas: {{ .Values.hpa.minReplicas }} - maxReplicas: {{ .Values.hpa.maxReplicas }} - metrics: - - type: Resource - resource: - name: cpu - targetAverageUtilization: {{ .Values.hpa.metrics.cpu.targetAverageUtilization }} - - type: Resource - resource: - name: memory - targetAverageUtilization: {{ .Values.hpa.metrics.memory.targetAverageUtilization }} -{{ end }} \ No newline at end of file diff --git a/chart/cloudnativesampleapp/templates/istio.yaml b/chart/cloudnativesampleapp/templates/istio.yaml deleted file mode 100644 index 7ee841b..0000000 --- a/chart/cloudnativesampleapp/templates/istio.yaml +++ /dev/null @@ -1,19 +0,0 @@ -{{ if .Values.istio.enabled }} -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: "{{ .Chart.Name }}-default" -spec: - destination: - name: "{{ .Chart.Name }}-service" - precedence: 1 - route: - - labels: - version: "current" - weight: {{ .Values.istio.weight }} -{{ if .Values.base.enabled }} - - labels: - version: "base" - weight: {{ .Values.base.weight }} -{{ end }} -{{ end }} \ No newline at end of file diff --git a/chart/cloudnativesampleapp/templates/service.yaml b/chart/cloudnativesampleapp/templates/service.yaml deleted file mode 100644 index 8e8cdb1..0000000 --- a/chart/cloudnativesampleapp/templates/service.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: "{{ .Chart.Name }}-service" - labels: - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" -spec: - type: {{ .Values.service.type }} - ports: - - name: http - port: {{ .Values.service.servicePort }} - selector: - app: "{{ .Chart.Name }}-selector" \ No newline at end of file diff --git a/chart/cloudnativesampleapp/values.yaml b/chart/cloudnativesampleapp/values.yaml deleted file mode 100644 index 26fb1d2..0000000 --- a/chart/cloudnativesampleapp/values.yaml +++ /dev/null @@ -1,34 +0,0 @@ -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. -replicaCount: 1 -revisionHistoryLimit: 1 -image: - repository: ibmcase/greeting - tag: v1.0.0 - pullPolicy: IfNotPresent - resources: - requests: - cpu: 200m - memory: 300Mi -service: - name: Node - type: NodePort - servicePort: 8080 -hpa: - enabled: false - minReplicas: 1 - maxReplicas: 2 - metrics: - cpu: - targetAverageUtilization: 70 - memory: - targetAverageUtilization: 70 -base: - enabled: false - replicaCount: 1 - image: - tag : v0.9.9 - weight: 100 -istio: - enabled: false - weight: 100 diff --git a/scripts/api_tests.sh b/scripts/api_tests.sh deleted file mode 100644 index 7600d52..0000000 --- a/scripts/api_tests.sh +++ /dev/null @@ -1,44 +0,0 @@ -function parse_arguments() { - # MICROSERVICE_HOST - if [ -z "${MICROSERVICE_HOST}" ]; then - echo "MICROSERVICE_HOST not set. Using parameter \"$1\""; - MICROSERVICE_HOST=$1; - fi - - if [ -z "${MICROSERVICE_HOST}" ]; then - echo "MICROSERVICE_HOST not set. Using default key"; - MICROSERVICE_HOST=127.0.0.1; - fi - - # MICROSERVICE_PORT - if [ -z "${MICROSERVICE_PORT}" ]; then - echo "MICROSERVICE_PORT not set. Using parameter \"$2\""; - MICROSERVICE_PORT=$2; - fi - - if [ -z "${MICROSERVICE_PORT}" ]; then - echo "MICROSERVICE_PORT not set. Using default key"; - MICROSERVICE_PORT=8080; - fi - - echo "Using http://${MICROSERVICE_HOST}:${MICROSERVICE_PORT}" -} - -function greeting() { - CURL=$(curl -s --max-time 5 http://${MICROSERVICE_HOST}:${MICROSERVICE_PORT}/greeting?name=John); - echo "Greeting service returns \"${CURL}\" message" - - if [ -z "${CURL}" ] || [ ! "${CURL}" -gt "0" ]; then - echo "greeting: ❌ could not get any message"; - exit 1; - else - echo "greeting received: ✅"; - fi -} - -# Setup -parse_arguments $1 $2 - -# API Tests -echo "Starting Tests" -greeting diff --git a/scripts/health_check.sh b/scripts/health_check.sh deleted file mode 100644 index 6099502..0000000 --- a/scripts/health_check.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -function is_healthy { - curl -s ${HEALTH_URL} | awk -F'"' '/status/{ print $(NF-1) }'; -} - -URL="$1"; -HEALTH_CHECK="health"; - -if [ -z "$URL" ]; then - URL="http://localhost:8080" - echo "No URL provided! Using ${URL}" -fi - -HEALTH_URL="${URL}/${HEALTH_CHECK}" - -echo "Health Check on \"${HEALTH_URL}\""; - -HEALTHY=$(is_healthy) - -echo -n "Waiting for service to be ready" - -until [ -n "$HEALTHY" ] && [ "${HEALTHY}" == 'UP' ]; do - HEALTHY=$(is_healthy); - echo -n .; - sleep 1; -done - -printf "\nService is ready\n" diff --git a/scripts/install_minikube_and_helm.sh b/scripts/install_minikube_and_helm.sh deleted file mode 100644 index 8cf570b..0000000 --- a/scripts/install_minikube_and_helm.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -# Install socat, which is needed for port-forwarding -sudo apt-get update -sudo apt-get install socat - -# Download kubectl, which is a requirement for using minikube. -curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ - -# Download minikube. -curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.35.0/minikube-linux-amd64 && chmod +x minikube && sudo cp minikube /usr/local/bin/ && rm minikube -# Start Minikube -sudo minikube start --vm-driver=none --kubernetes-version=v1.13.0 -# Update minikube directory permissions -sudo chown -R travis: /home/travis/.minikube/ -# Fix the kubectl context, as it's often stale. -minikube update-context -# Getting ip for testing -minikube ip -# Wait for Minikube to be up and ready. -JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done - -# Download helm -curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh && chmod 700 get_helm.sh && ./get_helm.sh && rm get_helm.sh -# Create Tiller Service Account -kubectl -n kube-system create sa tiller && kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller -# Install Helm on Minikube -helm init --service-account tiller -# Wait for helm to be ready -until helm list; do echo "waiting for helm to be ready"; sleep 1; done - -# Add incubator and bluecompute-charts Helm repos -helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator -helm repo add ibmcase-charts https://raw.githubusercontent.com/ibm-cloud-architecture/refarch-cloudnative-kubernetes/spring/docs/charts - -# Get cluster info -kubectl cluster-info diff --git a/scripts/push.sh b/scripts/push.sh deleted file mode 100644 index 83c31b1..0000000 --- a/scripts/push.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -setup_git() { - git config --global user.email "travis@travis-ci.org" - git config --global user.name "Travis CI" -} - -commit_values_yaml() { - git clone https://github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy.git - git checkout master - cd cloudnative_sample_app_deploy - cd chart/cloudnativesampleapp - sed -i.bak '/^image/,/^service/ s/\(\s*tag\s*:\s*\).*/\ \ tag: '$COMMIT'/g' values.yaml - rm values.yaml.bak - git add . *.yaml - git commit --message "Travis build: $TRAVIS_BUILD_NUMBER" -} - -push_files() { - git remote rm origin - git remote add origin https://${GH_USER}:${GH_TOKEN}@github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy.git > /dev/null 2>&1 - git push origin master --quiet -} - -setup_git -commit_values_yaml - -if [ $? -eq 0 ]; then - echo "Uploading to GitHub" - push_files -else - echo "No changes" -fi