use function

This commit is contained in:
Hyatt 2022-01-15 13:57:33 -06:00
parent 8e39509405
commit be1ca9b6b7
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA

View File

@ -1,51 +1,7 @@
def label = "jenkins-${UUID.randomUUID().toString()}"
def repository = "registry.c.test-chamber-13.lan"
def kanikoImage = "${repository}/library/kaniko:latest"
def repositoryCreds = "harbor-repository-creds"
podTemplate(
label: label,
name: "pipeline-worker",
yaml: """---
apiVersion: v1
kind: Pod
spec:
containers:
- name: kaniko
image: ${kanikoImage}
tty: true
command:
- /busybox/cat
""",
) {
node (label) {
def workspace = pwd()
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("Kaniko Build & Push") {
container ("kaniko") {
def dockerfile = """
def dockerfile = """
FROM ${repository}/dockerhub/cm2network/steamcmd:latest
EXPOSE 15777/udp
@ -59,9 +15,31 @@ WORKDIR /home/steam/SatisfactoryDedicatedServer
ENTRYPOINT ["/bin/bash" "-c" "./FactoryServer.sh -multihome=0.0.0.0"]
"""
writeFile (file: workspace + "/Dockerfile", text: dockerfile)
sh "/kaniko/executor --context \"${workspace}\" -f \"${workspace}/Dockerfile\" --destination \"${repository}/library/statafactory-server: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,
alpine: true
)
){
node (label) {
functions.buildContainer(
repository: repository,
imageDest: "${repository}/library/statafactory-server:latest",
dockerFile: dockerFile,
repoCreds: repositoryCreds,
)
functions.deletePod(
kubeAuth: "rancher-admin-token",
kubeURL: "https://rancher.test-chamber-13.lan/k8s/clusters/c-mc9cq",
namespace: "game-servers",
selector: "app=satasfactory"
)
}
}