[AETHER-423] Implement the Jenkins pipeline to deploy TOST
- Disabled all Jenkins job, only store in git system.
- Those files will be moved out once Aether related infra are ready.
Change-Id: I19983494c970dffce08b07fbfcf4989c15fd7698
diff --git a/jjb/pipeline/tost-deploy-fluentbit.groovy b/jjb/pipeline/tost-deploy-fluentbit.groovy
new file mode 100644
index 0000000..17dbf04
--- /dev/null
+++ b/jjb/pipeline/tost-deploy-fluentbit.groovy
@@ -0,0 +1,95 @@
+pipeline {
+ agent {
+ docker {
+ image 'ubuntu:18.04'
+ args '-u root:sudo'
+ }
+ }
+ environment {
+ KUBECONFIG = credentials("${params.k8s_config}")
+ git_password = credentials("${params.git_password_env}")
+ rancher_token = credentials("${params.rancher_api_env}")
+ }
+ stages {
+ stage('Install tools') {
+ steps {
+ sh '''
+ set -x
+ apt-get update -y
+ apt-get install -y curl wget jq git
+
+ # Install kubectl
+ curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl"
+ chmod +x ./kubectl
+ mv ./kubectl /usr/local/bin/kubectl
+
+ # Install rancher
+ wget https://github.com/rancher/cli/releases/download/v2.4.5/rancher-linux-amd64-v2.4.5.tar.gz
+ tar -xvf rancher-linux-amd64-v2.4.5.tar.gz
+ mv rancher-v2.4.5/rancher /usr/local/bin
+
+ rm rancher-linux-amd64-v2.4.5.tar.gz
+ rm -rf rancher-v2.4.5
+ # Test Kubectl & Rancher
+ KUBE_CONFIG=$KUBECONFIG kubectl get nodes
+ rancher --version
+ '''
+ }
+ }
+ stage('Clone Config Repo') {
+ options {
+ timeout(time: 10, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ git clone https://${git_user}:${git_password}@${git_server}/${git_repo}
+ if [ ! -z ${config_review} ] && [ ! -z ${config_patchset} ]; then
+ cd ${git_repo}
+ CFG_LAST2=$(echo ${config_review} | tail -c 3)
+ git fetch "https://${git_user}:${git_password}@${git_server}/a/${git_repo}" refs/changes/${CFG_LAST2}/${config_review}/${config_patchset} && git checkout FETCH_HEAD
+ git checkout FETCH_HEAD
+ cd ..
+ fi
+ '''
+ }
+ }
+ stage('Login Rancher') {
+ steps {
+ sh '''
+ rancher login ${rancher_server} --token ${rancher_token} --context ${rancher_context}:${rancher_project}
+ '''
+ }
+ }
+ stage('Uninstall Apps') {
+ options {
+ timeout(time: 90, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ for app in $(rancher apps ls -q | grep -E '(fluentbit)'); do rancher apps delete $app; done
+
+ until [ "$(rancher apps ls -q | grep -E '(fluentbit)')" = "" ]; do echo "wait deleted apps"; rancher apps ls ; sleep 1; done
+ '''
+ }
+ }
+ stage('Install apps') {
+ options {
+ timeout(time: 600, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ cd ${git_repo}/deployment-configs/aether/apps/${config_env}/
+ until rancher apps install --answers fluentbit-ans.yml --namespace ${fluentbit_ns} cattle-global-data:fluent-fluent-bit fluentbit; do :; done
+ apps=$(rancher apps -q | grep fluentbit)
+ for app in $apps; do until rancher wait $app --timeout 20; do :; done; rancher apps ls; done
+ '''
+ }
+ }
+
+ }
+ post {
+ always {
+ cleanWs()
+ }
+ }
+}
diff --git a/jjb/pipeline/tost-deploy-onos.groovy b/jjb/pipeline/tost-deploy-onos.groovy
new file mode 100644
index 0000000..d2c062a
--- /dev/null
+++ b/jjb/pipeline/tost-deploy-onos.groovy
@@ -0,0 +1,131 @@
+pipeline {
+ agent {
+ docker {
+ image 'ubuntu:18.04'
+ args '-u root:sudo'
+ }
+ }
+ environment {
+ KUBECONFIG = credentials("${params.k8s_config}")
+ registry_password = credentials("${params.registry_password_env}")
+ git_password = credentials("${params.git_password_env}")
+ onos_password = credentials("${params.onos_password}")
+ rancher_token = credentials("${params.rancher_api_env}")
+ }
+ stages {
+ stage('Install tools') {
+ steps {
+ sh '''
+ set -x
+ apt-get update -y
+ apt-get install -y curl wget jq git
+
+ # Install kubectl
+ curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl"
+ chmod +x ./kubectl
+ mv ./kubectl /usr/local/bin/kubectl
+
+ # Install rancher
+ wget https://github.com/rancher/cli/releases/download/v2.4.5/rancher-linux-amd64-v2.4.5.tar.gz
+ tar -xvf rancher-linux-amd64-v2.4.5.tar.gz
+ mv rancher-v2.4.5/rancher /usr/local/bin
+
+ rm rancher-linux-amd64-v2.4.5.tar.gz
+ rm -rf rancher-v2.4.5
+
+ # Test Kubectl & Rancher
+ KUBE_CONFIG=$KUBECONFIG kubectl get nodes
+ rancher --version
+ '''
+ }
+ }
+ stage('Clone Config Repo') {
+ options {
+ timeout(time: 10, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ git clone https://${git_user}:${git_password}@${git_server}/${git_repo}
+ if [ ! -z ${config_review} ] && [ ! -z ${config_patchset} ]; then
+ cd ${git_repo}
+ CFG_LAST2=$(echo ${config_review} | tail -c 3)
+ git fetch "https://${git_user}:${git_password}@${git_server}/a/${git_repo}" refs/changes/${CFG_LAST2}/${config_review}/${config_patchset} && git checkout FETCH_HEAD
+ git checkout FETCH_HEAD
+ echo "config.review: ${config_review}" >> deployment-configs/aether/apps/${config_env}/onos-ans.yml
+ echo "config.patchset: ${config_patchset}" >> deployment-configs/aether/apps/${config_env}/onos-ans.yml
+ cd ..
+ fi
+ '''
+ }
+ }
+ stage('Login Rancher') {
+ steps {
+ sh '''
+ rancher login ${rancher_server} --token ${rancher_token} --context ${rancher_context}:${rancher_project}
+ '''
+ }
+ }
+ stage('Push Secrets') {
+ steps {
+ sh '''
+
+ rancher namespaces ls | grep ${onos_ns} || rancher namespaces create ${onos_ns}
+
+ kubectl -n ${onos_ns} delete secret git-secret --ignore-not-found=true
+ kubectl -n ${onos_ns} create secret generic git-secret --from-literal=username=${git_user} --from-literal=password=${git_password}
+ kubectl -n ${onos_ns} delete secret aether-registry-credential --ignore-not-found=true
+ kubectl -n ${onos_ns} create secret docker-registry aether-registry-credential --docker-server=${registry_server} --docker-username=${registry_user} --docker-password=${registry_password}
+
+
+
+ kubectl -n ${onos_ns} delete secret onos-secret --ignore-not-found=true
+ kubectl -n ${onos_ns} create secret generic onos-secret --from-literal=username=${onos_user} --from-literal=password=${onos_password}
+ '''
+ }
+ }
+
+ stage('Uninstall Apps') {
+ options {
+ timeout(time: 90, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ for app in $(rancher apps ls -q | grep -E '(onos-tost)'); do rancher apps delete $app; done
+
+ until [ "$(rancher apps ls -q | grep -E '(onos-tost)')" = "" ]; do echo "wait deleted apps"; rancher apps ls ; sleep 1; done
+ '''
+ }
+ }
+ stage('Remove PVC') {
+ options {
+ timeout(time: 300, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ pvcs=$(kubectl -n onos-tost get pvc -lapp=onos-tost-atomix -o name)
+ for pv in $pvcs; do kubectl -n onos-tost delete $pv; done
+ '''
+ }
+ }
+ stage('Install apps') {
+ options {
+ timeout(time: 600, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ cd ${git_repo}/deployment-configs/aether/apps/${config_env}/
+
+ until rancher apps install --answers onos-ans.yml --namespace ${onos_ns} cattle-global-data:${onos_catalog_name}-onos-tost onos-tost; do :; done
+ apps=$(rancher apps -q | grep onos-tost)
+ for app in $apps; do until rancher wait $app --timeout 20; do :; done; rancher apps ls; done
+ '''
+ }
+ }
+
+ }
+ post {
+ always {
+ cleanWs()
+ }
+ }
+}
diff --git a/jjb/pipeline/tost-deploy-stratum.groovy b/jjb/pipeline/tost-deploy-stratum.groovy
new file mode 100644
index 0000000..24a777b
--- /dev/null
+++ b/jjb/pipeline/tost-deploy-stratum.groovy
@@ -0,0 +1,116 @@
+pipeline {
+ agent {
+ docker {
+ image 'ubuntu:18.04'
+ args '-u root:sudo'
+ }
+ }
+ environment {
+ KUBECONFIG = credentials("${params.k8s_config}")
+ registry_password = credentials("${params.registry_password_env}")
+ git_password = credentials("${params.git_password_env}")
+ rancher_token = credentials("${params.rancher_api_env}")
+ }
+ stages {
+ stage('Install tools') {
+ steps {
+ sh '''
+ set -x
+ apt-get update -y
+ apt-get install -y curl wget jq git
+
+ # Install kubectl
+ curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl"
+ chmod +x ./kubectl
+ mv ./kubectl /usr/local/bin/kubectl
+
+ # Install rancher
+ wget https://github.com/rancher/cli/releases/download/v2.4.5/rancher-linux-amd64-v2.4.5.tar.gz
+ tar -xvf rancher-linux-amd64-v2.4.5.tar.gz
+ mv rancher-v2.4.5/rancher /usr/local/bin
+
+ rm rancher-linux-amd64-v2.4.5.tar.gz
+ rm -rf rancher-v2.4.5
+ # Test Kubectl & Rancher
+ KUBE_CONFIG=$KUBECONFIG kubectl get nodes
+ rancher --version
+ '''
+ }
+ }
+ stage('Clone Config Repo') {
+ options {
+ timeout(time: 10, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ git clone https://${git_user}:${git_password}@${git_server}/${git_repo}
+ if [ ! -z ${config_review} ] && [ ! -z ${config_patchset} ]; then
+ cd ${git_repo}
+ CFG_LAST2=$(echo ${config_review} | tail -c 3)
+ git fetch "https://${git_user}:${git_password}@${git_server}/a/${git_repo}" refs/changes/${CFG_LAST2}/${config_review}/${config_patchset} && git checkout FETCH_HEAD
+ git checkout FETCH_HEAD
+ echo "config.review: ${config_review}" >> deployment-configs/aether/apps/${config_env}/stratum-ans.yml
+ echo "config.patchset: ${config_patchset}" >> deployment-configs/aether/apps/${config_env}/stratum-ans.yml
+ cd ..
+ fi
+
+ '''
+ }
+ }
+ stage('Login Rancher') {
+ steps {
+ sh '''
+ rancher login ${rancher_server} --token ${rancher_token} --context ${rancher_context}:${rancher_project}
+ '''
+ }
+ }
+ stage('Push Secrets') {
+ steps {
+ sh '''
+
+ rancher namespaces ls | grep ${stratum_ns} || rancher namespaces create ${stratum_ns}
+
+ kubectl -n ${stratum_ns} delete secret git-secret --ignore-not-found=true
+ kubectl -n ${stratum_ns} create secret generic git-secret --from-literal=username=${git_user} --from-literal=password=${git_password}
+ kubectl -n ${stratum_ns} delete secret aether-registry-credential --ignore-not-found=true
+ kubectl -n ${stratum_ns} create secret docker-registry aether-registry-credential --docker-server=${registry_server} --docker-username=${registry_user} --docker-password=${registry_password}
+
+
+ '''
+ }
+ }
+
+ stage('Uninstall Apps') {
+ options {
+ timeout(time: 90, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ for app in $(rancher apps ls -q | grep -E '(stratum)'); do rancher apps delete $app; done
+
+ until [ "$(rancher apps ls -q | grep -E '(stratum)')" = "" ]; do echo "wait deleted apps"; rancher apps ls ; sleep 1; done
+ '''
+ }
+ }
+ stage('Install apps') {
+ options {
+ timeout(time: 600, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ cd ${git_repo}/deployment-configs/aether/apps/${config_env}/
+ until rancher apps install --answers stratum-ans.yml --namespace ${stratum_ns} cattle-global-data:${stratum_catalog_name}-stratum stratum; do :; done
+
+ apps=$(rancher apps -q | grep stratum)
+ for app in $apps; do until rancher wait $app --timeout 20; do :; done; rancher apps ls; done
+ '''
+ }
+ }
+
+ }
+ post {
+ always {
+ cleanWs()
+ }
+ }
+}
diff --git a/jjb/pipeline/tost-deploy-telegraf.groovy b/jjb/pipeline/tost-deploy-telegraf.groovy
new file mode 100644
index 0000000..aa5daa1
--- /dev/null
+++ b/jjb/pipeline/tost-deploy-telegraf.groovy
@@ -0,0 +1,95 @@
+pipeline {
+ agent {
+ docker {
+ image 'ubuntu:18.04'
+ args '-u root:sudo'
+ }
+ }
+ environment {
+ KUBECONFIG = credentials("${params.k8s_config}")
+ git_password = credentials("${params.git_password_env}")
+ rancher_token = credentials("${params.rancher_api_env}")
+ }
+ stages {
+ stage('Install tools') {
+ steps {
+ sh '''
+ set -x
+ apt-get update -y
+ apt-get install -y curl wget jq git
+
+ # Install kubectl
+ curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl"
+ chmod +x ./kubectl
+ mv ./kubectl /usr/local/bin/kubectl
+
+ # Install rancher
+ wget https://github.com/rancher/cli/releases/download/v2.4.5/rancher-linux-amd64-v2.4.5.tar.gz
+ tar -xvf rancher-linux-amd64-v2.4.5.tar.gz
+ mv rancher-v2.4.5/rancher /usr/local/bin
+
+ rm rancher-linux-amd64-v2.4.5.tar.gz
+ rm -rf rancher-v2.4.5
+ # Test Kubectl & Rancher
+ KUBE_CONFIG=$KUBECONFIG kubectl get nodes
+ rancher --version
+ '''
+ }
+ }
+ stage('Clone Config Repo') {
+ options {
+ timeout(time: 10, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ git clone https://${git_user}:${git_password}@${git_server}/${git_repo}
+ if [ ! -z ${config_review} ] && [ ! -z ${config_patchset} ]; then
+ cd ${git_repo}
+ CFG_LAST2=$(echo ${config_review} | tail -c 3)
+ git fetch "https://${git_user}:${git_password}@${git_server}/a/${git_repo}" refs/changes/${CFG_LAST2}/${config_review}/${config_patchset} && git checkout FETCH_HEAD
+ git checkout FETCH_HEAD
+ cd ..
+ fi
+ '''
+ }
+ }
+ stage('Login Rancher') {
+ steps {
+ sh '''
+ rancher login ${rancher_server} --token ${rancher_token} --context ${rancher_context}:${rancher_project}
+ '''
+ }
+ }
+ stage('Uninstall Apps') {
+ options {
+ timeout(time: 90, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ for app in $(rancher apps ls -q | grep -E '(telegraf)'); do rancher apps delete $app; done
+
+ until [ "$(rancher apps ls -q | grep -E '(telegraf)')" = "" ]; do echo "wait deleted apps"; rancher apps ls ; sleep 1; done
+ '''
+ }
+ }
+ stage('Install apps') {
+ options {
+ timeout(time: 600, unit: "SECONDS")
+ }
+ steps {
+ sh '''
+ cd ${git_repo}/deployment-configs/aether/apps/${config_env}/
+ until rancher apps install --answers telegraf-ans.yml --namespace ${telegraf_ns} cattle-global-data:influxdata-telegraf telegraf; do :; done
+ apps=$(rancher apps -q | grep telegraf)
+ for app in $apps; do until rancher wait $app --timeout 20; do :; done; rancher apps ls; done
+ '''
+ }
+ }
+
+ }
+ post {
+ always {
+ cleanWs()
+ }
+ }
+}
diff --git a/jjb/pipeline/tost-deploy.groovy b/jjb/pipeline/tost-deploy.groovy
new file mode 100644
index 0000000..42961ff
--- /dev/null
+++ b/jjb/pipeline/tost-deploy.groovy
@@ -0,0 +1,108 @@
+pipeline {
+ agent {
+ docker {
+ image 'ubuntu:18.04'
+ args '-u root:sudo'
+ }
+ }
+ environment {
+ KUBECONFIG = credentials("${params.k8s_config}")
+ }
+ stages {
+ stage('Install tools') {
+ steps {
+ sh '''
+ set -x
+ apt-get update -y
+ apt-get install -y curl wget jq git
+
+ # Install kubectl
+ curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl"
+ chmod +x ./kubectl
+ mv ./kubectl /usr/local/bin/kubectl
+
+ # Test Kubectl & Rancher
+ kubectl get nodes
+ '''
+ }
+ }
+ stage('Parallel Stage') {
+ parallel {
+ stage('onos') {
+ steps {
+ sh(script: "date -u")
+ build(job: "${params.job_name}-onos")
+ }
+ }
+ stage('stratum') {
+ steps {
+ sh(script: "date -u")
+ build(job: "${params.job_name}-stratum")
+ }
+ }
+ stage('telegraf') {
+ steps {
+ sh(script: "date -u")
+ build(job: "${params.job_name}-telegraf")
+ }
+ }
+ }
+ }
+ stage('E2E Testing') {
+ options {
+ timeout(time: 120, unit: "SECONDS")
+ }
+ steps {
+ sh """
+ echo ${params.target_server}
+ timestamp=\$(date +%s)
+ if [ ! -z "${params.target_server}" ]; then
+ kubectl delete --wait=true ds -l test=e2e || true
+cat <<EOF > test.yaml
+apiVersion: apps/v1
+kind: DaemonSet
+metadata:
+ name: ping-test-\${timestamp}
+ labels:
+ test: e2e-\${timestamp}
+spec:
+ selector:
+ matchLabels:
+ test: e2e-\${timestamp}
+ template:
+ metadata:
+ labels:
+ test: e2e-\${timestamp}
+ spec:
+ hostNetwork: true
+ terminationGracePeriodSeconds: 5
+ initContainers:
+ - name: ping-test
+ image: alpine:3.12.0
+ command: ["sh", "-c", "until ping ${params.target_server} -c1 -W 4; do echo 'ping retry'; sleep 3; done;"]
+ containers:
+ - name: ping-test-wait
+ image: alpine:3.12.0
+ command: ["sh", "-c", "sleep 100000"]
+ restartPolicy: Always
+EOF
+ kubectl apply -f test.yaml
+ number=\$(kubectl get --no-headers ds -ltest=e2e-\${timestamp} -o custom-columns=':.status.desiredNumberScheduled')
+ echo "\${number}"
+ until [ \${number} -eq \$(kubectl get pods -l test=e2e-\${timestamp} --no-headers -o custom-columns=':.status.phase' | grep Running | wc -l) ]; do echo 'wait ping completed'; sleep 5; done;
+ fi
+ """
+ }
+ }
+ }
+ post {
+ always {
+ sh """
+ if [ ! -z "${params.target_server}" ]; then
+ kubectl delete -f test.yaml
+ fi
+ """
+ cleanWs()
+ }
+ }
+}