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-factario-container.jenkins

160 lines
5.5 KiB
Plaintext

def ImageRepository = "registry.test-chamber-13.lan:5000"
def ImageName = "factorio"
def ImageTag = "latest"
def AlpineGlibcBaseURL = "https://github.com/sgerrand/alpine-pkg-glibc/releases/download"
def AlpineGlibcPackageVersion = "2.30-r0"
def AlpineGlibcBasePackageFilename = "glibc-${AlpineGlibcPackageVersion}.apk"
def AlpineGlibcBinPackageFilename = "glibc-bin-${AlpineGlibcPackageVersion}.apk"
def AlpineGlibcI18nPackageFilename = "glibc-i18n-${AlpineGlibcPackageVersion}.apk"
def GlibcLanguage = "C.UTF-8"
def TimeZone = "America/Chicago"
def FactorioDownloadURL = "https://www.factorio.com/get-download/stable/headless/linux64"
def FactorioFileName = "/tmp/factorio.tar"
def dockerFile = """
FROM alpine:3.10
MAINTAINER The_Spider <spider@smoothnet.org>
ENV PORT=34197 \\
RCON_PORT=27015 \\
SAVES=/factorio/saves \\
CONFIG=/factorio/config \\
MODS=/factorio/mods \\
SCENARIOS=/factorio/scenarios \\
SCRIPT_OUTPUT=/factorio/script-output
RUN \\
apk add --update --no-cache \\
pwgen \\
binutils \\
gettext \\
libintl \\
shadow && \\
apk add --update --no-cache --virtual=.build-dependencies \\
curl \\
ca-certificates && \\
printf '%s\\n' \\
"-----BEGIN PUBLIC KEY-----" \\
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApZ2u1KJKUu/fW4A25y9m" \\
"y70AGEa/J3Wi5ibNVGNn1gT1r0VfgeWd0pUybS4UmcHdiNzxJPgoWQhV2SSW1JYu" \\
"tOqKZF5QSN6X937PTUpNBjUvLtTQ1ve1fp39uf/lEXPpFpOPL88LKnDBgbh7wkCp" \\
"m2KzLVGChf83MS0ShL6G9EQIAUxLm99VpgRjwqTQ/KfzGtpke1wqws4au0Ab4qPY" \\
"KXvMLSPLUp7cfulWvhmZSegr5AdhNw5KNizPqCJT8ZrGvgHypXyiFvvAH5YRtSsc" \\
"Zvo9GI2e2MaZyo9/lvb+LbLEJZKEQckqRj4P26gmASrZEPStwc+yqy1ShHLA0j6m" \\
"1QIDAQAB" \\
"-----END PUBLIC KEY-----" > "/etc/apk/keys/sgerrand.rsa.pub" && \\
curl -sSLO "${AlpineGlibcBaseURL}/${AlpineGlibcPackageVersion}/${AlpineGlibcBasePackageFilename}" && \\
curl -sSLO "${AlpineGlibcBaseURL}/${AlpineGlibcPackageVersion}/${AlpineGlibcBinPackageFilename}" && \\
curl -sSLO "${AlpineGlibcBaseURL}/${AlpineGlibcPackageVersion}/${AlpineGlibcI18nPackageFilename}" && \\
apk add --no-cache \\
"${AlpineGlibcBasePackageFilename}" \\
"${AlpineGlibcBinPackageFilename}" \\
"${AlpineGlibcI18nPackageFilename}" && \\
rm -v "/etc/apk/keys/sgerrand.rsa.pub" && \\
/usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "${GlibcLanguage}" || true && \\
printf '%s\\n' \\
"export LANG=${GlibcLanguage}" \\
"export TZ=${TimeZone}" >> /etc/profile.d/locale.sh && \\
mkdir -p /opt /factorio && \\
curl -sSL "${FactorioDownloadURL}" -o ${FactorioFileName} && \\
tar -x -f ${FactorioFileName} --directory /opt && \\
apk del glibc-i18n && \\
apk del .build-dependencies && \\
rm -v \\
${AlpineGlibcBasePackageFilename} \\
${AlpineGlibcBinPackageFilename} \\
${AlpineGlibcI18nPackageFilename} \\
${FactorioFileName} && \\
addgroup -g 1000 -S factorio && \\
adduser -u 1000 -G factorio -s /bin/sh -SDH factorio && \\
chown -R factorio:factorio /opt/factorio /factorio && \\
printf '%s\\n' \\
"#!/bin/sh -x" \\
"set -e" \\
"id" \\
"mkdir -p /factorio \${SAVES} \${CONFIG} \${MODS} \${SCENARIOS} \${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" \\
"find -L \${SAVES} -iname \\*.tmp.zip -mindepth 1 -print | grep -q .; then rm -f \${SAVES}/*.tmp.zip" \\
"if ! find -L \${SAVES} -iname \\*.tmp.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 \\\\" \\
" \${@}"
"""
podTemplate(
containers: [
containerTemplate(
name: "docker",
image: "docker:19.03",
command: "sleep",
args: "99d",
envVars: [
envVar(
key: "DOCKER_HOST",
value: "tcp://localhost:2375"
)
]
),
containerTemplate(
name: "docker-daemon",
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) {
container("docker") {
stage("Test DinD Daemon") {
sh """
docker version
"""
}
stage("Write Dockerfile"){
writeFile(file: "Dockerfile", text: dockerFile)
sh """
cat Dockerfile
"""
}
stage("Build Container"){
sh """
docker build --tag ${ImageRepository}/${ImageName}:${ImageTag} ./
"""
}
stage("Push Container"){
sh """
docker push ${ImageRepository}/${ImageName}:${ImageTag}
"""
}
}
}
}