From 1ebd511d29186d91036b584b3d7c9a23936da1eb Mon Sep 17 00:00:00 2001 From: The_Spider Date: Sun, 28 Jun 2020 09:01:52 -0500 Subject: [PATCH] Updated Mincraft builder to use kaniko and 1.16.1. --- build-minecraft.jenkins | 109 +++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/build-minecraft.jenkins b/build-minecraft.jenkins index fe9d370..e233f72 100644 --- a/build-minecraft.jenkins +++ b/build-minecraft.jenkins @@ -1,10 +1,55 @@ -def dockerFile = """ -FROM alpine:latest +// Node Label +def nodeLabel = "${UUID.randomUUID().toString()}" + +// Kaniko Image +def kanikoImage = "gcr.io/kaniko-project/executor:debug" + +// Repository Locations +def pushRepo = "registry.test-chamber-13.lan:5000" +def pushImage = "minecraft" +def pushTag = "latest" + +// Container Variables +def baseImage = "alpine" +def baseImageTag = "3.12" +def alpineJavaPackage = "openjdk11" + +// PaperMC URL +def paperMCDownload = "https://papermc.io/api/v1/paper/1.16.1/latest/download" + +// 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 +""") { + node (nodeLabel) { + // Set working directory + def workspace = pwd() + + stage ("Pre-Build") { + def dockerFile = """ +FROM ${baseImage}:${baseImageTag} MAINTAINER The_Spider RUN \\ - apk add --no-cache openjdk11 curl && \\ + apk add --no-cache ${alpineJavaPackage} curl && \\ addgroup -S -g 1000 minecraft && \\ adduser -S minecraft -G minecraft -h /minecraft -u 1000 @@ -13,63 +58,21 @@ USER minecraft WORKDIR /minecraft RUN \ - curl -Ls https://papermc.io/api/v1/paper/1.15.2/latest/download -o /minecraft/paper-mc.jar && \\ + curl -Ls "${paperMCDownload}" -o /minecraft/paper-mc.jar && \\ mkdir /minecraft/data && \\ mkdir /minecraft/html && \\ cd /minecraft/data && \\ java -jar ../paper-mc.jar; exit 0 -CMD cd data; java -Xms1g -Xmx48g -jar ../paper-mc.jar +CMD cd data; java -Xms${memoryMin} -Xmx${memoryMax} -jar ../paper-mc.jar """ -podTemplate( - containers: [ - containerTemplate( - name: "docker", - image: "docker:19.03", - command: "sleep", - args: "99d", - envVars: [ - envVar( - key: "DOCKER_HOST", - value: "tcp://localhost:2375" - ) - ] - ), - containerTemplate( - name: "docker-daemon", - image: "docker:19.03-dind", - command: "dockerd-entrypoint.sh", - args: "--insecure-registry registry.test-chamber-13.lan:5000", - privileged: true, - envVars: [ - envVar( - key: "DOCKER_TLS_CERTDIR", - value: "" - ) - ], - ) - ] -) { - node(POD_LABEL) { - container("docker") { - stage("Test DinD Daemon") { - sh """ - docker version - """ - } - stage("Write Dockerfile"){ - writeFile(file: "Dockerfile", text: dockerFile) - } - stage("Build Container"){ - sh """ - docker build --tag registry.test-chamber-13.lan:5000/minecraft:latest ./ - """ - } - stage("Push Container"){ - sh """ - docker push registry.test-chamber-13.lan:5000/minecraft:latest - """ + writeFile(file: workspace + '/Dockerfile', text: dockerFile) + } + + stage ("Build & Push") { + container ("kaniko") { + sh "/kaniko/executor --cleanup --insecure --skip-tls-verify --context \"${workspace}\" -f \"${workspace}/Dockerfile\" --destination \"${pushRepo}/${pushImage}:${pushTag}\"" } } }