This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
build-containers/build-minecraft.jenkins

116 lines
4.1 KiB
Groovy

#!groovy
def repository = "registry.c.test-chamber-13.lan"
def repositoryCreds = "harbor-repository-creds"
def workspace
def dockerFile
def paperVersion
def memoryMin
def memoryMax
def paperDownload
def label = "kubernetes-${UUID.randomUUID().toString()}"
def templateName = "pipeline-worker"
pipeline {
agent {
kubernetes {
yaml functions.podYaml(
repo: repository,
templateName: templateName,
kaniko: true,
alpine: true
)
}
}
stages {
stage ('Initalize Jenkins') {
steps {
script {
workspace = pwd()
paperVersion = "1.21.1"
memoryMin = "1g"
memoryMax = "16g"
dockerFile = """FROM registry.c.test-chamber-13.lan/library/alpine:latest 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 registry.c.test-chamber-13.lan/google/distroless/java17-debian11:latest
FROM registry.c.test-chamber-13.lan/dockerhub/library/openjdk:21
LABEL 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"]
"""
}
}
}
stage ("Get Paper-MC Version") {
steps {
container ("alpine") {
script {
sh """
if [ ! -f "/usr/bin/curl" ] || [ ! -x "/usr/bin/curl" ]; then
apk add --no-cache curl
fi
if [ ! -f "/usr/bin/jq" ] || [ ! -x "/usr/bin/jq" ]; then
apk add --no-cache jq
fi
"""
paperDownload = sh (
script: """
paperBuild=\$(curl --silent --location --fail https://nexus.c.test-chamber-13.lan/repository/paper-io/api/v2/projects/paper/versions/${paperVersion} | jq '.builds | max')
paperFile=\$(curl --silent --location --fail https://nexus.c.test-chamber-13.lan/repository/paper-io/api/v2/projects/paper/versions/${paperVersion}/builds/\${paperBuild} | jq -r '.downloads.application.name')
echo https://nexus.c.test-chamber-13.lan/repository/paper-io/api/v2/projects/paper/versions/${paperVersion}/builds/\${paperBuild}/downloads/\${paperFile}
""",
returnStdout: true
).trim()
}
}
}
}
stage ('Build & Push') {
steps {
container ('kaniko') {
script {
declarativeFunctions.buildContainerMultipleDestinations(
dockerFile: dockerFile,
repositoryAccess: [
[
repository: repository,
credentials: repositoryCreds
],
],
destination: [
"${repository}/library/minecraft:latest",
],
[
"paperDownload=${paperDownload}"
]
)
}
}
}
}
}
}