updates to use new factorio and ditches docker-in-docker method

This commit is contained in:
Hyatt 2021-05-06 09:39:49 -05:00
parent 0aba874058
commit a0a0e1346c

View File

@ -1,9 +1,14 @@
def ImageRepository = "registry.test-chamber-13.lan:5000" def label = "jenkins-${UUID.randomUUID().toString()}"
def ImageName = "factorio"
def ImageTag = "latest"
def AlpineGlibcBaseURL = "https://github.com/sgerrand/alpine-pkg-glibc/releases/download" def repository = "registry.test-chamber-13.lan"
def AlpineGlibcPackageVersion = "2.30-r0" def kanikoImage = "${repository}/nhyatt/kaniko:latest"
def imageName = "nhyatt/factorio"
def imageTag = "latest"
def FactorioDownloadURL="https://factorio.com/get-download/stable/headless/linux64"
def AlpineGlibcBaseURL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download"
def AlpineGlibcPackageVersion = "2.33-r0"
def AlpineGlibcBasePackageFilename = "glibc-${AlpineGlibcPackageVersion}.apk" def AlpineGlibcBasePackageFilename = "glibc-${AlpineGlibcPackageVersion}.apk"
def AlpineGlibcBinPackageFilename = "glibc-bin-${AlpineGlibcPackageVersion}.apk" def AlpineGlibcBinPackageFilename = "glibc-bin-${AlpineGlibcPackageVersion}.apk"
def AlpineGlibcI18nPackageFilename = "glibc-i18n-${AlpineGlibcPackageVersion}.apk" def AlpineGlibcI18nPackageFilename = "glibc-i18n-${AlpineGlibcPackageVersion}.apk"
@ -12,24 +17,21 @@ def GlibcLanguage = "C.UTF-8"
def TimeZone = "America/Chicago" def TimeZone = "America/Chicago"
def FactorioDownloadURL = "https://www.factorio.com/get-download/stable/headless/linux64"
def FactorioFileName = "/tmp/factorio.tar"
def dockerFile = """ def dockerFile = """
FROM alpine:latest FROM registry.test-chamber-13.lan/nhyatt/alpine:latest
MAINTAINER The_Spider <spider@smoothnet.org> MAINTAINER The_Spider <spider@smoothnet.org>
ENV PORT=34197 \\ ENV PORT=34197 \\
RCON_PORT=27015 \\ RCON_PORT=27015 \\
SAVES=/factorio/saves \\ SAVES=/data/saves \\
CONFIG=/factorio/config \\ CONFIG=/data/config \\
MODS=/factorio/mods \\ MODS=/data/mods \\
SCENARIOS=/factorio/scenarios \\ SCENARIOS=/data/scenarios \\
SCRIPT_OUTPUT=/factorio/script-output SCRIPT_OUTPUT=/data/script-output \\
TZ=${TimeZone}
RUN \\ RUN apk add --update --no-cache \\
apk add --update --no-cache \\
pwgen \\ pwgen \\
binutils \\ binutils \\
gettext \\ gettext \\
@ -58,30 +60,39 @@ RUN \\
rm -v "/etc/apk/keys/sgerrand.rsa.pub" && \\ rm -v "/etc/apk/keys/sgerrand.rsa.pub" && \\
/usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "${GlibcLanguage}" || true && \\ /usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "${GlibcLanguage}" || true && \\
printf '%s\\n' \\ printf '%s\\n' \\
"export LANG=${GlibcLanguage}" \\ "export LANG=${GlibcLanguage}" && \\
"export TZ=${TimeZone}" >> /etc/profile.d/locale.sh && \\ mkdir -p /opt/factorio \\
mkdir -p /opt /factorio && \\ /data \\
curl -sSL "${FactorioDownloadURL}" -o ${FactorioFileName} && \\ \${SAVES} \\
tar -x -f ${FactorioFileName} --directory /opt && \\ \${CONFIG} \\
\${MODS} \\
\${SCENARIOS} \\
\${SCRIPT_OUTPUT} && \\
curl --location --silent "${FactorioDownloadURL}" --output /tmp/factorio.tar.xz && \\
tar -x -f /tmp/factorio.tar.xz --directory /opt && \\
apk del glibc-i18n && \\ apk del glibc-i18n && \\
apk del .build-dependencies && \\ apk del .build-dependencies && \\
rm -v \\ rm -v \\
${AlpineGlibcBasePackageFilename} \\ ${AlpineGlibcBasePackageFilename} \\
${AlpineGlibcBinPackageFilename} \\ ${AlpineGlibcBinPackageFilename} \\
${AlpineGlibcI18nPackageFilename} \\ ${AlpineGlibcI18nPackageFilename} \\
${FactorioFileName} && \\ /tmp/factorio.tar.xz && \\
ln -s \${SAVES} /opt/factorio/saves && \\ ln -s \${SAVES} /opt/factorio/saves && \\
ln -s \${MODS} /opt/factorio/mods && \\ ln -s \${MODS} /opt/factorio/mods && \\
ln -s \${SCENARIOS} /opt/factorio/scenarios && \\ ln -s \${SCENARIOS} /opt/factorio/scenarios && \\
ln -s \${SCRIPT_OUTPUT} /opt/factorio/script-output && \\ ln -s \${SCRIPT_OUTPUT} /opt/factorio/script-output && \\
addgroup -g 1000 -S factorio && \\ addgroup -g 1000 -S factorio && \\
adduser -u 1000 -G factorio -s /bin/sh -SDH factorio && \\ adduser -u 1000 -G factorio -s /bin/sh -SDH factorio && \\
chown -R factorio:factorio /opt/factorio /factorio && \\ chown -R factorio:factorio /opt/factorio /data && \\
printf '%s\\n' \\ printf '%s\\n' \\
"#!/bin/sh -x" \\ "#!/bin/sh -x" \\
"set -e" \\ "set -e" \\
"id" \\ "id" \\
"mkdir -p /factorio \${SAVES} \${CONFIG} \${MODS} \${SCENARIOS} \${SCRIPT_OUTPUT}" \\ "[ ! -d \\\"\${SAVES}\\\" ] && mkdir -p \${SAVES}" \
"[ ! -d \\\"\${CONFIG}\\\" ] && mkdir -p \${CONFIG}" \
"[ ! -d \\\"\${MODS}\\\" ] && mkdir -p \${MODS}" \
"[ ! -d \\\"\${SCENARIOS}\\\" ] && mkdir -p \${SCENARIOS}" \
"[ ! -d \\\"\${SCRIPT_OUTPUT}\\\" ] && mkdir -p \${SCRIPT_OUTPUT}" \
"[ ! -f \\\"\${CONFIG}/rconpw\\\" ] && printf '%s' \\\"\\\$(pwgen 15 1)\\\" > \${CONFIG}/rconpw" \\ "[ ! -f \\\"\${CONFIG}/rconpw\\\" ] && printf '%s' \\\"\\\$(pwgen 15 1)\\\" > \${CONFIG}/rconpw" \\
"[ ! -f \\\"\${CONFIG}/server-settings.json\\\" ] && cp /opt/factorio/data/server-settings.example.json \${CONFIG}/server-settings.json" \\ "[ ! -f \\\"\${CONFIG}/server-settings.json\\\" ] && cp /opt/factorio/data/server-settings.example.json \${CONFIG}/server-settings.json" \\
"[ ! -f \\\"\${CONFIG}/map-gen-settings.json\\\" ] && cp /opt/factorio/data/map-gen-settings.example.json \${CONFIG}/map-gen-settings.json" \\ "[ ! -f \\\"\${CONFIG}/map-gen-settings.json\\\" ] && cp /opt/factorio/data/map-gen-settings.example.json \${CONFIG}/map-gen-settings.json" \\
@ -111,61 +122,56 @@ RUN \\
USER factorio USER factorio
CMD ./start-server.sh WORKDIR /opt/factorio
ENTRYPOINT [ "/bin/sh", "-c", "./start-server.sh" ]
""" """
podTemplate( podTemplate(
containers: [ label: label,
containerTemplate( name: "pipeline-worker",
name: "docker", yaml: """---
image: "docker:19.03", apiVersion: v1
command: "sleep", kind: Pod
args: "99d", metadata:
envVars: [ name: pipeline-worker
envVar( spec:
key: "DOCKER_HOST", containers:
value: "tcp://localhost:2375" - name: kaniko
) imagePullPolicy: Always
] image: ${kanikoImage}
), tty: true
containerTemplate( command:
name: "docker-daemon", - /busybox/cat
image: "docker:19.03-dind", """,
command: "dockerd-entrypoint.sh",
args: "--insecure-registry registry.test-chamber-13.lan:5000",
privileged: true,
envVars: [
envVar(
key: "DOCKER_TLS_CERTDIR",
value: ""
)
],
)
]
) { ) {
node(POD_LABEL) { node(label) {
container("docker") {
stage("Test DinD Daemon") { stage ("Prepare Kaniko") {
sh """ container ("kaniko") {
docker version withCredentials([usernameColonPassword(
""" credentialsId: repositoryCreds,
} variable: "dCreds",
stage("Write Dockerfile"){ )]) {
writeFile(file: "Dockerfile", text: dockerFile) def dockerJSON = """{
sh """ "auths": {
cat Dockerfile "${repository}": {
""" "auth": "${dcreds.bytes.encodeBase64().toString()}"
} }
stage("Build Container"){ }
sh """ }"""
docker build --tag ${ImageRepository}/${ImageName}:${ImageTag} ./ sh """
""" set +x
} echo '${dockerJSON}' > /kaniko/.docker/config.json
stage("Push Container"){ """
sh """ }
docker push ${ImageRepository}/${ImageName}:${ImageTag} }
""" }
stage("Build Factorio Image") {
container("kaniko") {
writeFile(file: workspace + "/Dockerfile", text: dockerFile)
sh "/kaniko/executor --cleanup --context \"${workspace}\" -f \"${workspace}/Dockerfile\" --destination \"${repository}/${imageName}:${imageTag}\""
} }
} }
}
} }