Commit e047fb4c authored by joonas lume's avatar joonas lume
Browse files

Add elasticsearch deployment

parent e2597c26
#!/usr/bin/env groovy
node {
checkout scm
common = load 'common.groovy'
}
pipeline {
agent any
parameters {
booleanParam(name: 'Recreate', defaultValue: false, description: 'Delete and create VM')
string(name: 'ElasticSearchVersion', defaultValue: '7.8.0', description: 'ElasticSearch version', trim: true)
}
environment {
SSH = 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
SCP = 'scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
TLD = 'riaint.ee'
NODE = "${env.JOB_BASE_NAME}-01.dev.${TLD}"
PROJECT_NAME = 'jut'
PROJECT_PATH = "${PROJECT_NAME}/${env.JOB_BASE_NAME}" //terrafrom VM project full path
}
options {
ansiColor('xterm')
buildDiscarder(logRotator(numToKeepStr: '20'))
disableConcurrentBuilds()
timestamps()
}
stages {
stage('Terraform destroy') {
when {
expression { params.Recreate == true }
}
steps {
build job: "Terraform destroy", parameters: [[$class: 'StringParameterValue', name: 'Project', value: "${PROJECT_PATH}"]]
}
}
stage('Terraform create') {
when {
expression { params.Recreate == true }
}
steps {
build job: "Terraform create", parameters: [[$class: 'StringParameterValue', name: 'Project', value: "${PROJECT_PATH}"]]
}
}
stage('apt update and apt dist-upgrade') {
when {
expression { params.Recreate == true }
}
steps {
script {
timeout(10) {
build job: "Salt apt update and apt dist-upgrade", parameters: [
[$class: "StringParameterValue", name: "targetname", value: "${NODE}"]
]
}
}
}
}
stage('Install package') {
when {
expression { params.Recreate == true }
}
steps {
script {
build job: "Salt Install Package", parameters: [
[$class: 'StringParameterValue', name: 'targetname', value: "${NODE}"],
[$class: 'StringParameterValue', name: 'pkgname', value: "confd"]
]
}
}
}
stage("Install ES") {
when {
expression { params.Recreate == true }
}
steps {
script {
command = """
cd /tmp
echo '"'"'deb [arch=amd64] http://apt.tt.kit/ubuntu-elk-7 stable main '"'"' | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo wget -O - http://apt.tt.kit/ubuntu/apt-gpg-keys/ELK-GPG-KEY.pub | sudo apt-key add -
sudo apt-get update
sudo apt-get install nginx -y
sudo apt-get install elasticsearch=${params.ElasticSearchVersion} -y
sudo update-rc.d elasticsearch defaults 95 10
"""
sh "$SSH riajenk@$NODE '$command'"
}
}
}
stage('Python dependencies install') {
when {
expression { params.Recreate == true }
}
steps {
script {
ssh_script = """
set -x
set -e
sudo apt-get install -y python3-pip jq
pip3 install --user pipenv
"""
sh "$SSH riajenk@${NODE} '$ssh_script'"
}
}
}
stage('Start Elasticsearch') {
when {
expression { params.Recreate == true }
}
steps {
script {
ssh_start_es = '''
sudo systemctl start elasticsearch
'''
sh "$SSH riajenk@${NODE} '$ssh_start_es'"
}
}
}
stage('Check Elasticsearch health') {
when {
expression { params.Recreate == true }
}
steps {
script {
ssh_build_cmd = '''
elasticsearchHost="http://localhost:9200"
echo "Elasticsearch health check on ${HOSTNAME}:"
n=0
until [ "$n" -ge 60 ]
do
$(curl --output /dev/null --insecure --silent --head --fail "$elasticsearchHost") && echo "Elasticsearch is up and running" && exit 0 && break
n=$((n+1))
echo "Elasticsearch is unavailable - sleeping"
sleep 10
done
echo "Elasticsearch did not start on time. Exiting ..."
exit 1
'''
ELK_HOST = common.host2ip("${NODE}")
sh "$SSH riajenk@$ELK_HOST '$ssh_build_cmd'"
}
}
}
}
post {
always {
cleanWs()
}
fixed {
echo "Build back to normal"
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment