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
2022-01-28 10:24:23 -06:00

75 lines
2.6 KiB
Plaintext

def repository = "registry.c.test-chamber-13.lan"
def repositoryCreds = "harbor-repository-creds"
def paperVersion = "1.18.1"
def memoryMin = "1g"
def memoryMax = "48g"
def 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:latest
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"]
"""
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 (label) {
def workspace = pwd()
stage ("Get Paper-MC Version") {
container ("alpine") {
sh "apk add --no-cache curl jq"
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 '.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()
}
}
functions.buildContainer(
repository: repository,
imageDest: "${repository}/library/minecraft:latest",
dockerFile: dockerFile,
repoCreds: repositoryCreds,
[
"paperDownload=${paperDownload}"
]
)
}
}