From 7254291e24bdcca67cf8fb0ea75a5a6b9b2e22a3 Mon Sep 17 00:00:00 2001
From: The_Spider <nhyatt@smoothnet.org>
Date: Thu, 27 Jan 2022 08:43:52 -0600
Subject: [PATCH] deluge to new format

---
 build-deluge.jenkins | 87 ++++++++++++++++----------------------------
 1 file changed, 32 insertions(+), 55 deletions(-)

diff --git a/build-deluge.jenkins b/build-deluge.jenkins
index f9a8f9d..9e58410 100644
--- a/build-deluge.jenkins
+++ b/build-deluge.jenkins
@@ -1,51 +1,9 @@
-def nodeLabel = "${UUID.randomUUID().toString()}"
+#!groovy
+
 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
+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."
@@ -81,20 +39,39 @@ if [[ "\${?}" != "0" ]]; then
 fi
 """
 
-				def dockerfile = """FROM ${repository}/dockerhub/linuxserver/deluge:amd64-version-2.0.3-2201906121747ubuntu18.04.1
-COPY connectivity_test.sh /root
+def dockerFile = """FROM ${repository}/dockerhub/linuxserver/deluge:amd64-latest
+#FROM ${repository}/dockerhub/linuxserver/deluge:amd64-version-2.0.3-2201906121747ubuntu18.04.1
+
+COPY connectivity_test.sh /root/connectivity_test.sh
 
 RUN apt-get update && \\
 	apt-get install -y openvpn iputils-ping dnsutils && \\
 	apt-get clean && \\
-	rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*
+	rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* && \\
+    chmod +x /root/connectivity_test.sh
 """
 
-				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\""
-			}
-		}
-	}
+def label = "kubernetes-${UUID.randomUUID().toString()}"
+def templateName = "pipeline-worker"
+podTemplate(
+    label: label,
+    name: templateName,
+    yaml: functions.podYaml(
+        repo: repository,
+        templateName: templateName,
+        kaniko: true 
+    )
+) {
+    node (label) {
+        def workspace = pwd()
+
+        writeFile(file: workspace + "/connectivity_test.sh", text: connectivity_test)
+
+        functions.buildContainer(
+            repository: repository,
+            imageDest: "${repository}/library/deluge:latest",
+            dockerFile: dockerFile,
+            repoCreds: repositoryCreds,
+        )
+    }
 }