// Node Label def nodeLabel = "${UUID.randomUUID().toString()}" // Kaniko Image def repository = "registry.c.test-chamber-13.lan" def kanikoImage = "${repository}/library/kaniko:latest" def repositoryCreds = "harbor-repository-creds" // Container Variables def baseImage = "${repository}/library/alpine" def baseImageTag = "latest" def alpineJavaPackage = "openjdk17" // PaperMC URL def paperVersion = "1.17.1" // Minecraft Configuration def memoryMin = "1g" def memoryMax = "48g" 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 - name: alpine image: ${repository}/library/alpine:latest imagePullPolicy: Always tty: true command: - /bin/sh """) { node (nodeLabel) { // Set working directory 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 ("Pre-Build") { def dockerFile = """ FROM ${baseImage}:${baseImageTag} ARG paperDownload MAINTAINER The_Spider RUN sed -i -r -e 's/v3.14\\/community/edge\\/community/' /etc/apk/repositories && \\ apk add --no-cache ${alpineJavaPackage} curl jq && \\ addgroup -S -g 1000 minecraft && \\ adduser -S minecraft -G minecraft -h /minecraft -u 1000 && \\ curl --location --fail --silent \${paperDownload} -o /minecraft/paper-mc.jar && \\ mkdir /minecraft/data && \\ mkdir /minecraft/html && \\ chown -R minecraft:minecraft /minecraft USER minecraft WORKDIR /minecraft CMD cd data; java -Xms${memoryMin} -Xmx${memoryMax} -jar ../paper-mc.jar """ writeFile(file: workspace + '/Dockerfile', text: dockerFile) } stage ("Build & Push") { container ("alpine") { sh "apk add --no-cache curl jq" paperDownload = sh ( script: """ paperBuild=\$(curl --silent --location --fail https://papermc.io/api/v2/projects/paper/versions/${paperVersion} | jq '.builds | max') paperFile=\$(curl --silent --location --fail https://papermc.io/api/v2/projects/paper/versions/${paperVersion}/builds/\${paperBuild} | jq '.downloads.application.name') echo https://papermc.io/api/v2/projects/paper/versions/${paperVersion}/builds/\${paperBuild}/downloads/\${paperFile} """, returnStdout: true ).trim() } container ("kaniko") { sh """ /kaniko/executor --cleanup --context "${workspace}" -f "${workspace}/Dockerfile" --destination "${repository}/library/minecraft:latest" --build-arg "paperDownload=${paperDownload}" """ } } } }