updates to 1.18.1 and uses common functions

This commit is contained in:
Hyatt 2022-01-19 13:58:12 -06:00
parent 4c01b95b0b
commit 8bd3f00e70
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA

View File

@ -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 <spider@smoothnet.org>"
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 <spider@smoothnet.org>
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}"
]
)
}
}
}