pub-dns/Jenkinsfile

237 lines
6.3 KiB
Groovy

pipeline {
agent {
label 'pi501.in.thelinuxpro.net'
}
stages {
stage("verify tooling") {
steps {
sh '''
docker version
docker info
docker compose version
'''
}
}
stage("Build Containers and push to registry") {
steps {
script {
def status_p = sh(returnStatus: true, script: 'docker images | grep bind9-primary | grep $(grep image docker-compose.yml | grep primary | awk -F\':\' \'{ print $4 }\')')
def status_s = sh(returnStatus: true, script: 'docker images | grep bind9-secondary | grep $(grep image docker-compose.yml | grep secondary | awk -F\':\' \'{ print $4 }\')')
def status_d = sh(returnStatus: true, script: 'docker images | grep pubdnsdist | grep $(grep image docker-compose.yml | grep pubdnsdist | awk -F\':\' \'{ print $4 }\')')
if (status_p != 0) {
sh 'docker compose build primary --push'
} else {
echo "Primary Image version already exists, no need to rebuild."
}
if (status_s != 0) {
sh 'docker compose build secondary1 --push'
} else {
echo "Secondary Image version already exists, no need to rebuild."
}
if (status_s != 0) {
sh 'docker compose build secondary2 --push'
} else {
echo "Secondary Image version already exists, no need to rebuild."
}
if (status_d != 0) {
sh 'docker compose build pubdnsdist1 --push'
} else {
echo "pubdnsdist Image version already exists, no need to rebuild."
}
if (status_d != 0) {
sh 'docker compose build pubdnsdist2 --push'
} else {
echo "pubdnsdist Image version already exists, no need to rebuild."
}
}
}
}
stage('Stop primary container') {
steps {
script {
def status_p = sh(returnStatus: true, script: 'grep $(docker compose ps | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status_p != 0) {
sh 'docker compose down'
sh 'sleep 5'
} else {
echo 'skip'
}
}
}
}
stage('Start primary container') {
steps {
script {
def status_p = sh(returnStatus: true, script: 'grep $(docker compose ps | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status_p != 0) {
sh 'docker compose down'
sh 'docker compose up -d --no-color primary'
sh 'docker compose ps'
} else {
echo 'skip'
}
}
}
}
stage('Create contexts') {
steps {
sh 'docker context ls | grep pi502 || docker context create pi502 --docker "host=ssh://pi502.in.thelinuxpro.net"'
sh 'docker context ls | grep pi503 || docker context create pi503 --docker "host=ssh://pi503.in.thelinuxpro.net"'
}
}
stage('Stop secondary container 1') {
steps {
script {
def status_s = sh(returnStatus: true, script: 'grep $(docker --context pi502 compose ps | grep ns1 | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status_s != 0) {
sh 'docker --context pi502 compose down secondary1'
sh 'sleep 5'
} else {
echo 'skip'
}
}
}
}
stage('Start secondary container 1') {
steps {
script {
def status_s = sh(returnStatus: true, script: 'grep $(docker --context pi502 compose ps | grep ns1 | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status_s != 0) {
sh 'docker --context pi502 compose up -d --no-color secondary1'
sh 'docker --context pi502 compose ps'
} else {
echo 'skip'
}
}
}
}
stage('Stop secondary container 2') {
steps {
script {
def status_s = sh(returnStatus: true, script: 'grep $(docker --context pi503 compose ps | grep ns2 | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status_s != 0) {
sh 'docker --context pi503 compose down secondary2'
sh 'sleep 5'
} else {
echo 'skip'
}
}
}
}
stage('Start secondary container 2') {
steps {
script {
def status_s = sh(returnStatus: true, script: 'grep $(docker --context pi503 compose ps | grep ns2 | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status_s != 0) {
sh 'docker --context pi503 compose up -d --no-color secondary2'
sh 'docker --context pi503 compose ps'
} else {
echo 'skip'
}
}
}
}
stage('Stop pubdnsdist container 1') {
steps {
script {
def status = sh(returnStatus: true, script: 'grep $(docker --context pi502 compose ps | grep dnsdist1 | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status != 0) {
sh 'docker --context pi502 compose down pubdnsdist1'
sh 'sleep 5'
} else {
echo 'skip'
}
}
}
}
stage('Start pubdnsdist container 1') {
steps {
script {
def status = sh(returnStatus: true, script: 'grep $(docker --context pi502 compose ps | grep dnsdist1 | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status != 0) {
sh 'docker --context pi502 compose up pubdnsdist1 -d'
sh 'docker --context pi502 compose ps'
sh 'sleep 3'
sh 'docker --context pi502 compose logs'
} else {
echo 'skip'
}
}
}
}
stage('Stop pubdnsdist container 2') {
steps {
script {
def status = sh(returnStatus: true, script: 'grep $(docker --context pi503 compose ps | grep dnsdist2 | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status != 0) {
sh 'docker --context pi503 compose down pubdnsdist2'
sh 'sleep 5'
} else {
echo 'skip'
}
}
}
}
stage('Start pubdnsdist container 2') {
steps {
script {
def status = sh(returnStatus: true, script: 'grep $(docker --context pi503 compose ps | grep dnsdist2 | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status != 0) {
sh 'docker --context pi503 compose up pubdnsdist2 -d'
sh 'docker --context pi503 compose ps'
sh 'sleep 3'
sh 'docker --context pi503 compose logs'
} else {
echo 'skip'
}
}
}
}
// stage('Integration Tests') {
// steps {
// sh 'rm -rf test/results'
// sh 'mkdir -p test/results/integration'
// sh 'bats -F junit test/integration/dns/**/*.bat test/integration/dns/**/**/*.bat > test/results/integration/dns.xml'
// }
// }
// }
// post {
// always {
// archiveArtifacts artifacts: 'test/results/**/*.xml', fingerprint: true
// junit 'test/results/**/*.xml'
// sh 'rm -rf test/results'
// }
}
}