#!groovy def repository = "registry.c.test-chamber-13.lan" def repositoryCreds = "harbor-repository-creds" def FactorioDownloadURL="https://nexus.c.test-chamber-13.lan/repository/factorio/stable/headless/linux64" def factorioScript = """#!/bin/sh set -e id [ ! -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}/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-settings.json" ] && cp /opt/factorio/data/map-settings.example.json "\${CONFIG}/map-settings.json" if find -L "\${SAVES}" -iname \\*.tmp.zip -mindepth 1 -print | grep -q .; then rm -f \${SAVES}/*.tmp.zip fi if ! find -L "\${SAVES}" -iname \\*.zip -mindepth 1 -print | grep -q .; then /opt/factorio/bin/x64/factorio \\ --create "\${SAVES}/_autosave1.zip" \\ --map-gen-settings "\${CONFIG}/map-gen-settings.json" \\ --map-settings "\${CONFIG}/map-settings.json" fi /opt/factorio/bin/x64/factorio \\ --port \${PORT} \\ --start-server-load-latest \\ --server-settings "\${CONFIG}/server-settings.json" \\ --server-banlist "\${CONFIG}/server-banlist.json" \\ --rcon-port \${RCON_PORT} \\ --server-whitelist "\${CONFIG}/server-whitelist.json" \\ --use-server-whitelist \\ --server-adminlist "\${CONFIG}/server-adminlist.json" \\ --rcon-password "\$(cat "\${CONFIG}/rconpw")" \\ --server-id /factorio/config/server-id.json \\ \${@} """ def dockerFile = """ FROM registry.c.test-chamber-13.lan/library/alpine-glibc:2.34-r0 LABEL maintainer="The_Spider " ENV PORT=34197 \\ RCON_PORT=27015 \\ SAVES=/data/saves \\ CONFIG=/data/config \\ MODS=/data/mods \\ SCENARIOS=/data/scenarios \\ SCRIPT_OUTPUT=/data/script-output COPY start-server.sh /opt/factorio/start-server.sh RUN apk add --update --no-cache \\ pwgen \\ binutils \\ gettext \\ libintl \\ shadow && \\ apk add --no-cache --virtual=.build-dependencies curl && \\ curl --location --silent "${FactorioDownloadURL}" --output /tmp/factorio.tar.xz && \\ tar -x -f /tmp/factorio.tar.xz --directory /opt && \\ rm -v /tmp/factorio.tar.xz && \\ apk del .build-dependencies && \\ mkdir -p /opt/factorio \\ /data \\ \${SAVES} \\ \${CONFIG} \\ \${MODS} \\ \${SCENARIOS} \\ \${SCRIPT_OUTPUT} && \\ 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, alpine: true ) ) { node (label) { def workspace = pwd() writeFile(file: workspace + "/start-server.sh", text: factorioScript) sh "chmod +x ${workspace}/start-server.sh" functions.buildContainer( repository: repository, imageDest: "${repository}/library/factorio:latest", dockerFile: dockerFile, repoCreds: repositoryCreds, ) functions.deletePod( kubeAuth: "k8s-game-servers-access", kubeURL: "https://k8s.test-chamber-13.lan:8043", namespace: "game-servers", selector: "app=factorio" ) } }