#!groovy def repository = "registry.c.test-chamber-13.lan" def repositoryCreds = "harbor-repository-creds" def workspace def dockerFile def route_override def connectivity_test def label = "kubernetes-${UUID.randomUUID().toString()}" def templateName = "pipeline-worker" pipeline { agent { kubernetes { yaml functions.podYaml( repo: repository, templateName: templateName, kaniko: true ) } } stages { stage ('Initalize Jenkins') { steps { script { workspace = pwd() route_override = """#! /usr/bin/env sh VPN_GATEWAY=\$(ip route | grep default | awk '{print \$3}') ip route add 10.42.0.0/16 via "\${VPN_GATEWAY}" dev eth0 ip route add 10.43.0.0/16 via "\${VPN_GATEWAY}" dev eth0 ip route add 10.20.0.0/16 via "\${VPN_GATEWAY}" dev eth0 ip route del default via "\${VPN_GATEWAY}" printf "%s\n" "Route Updated" """ writeFile(file: workspace + "/route-override.sh", text: route_override) connectivity_test = """#! /usr/bin/env sh getPublicIP() { ip="" # curl lookups for i in "https://icanhazip.com" "https://ifconfig.me" "https://api.ipify.org" "https://bot.whatismyipaddress.com" "https://ipinfo.io/ip" "https://ipecho.net/plain"; do ip=\$(curl -s "\${i}") if [ "\${ip}" != "" ]; then printf '%s' "\${ip}" return 0 fi done # DNS Lookups ip=\$(dig -4 @ns1.google.com TXT o-o.myaddr.l.google.com +short | sed -e 's/"//g') if [ "\${ip}" != "" ]; then printf '%s' "\${ip}" return 0 fi ip=\$(dig -4 @resolver1.opendns.com A myip.opendns.com +short | sed -e 's/"//g') if [ "\${ip}" != "" ]; then printf '%s' "\${ip}" return 0 fi ip=\$(dig -4 @1.0.0.1 txt ch whoami.cloudflare +short | sed -e 's/"//g') if [ "\${ip}" != "" ]; then printf '%s' "\${ip}" return 0 fi } if ! curl --silent --fail --insecure http://localhost:8112 > /dev/null; 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=\$(getPublicIP) 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 if ! ping -c 2 google.com > /dev/null; then printf '%s\\n' "No internet connectivity." exit 100 fi """ writeFile(file: workspace + "/connectivity_test.sh", text: connectivity_test) dockerFile = """FROM ${repository}/linuxserver/linuxserver/deluge:amd64-latest LABEL maintainer="The_Spider " COPY route-override.sh connectivity_test.sh /root/ RUN apk add --no-cache openvpn iputils bind-tools curl && \\ chmod +x /root/route-override.sh /root/connectivity_test.sh """ } } } stage ('Build & Push') { steps { container ('kaniko') { script { declarativeFunctions.buildContainerMultipleDestinations( dockerFile: dockerFile, repositoryAccess: [ [ repository: repository, credentials: repositoryCreds ], ], destination: [ "${repository}/library/deluge:latest", ] ) } } } } } }