117 lines
3.8 KiB
Groovy
117 lines
3.8 KiB
Groovy
#!groovy
|
|
|
|
def repository = "registry.c.test-chamber-13.lan"
|
|
def repositoryCreds = "harbor-repository-creds"
|
|
|
|
def FactorioDownloadURL="https://factorio.com/get-download/stable/headless/linux64"
|
|
def factorioScript = """#!/bin/sh
|
|
set -e
|
|
|
|
id
|
|
[ ! -d "/data/saves" ] && mkdir -p /data/saves
|
|
[ ! -d "/data/config" ] && mkdir -p /data/config
|
|
[ ! -d "/data/mods" ] && mkdir -p /data/mods
|
|
[ ! -d "/data/scenarios" ] && mkdir -p /data/scenarios
|
|
[ ! -d "/data/script-output" ] && mkdir -p /data/script-output
|
|
[ ! -f "/data/config/rconpw" ] && printf '%s' "\$(pwgen 15 1)" > /data/config/rconpw
|
|
[ ! -f "/data/config/server-settings.json" ] && cp /opt/factorio/data/server-settings.example.json /data/config/server-settings.json
|
|
[ ! -f "/data/config/map-gen-settings.json" ] && cp /opt/factorio/data/map-gen-settings.example.json /data/config/map-gen-settings.json
|
|
[ ! -f "/data/config/map-settings.json" ] && cp /opt/factorio/data/map-settings.example.json /data/config/map-settings.json
|
|
|
|
if find -L /data/saves -iname \\\\*.tmp.zip -mindepth 1 -print | grep -q .; then
|
|
rm -f /data/saves/*.tmp.zip
|
|
fi
|
|
|
|
if ! find -L /data/saves -iname \*.zip -mindepth 1 -print | grep -q .; then
|
|
/opt/factorio/bin/x64/factorio \\
|
|
--create /data/saves/_autosave1.zip \\
|
|
--map-gen-settings /data/config/map-gen-settings.json \\
|
|
--map-settings /data/config/map-settings.json
|
|
fi
|
|
|
|
/opt/factorio/bin/x64/factorio \\
|
|
--port \${PORT} \\
|
|
--start-server-load-latest \\
|
|
--server-settings /data/config/server-settings.json \\
|
|
--server-banlist /data/config/server-banlist.json \\
|
|
--rcon-port \${RCON_PORT} \\
|
|
--server-whitelist /data/config/server-whitelist.json \\
|
|
--use-server-whitelist \\
|
|
--server-adminlist /data/config/server-adminlist.json \\
|
|
--rcon-password "\$(cat /data/config/rconpw)" \\
|
|
--server-id /factorio/config/server-id.json \\
|
|
\${@}
|
|
"""
|
|
|
|
def dockerFile = """
|
|
FROM registry.c.test-chamber-13.lan/library/alpine-glibc:latest
|
|
|
|
LABEL org.opencontainers.image.authors="The_Spider <spider@smoothnet.org>"
|
|
|
|
ARG SAVES=/data/saves \\
|
|
CONFIG=/data/config \\
|
|
MODS=/data/mods \\
|
|
SCENARIOS=/data/scenarios \\
|
|
SCRIPT_OUTPUT=/data/script-output
|
|
|
|
ENV PORT=34197 \\
|
|
RCON_PORT=27015
|
|
|
|
COPY start-server.sh /opt/factorio/start-server.sh
|
|
|
|
RUN apk add --update --no-cache \\
|
|
pwgen \\
|
|
binutils \\
|
|
gettext \\
|
|
libintl \\
|
|
shadow && \\
|
|
mkdir -p /opt/factorio \\
|
|
/data \\
|
|
\${SAVES} \\
|
|
\${CONFIG} \\
|
|
\${MODS} \\
|
|
\${SCENARIOS} \\
|
|
\${SCRIPT_OUTPUT} && \\
|
|
curl --location --silent "${FactorioDownloadURL}" --output /tmp/factorio.tar.xz && \\
|
|
tar -x -f /tmp/factorio.tar.xz --directory /opt && \\
|
|
rm -v /tmp/factorio.tar.xz && \\
|
|
ln -s \${SAVES} /opt/factorio/saves && \\
|
|
ln -s \${MODS} /opt/factorio/mods && \\
|
|
ln -s \${SCENARIOS} /opt/factorio/scenarios && \\
|
|
ln -s \${SCRIPT_OUTPUT} /opt/factorio/script-output && \\
|
|
addgroup -g 1000 -S factorio && \\
|
|
adduser -u 1000 -G factorio -s /bin/sh -SDH factorio && \\
|
|
chown -R factorio:factorio /opt/factorio /data
|
|
|
|
USER factorio
|
|
|
|
WORKDIR /opt/factorio
|
|
|
|
ENTRYPOINT [ "/bin/sh", "-c", "/opt/factorio/start-server.sh" ]
|
|
"""
|
|
|
|
def label = "kubernetes-${UUID.randomUUID().toString()}"
|
|
def templateName = "pipeline-worker"
|
|
podTemplate(
|
|
label: label,
|
|
name: templateName,
|
|
yaml: functions.podYaml(
|
|
repo: repository,
|
|
templateName: templateName,
|
|
kaniko: true
|
|
)
|
|
) {
|
|
node (label) {
|
|
def workspace = pwd()
|
|
|
|
writeFile(file: workspace + "/start-server.sh", text: factorioScript)
|
|
|
|
functions.buildContainer(
|
|
repository: repository,
|
|
imageDest: "${repository}/library/factorio:latest",
|
|
dockerFile: dockerFile,
|
|
repoCreds: repositoryCreds,
|
|
)
|
|
}
|
|
}
|