This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
build-containers/build-deluge.jenkins

102 lines
2.5 KiB
Plaintext

def nodeLabel = "${UUID.randomUUID().toString()}"
def repository = "registry.c.test-chamber-13.lan"
def kanikoImage = "${repository}/library/kaniko:latest"
def repositoryCreds = "harbor-repository-creds"
podTemplate(
name: "pipelineContainer",
label: nodeLabel,
yaml: """---
apiVersion: v1
kind: Pod
metadata:
name: kaniko
spec:
containers:
- name: kaniko
image: ${kanikoImage}
imagePullPolicy: Always
tty: true
command:
- /busybox/cat
""") {
node (nodeLabel) {
stage ("Prepare Kaniko") {
container ("kaniko") {
withCredentials([usernameColonPassword(
credentialsId: repositoryCreds,
variable: "dCreds",
)]) {
def dockerJSON = """{
"auths": {
"${repository}": {
"auth": "${dcreds.bytes.encodeBase64().toString()}"
}
}
}"""
sh """
set +x
echo '${dockerJSON}' > /kaniko/.docker/config.json
"""
}
}
}
stage('Build Container') {
container('kaniko') {
def connectivity_test = """
#! /usr/bin/env bash
curl --silent --fail --insecure http://localhost:8112 > /dev/null
if [[ "\${?}" != "0" ]]; then
printf '%s\\n' "Deluge not running."
exit 100
fi
if [[ -z "\${DDNS_HOST}" ]] || [[ "\${DDNS_HOST}" == "" ]]; then
printf '%s\\n' "Dynamic DNS host is not set."
exit 100
fi
DIP=\$(dig -4 @ns1.google.com TXT o-o.myaddr.l.google.com +short | sed -e 's/"//g')
if [[ -z "\${DIP+x}" ]] || [[ "\${DIP}" == "" ]]; then
printf '%s\\n' "Unable to detect real-world IP."
exit 100
fi
KIP=\$(dig \${DDNS_HOST} +short)
if [[ -z "\${KIP+x}" ]] || [[ "\${KIP}" == "" ]]; then
printf '%s\\n' "Unable to get known IP."
exit 100
fi
if [[ "\${DIP}" == "\${KIP}" ]]; then
printf '%s\\n' "VPN is not functional."
exit 100
fi
ping -c 2 google.com > /dev/null
if [[ "\${?}" != "0" ]]; then
printf '%s\\n' "No internet connectivity."
exit 100
fi
"""
def dockerfile = """FROM ${repository}/dockerhub/linuxserver/deluge:amd64-latest
COPY connectivity_test.sh /root
RUN apt-get update && \\
apt-get upgrade -y && \\
apt-get install -y openvpn iputils-ping dnsutils && \\
apt-get clean && \\
rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*
"""
writeFile file: workspace + '/Dockerfile', text: dockerfile
writeFile file: workspace + '/connectivity_test.sh', text: connectivity_test
sh "chmod +x \"${workspace}/connectivity_test.sh\""
sh "/kaniko/executor --context \"${workspace}\" -f \"${workspace}/Dockerfile\" --destination \"${repository}/library/deluge:latest\""
}
}
}
}