From f6b7d53f11b21fb4527f6b3527db3b5dcb54444b Mon Sep 17 00:00:00 2001 From: The_Spider Date: Fri, 7 Jan 2022 10:42:08 -0600 Subject: [PATCH] initial commit --- vars/functions.groovy | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 vars/functions.groovy diff --git a/vars/functions.groovy b/vars/functions.groovy new file mode 100644 index 0000000..656b183 --- /dev/null +++ b/vars/functions.groovy @@ -0,0 +1,48 @@ +#!groovy + +def buildContainer(String repository, + String imageDest, + String dockerFile, + String repoCreds,) { + + def label = "kaniko-${UUID.randomUUID().toString()}" + def ws = pwd() + + podTemplate( + label: label, + name: "pipeline-worker", + yaml: """ +--- +apiVersion: v1 +kind: Pod +metadata: + name: pipeline-worker +spec: + containers: + - name: kaniko + imagePullPolicy: Always + image: ${repository}/library/kaniko:latest + tty: true + command: + - /busybox/sh +""", + ){ + node(label) { + container ("kaniko") { + writeFile(file: ws + "/Dockerfile", text: DF) + withCredentials([usernameColonPassword( + credentialsId: repoCreds, + variable: "dCreds", + )]) { + sh "set +x; printf '{\"auths\":{\"%s\":{\"auth\": \"%s\"}}}' \"${repository}\" \"${dcreds.bytes.encodeBase64().toString()}\" > /kaniko/.docker/config.json" + } + sh """ + /kaniko/executor \\ + --context "${ws}" \\ + -f "${ws}/Dockerfile" \\ + --destination "${repository}/${imageDest} + """ + } + } + } +} \ No newline at end of file