converts to declarative format
This commit is contained in:
parent
a6096db9da
commit
169b391455
@ -1,17 +1,44 @@
|
|||||||
#!groovy
|
#!groovy
|
||||||
|
|
||||||
// repository configuration
|
|
||||||
def repository = "registry.c.test-chamber-13.lan"
|
def repository = "registry.c.test-chamber-13.lan"
|
||||||
|
def repositoryCreds = "harbor-repository-creds"
|
||||||
|
|
||||||
// jenkins secrets
|
def workspace
|
||||||
def nordCreds = "nordvpn-login-creds"
|
def dockerFile
|
||||||
|
def nordCreds
|
||||||
|
def kubeNamespace
|
||||||
|
def kubeSecret
|
||||||
|
def nordURL
|
||||||
|
def openVPNConfig
|
||||||
|
def k8sSecret
|
||||||
|
|
||||||
// kubernetes configuration
|
def label = "kubernetes-${UUID.randomUUID().toString()}"
|
||||||
def kubeNamespace = "dl-automation"
|
def templateName = "pipeline-worker"
|
||||||
def kubeSecret = "openvpn"
|
pipeline {
|
||||||
|
agent {
|
||||||
|
kubernetes {
|
||||||
|
yaml functions.podYaml(
|
||||||
|
repo: repository,
|
||||||
|
templateName: templateName,
|
||||||
|
alpine: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// list of urls that return different nordVPN servers
|
stages {
|
||||||
def nordURLs = [
|
stage ('Initalize Jenkins') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
workspace = pwd()
|
||||||
|
// jenkins secrets
|
||||||
|
nordCreds = "nordvpn-login-creds"
|
||||||
|
|
||||||
|
// kubernetes configuration
|
||||||
|
kubeNamespace = "dl-automation"
|
||||||
|
kubeSecret = "openvpn"
|
||||||
|
|
||||||
|
// list of urls that return different nordVPN servers
|
||||||
|
def nordURLs = [
|
||||||
// canada
|
// canada
|
||||||
"https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:38,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}",
|
"https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:38,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}",
|
||||||
// france
|
// france
|
||||||
@ -28,12 +55,33 @@ def nordURLs = [
|
|||||||
"https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:153,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}",
|
"https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:153,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}",
|
||||||
// united kingdom
|
// united kingdom
|
||||||
"https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:38,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}",
|
"https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:38,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}",
|
||||||
]
|
]
|
||||||
// randomly select one from the list
|
|
||||||
def nordURL = nordURLs[Math.abs(new Random().nextInt() % [8])]
|
|
||||||
|
|
||||||
// script used to retrieve a nordVPN OpenVPN configuration from NordVPN
|
// randomly select one from the list
|
||||||
def openVPNConfigScript = """# Get OpenVPN Config
|
nordURL = nordURLs[Math.abs(new Random().nextInt() % [8])]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage ('Prepare Container') {
|
||||||
|
steps {
|
||||||
|
container ('alpine') {
|
||||||
|
script {
|
||||||
|
sh """
|
||||||
|
if [ ! -f "/usr/bin/curl" ] || [ ! -x "/usr/bin/curl" ]; then
|
||||||
|
apk add --no-cache curl
|
||||||
|
fi
|
||||||
|
if [ ! -f "/usr/bin/jq" ] || [ ! -x "/usr/bin/jq" ]; then
|
||||||
|
apk add --no-cache jq
|
||||||
|
fi
|
||||||
|
if [ ! -f "/bin/sed" ] || [ ! -x "/bin/sed" ]; then
|
||||||
|
apk add --no-cache sed
|
||||||
|
fi
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
openVPNConfig = sh(
|
||||||
|
returnStdout: true,
|
||||||
|
script: """# Get OpenVPN Config
|
||||||
curl \
|
curl \
|
||||||
--silent \
|
--silent \
|
||||||
--location \
|
--location \
|
||||||
@ -53,45 +101,16 @@ curl \
|
|||||||
--expression='s/auth-user-pass/auth-user-pass \\/etc\\/openvpn\\/client\\/openvpn-credentials.txt/' \
|
--expression='s/auth-user-pass/auth-user-pass \\/etc\\/openvpn\\/client\\/openvpn-credentials.txt/' \
|
||||||
| base64 -w 0
|
| base64 -w 0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def label = "kubernetes-${UUID.randomUUID().toString()}"
|
|
||||||
def templateName = "pipeline-worker"
|
|
||||||
podTemplate(
|
|
||||||
label: label,
|
|
||||||
name: templateName,
|
|
||||||
yaml: functions.podYaml(
|
|
||||||
repo: repository,
|
|
||||||
templateName: templateName,
|
|
||||||
alpine: true
|
|
||||||
)
|
)
|
||||||
) {
|
withCredentials(
|
||||||
node (label) {
|
[
|
||||||
def workspace = pwd()
|
string(
|
||||||
|
|
||||||
stage ("Prepare Container") {
|
|
||||||
container ("alpine") {
|
|
||||||
sh """
|
|
||||||
apk add --no-cache curl jq sed
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def openVPNConfig
|
|
||||||
stage ("Get Remote OpenVPN Config") {
|
|
||||||
container ("alpine") {
|
|
||||||
openVPNConfig = sh(
|
|
||||||
returnStdout: true,
|
|
||||||
script: openVPNConfigScript
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def k8sSecret
|
|
||||||
stage ("Compile Secret") {
|
|
||||||
withCredentials([string(
|
|
||||||
credentialsId: nordCreds,
|
credentialsId: nordCreds,
|
||||||
variable: "NORD_CREDS",
|
variable: "NORD_CREDS",
|
||||||
)]) {
|
)
|
||||||
|
]
|
||||||
|
) {
|
||||||
|
|
||||||
k8sSecret = """apiVersion: v1
|
k8sSecret = """apiVersion: v1
|
||||||
kind: Secret
|
kind: Secret
|
||||||
metadata:
|
metadata:
|
||||||
@ -103,19 +122,37 @@ data:
|
|||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
functions.createSecret(
|
stage ('Create Secret') {
|
||||||
|
steps {
|
||||||
|
container ('alpine') {
|
||||||
|
script {
|
||||||
|
declarativeFunctions.createSecret(
|
||||||
kubeAuth: "k8s-dl-automation-access",
|
kubeAuth: "k8s-dl-automation-access",
|
||||||
kubeURL: "https://kubernetes.test-chamber-13.lan:6443",
|
kubeURL: "https://kubernetes.test-chamber-13.lan:6443",
|
||||||
namespace: "dl-automation",
|
namespace: "dl-automation",
|
||||||
secret: k8sSecret
|
secret: k8sSecret
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
functions.deletePod(
|
stage ('Restart Pod') {
|
||||||
|
steps {
|
||||||
|
container ('alpine') {
|
||||||
|
script {
|
||||||
|
declarativeFunctions.deletePod(
|
||||||
kubeAuth: "k8s-dl-automation-access",
|
kubeAuth: "k8s-dl-automation-access",
|
||||||
kubeURL: "https://kubernetes.test-chamber-13.lan:6443",
|
kubeURL: "https://kubernetes.test-chamber-13.lan:6443",
|
||||||
namespace: "dl-automation",
|
namespace: "dl-automation",
|
||||||
selector: "app=deluge"
|
selector: "app=deluge"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user