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

99 lines
2.5 KiB
Plaintext

// Node Label
def nodeLabel = "${UUID.randomUUID().toString()}"
// Kaniko Image
def repository = "registry.cluster.test-chamber-13.lan"
def kanikoImage = "${repository}/library/kaniko:latest"
def repositoryCreds = "harbor-repository-creds"
// Container Variables
def baseImage = "${repository}/library/alpine"
def baseImageTag = "latest"
def alpineJavaPackage = "openjdk16"
// PaperMC URL
def paperMCDownload = "https://papermc.io/api/v1/paper/1.16.5/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 ("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
"""
}
}
}
stage ("Pre-Build") {
def dockerFile = """
FROM ${baseImage}:${baseImageTag}
MAINTAINER The_Spider <spider@smoothnet.org>
RUN printf '%s\\n' "aHR0cHM6Ly9kbC1jZG4uYWxwaW5lbGludXgub3JnL2FscGluZS9lZGdlL21haW4KaHR0cHM6Ly9k" \\
"bC1jZG4uYWxwaW5lbGludXgub3JnL2FscGluZS9lZGdlL2NvbW11bml0eQpodHRwczovL2RsLWNk" \\
"bi5hbHBpbmVsaW51eC5vcmcvYWxwaW5lL2VkZ2UvdGVzdGluZwo=" | base64 -d > /etc/apk/repositories && \\
apk update && \\
apk upgrade && \\
apk add --no-cache ${alpineJavaPackage} curl && \\
apk cache --purge && \\
addgroup -S -g 1000 minecraft && \\
adduser -S minecraft -G minecraft -h /minecraft -u 1000 && \\
curl -Ls "${paperMCDownload}" -o /minecraft/paper-mc.jar && \\
mkdir /minecraft/data && \\
mkdir /minecraft/html && \\
chown -R minecraft:minecraft /minecraft
USER minecraft
WORKDIR /minecraft
CMD cd data; java -Xms${memoryMin} -Xmx${memoryMax} -jar ../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\""
}
}
}
}