Distroless image?

This commit is contained in:
Hyatt 2021-12-09 09:32:27 -06:00
parent d3289ffff3
commit 275a618b8d
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA

View File

@ -7,12 +7,11 @@ def kanikoImage = "${repository}/library/kaniko:latest"
def repositoryCreds = "harbor-repository-creds"
// Container Variables
def baseImage = "${repository}/library/alpine"
def baseImageTag = "latest"
def alpineJavaPackage = "openjdk17"
def buildImage = "${repository}/library/alpine"
def buildImageTag = "latest"
// PaperMC URL
def paperVersion = "1.17.1"
def paperVersion = "1.18"
// Minecraft Configuration
def memoryMin = "1g"
@ -45,6 +44,32 @@ spec:
// Set working directory
def workspace = pwd()
// Set dockerfile
def dockerFile = """
FROM ${buildImage}:${buildImageTag} as builder
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 && \\
mkdir /minecraft/data && \\
mkdir /minecraft/html && \\
curl --location --fail --silent \${paperDownload} -o /minecraft/paper-mc.jar
FROM gcr.io/distroless/java17:latest
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
CMD ["java", "-Xms${memoryMin}", "-Xmx${memoryMax}", "-jar ../paper-mc.jar"]
"""
stage ("Prepare Kaniko") {
container ("kaniko") {
withCredentials([usernameColonPassword(
@ -66,34 +91,11 @@ spec:
}
}
stage ("Pre-Build") {
def dockerFile = """
FROM ${baseImage}:${baseImageTag}
ARG paperDownload
MAINTAINER The_Spider <spider@smoothnet.org>
RUN sed -i -r -e 's/v3.14\\/community/edge\\/community/' /etc/apk/repositories && \\
apk add --no-cache ${alpineJavaPackage} curl jq && \\
addgroup -S -g 1000 minecraft && \\
adduser -S minecraft -G minecraft -h /minecraft -u 1000 && \\
curl --location --fail --silent \${paperDownload} -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
"""
stage ("Create Dockerfile") {
writeFile(file: workspace + '/Dockerfile', text: dockerFile)
}
stage ("Build & Push") {
stage ("Get Paper-MC Version") {
container ("alpine") {
sh "apk add --no-cache curl jq"
paperDownload = sh (
@ -105,10 +107,17 @@ CMD cd data; java -Xms${memoryMin} -Xmx${memoryMax} -jar ../paper-mc.jar
returnStdout: true
).trim()
}
}
stage ("Build & Push") {
container ("kaniko") {
sh """
/kaniko/executor --cleanup --context "${workspace}" -f "${workspace}/Dockerfile" --destination "${repository}/library/minecraft:latest" --build-arg "paperDownload=${paperDownload}"
/kaniko/executor \\
--cleanup \\
--context "${workspace}" \\
-f "${workspace}/Dockerfile" \\
--destination "${repository}/library/minecraft:latest" \\
--build-arg "paperDownload=${paperDownload}"
"""
}
}