From 8bd3f00e70d33bb48ca2968360eaa2a84b766fcf Mon Sep 17 00:00:00 2001 From: The_Spider Date: Wed, 19 Jan 2022 13:58:12 -0600 Subject: [PATCH] updates to 1.18.1 and uses common functions --- build-minecraft.jenkins | 154 +++++++++++++--------------------------- 1 file changed, 50 insertions(+), 104 deletions(-) diff --git a/build-minecraft.jenkins b/build-minecraft.jenkins index d4c15c8..c50ba2e 100644 --- a/build-minecraft.jenkins +++ b/build-minecraft.jenkins @@ -1,69 +1,51 @@ -// 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 buildImage = "${repository}/library/alpine" -def buildImageTag = "latest" - -// PaperMC URL def paperVersion = "1.18.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() +def dockerFile = """FROM registry.c.test-chamber-13.lan/library/alpine:latest as builder - 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 - """ - } - } - } +ARG paperDownload + +RUN addgroup -S -g 1000 minecraft && \\ + adduser --disabled-password -G minecraft --gecos "application account" --home "/minecraft" --shell "/sbin/nologin" --uid 1000 minecraft && \\ + apk add --no-cache curl && \\ + mkdir /minecraft/data && \\ + mkdir /minecraft/html && \\ + curl --location --fail --silent \${paperDownload} -o /minecraft/paper-mc.jar + +FROM gcr.io/distroless/java17:latest + +LABEL org.opencontainers.image.authors="The_Spider " + +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=builder /etc/passwd /etc/group /etc/ +COPY --from=builder --chown=minecraft:minecraft /minecraft/ /minecraft/ + +USER minecraft + +WORKDIR /minecraft/data + +ENTRYPOINT ["/usr/bin/java", "-Xms${memoryMin}", "-Xmx${memoryMax}", "-jar"] +CMD ["../paper-mc.jar"] +""" + +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 (nodeLabel) { + def workspace = pwd() stage ("Get Paper-MC Version") { container ("alpine") { @@ -79,50 +61,14 @@ spec: } } - stage ("Create Dockerfile") { - // Set dockerfile - def dockerFile = """ -FROM ${buildImage}:${buildImageTag} as builder - -ARG paperDownload - -RUN addgroup -S -g 1000 minecraft && \\ - adduser --disabled-password -G minecraft --gecos "application account" --home "/minecraft" --shell "/sbin/nologin" --uid 1000 minecraft && \\ - apk add --no-cache curl && \\ - mkdir /minecraft/data && \\ - mkdir /minecraft/html && \\ - curl --location --fail --silent \${paperDownload} -o /minecraft/paper-mc.jar - -FROM gcr.io/distroless/java17:latest - -MAINTAINER The_Spider - -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt -COPY --from=builder /etc/passwd /etc/group /etc/ -COPY --from=builder --chown=minecraft:minecraft /minecraft/ /minecraft/ - -USER minecraft - -WORKDIR /minecraft/data - -ENTRYPOINT ["/usr/bin/java", "-Xms${memoryMin}", "-Xmx${memoryMax}", "-jar"] -CMD ["../paper-mc.jar"] -""" - writeFile(file: workspace + '/Dockerfile', text: dockerFile) - } - - stage ("Build & Push") { - container ("kaniko") { - sh """ - /kaniko/executor \\ - --cleanup \\ - --context "${workspace}" \\ - -f "${workspace}/Dockerfile" \\ - --destination "${repository}/library/minecraft:latest" \\ - --build-arg "paperDownload=${paperDownload}" \\ - --single-snapshot - """ - } - } + functions.buildContainer( + repository: repository, + imageDest: "${repository}/library/the-spider:latest", + dockerFile: dockerFile, + repoCreds: repositoryCreds, + [ + "paperDownload=${paperDownload}" + ] + ) } -} \ No newline at end of file +}