From 591aa127d8f5d94dc6d066da60f8e389a4014bad Mon Sep 17 00:00:00 2001 From: The_Spider Date: Wed, 6 Jul 2022 21:11:49 -0500 Subject: [PATCH] project-zomboid re-write --- build-projectzomboid.jenkins | 66 +++++++++++++++ deprecated/build-projectzomboid.jenkins | 104 ------------------------ 2 files changed, 66 insertions(+), 104 deletions(-) create mode 100644 build-projectzomboid.jenkins delete mode 100644 deprecated/build-projectzomboid.jenkins diff --git a/build-projectzomboid.jenkins b/build-projectzomboid.jenkins new file mode 100644 index 0000000..c7d9dab --- /dev/null +++ b/build-projectzomboid.jenkins @@ -0,0 +1,66 @@ +#!groovy + +def repository = "registry.c.test-chamber-13.lan" +def repositoryCreds = "harbor-repository-creds" + +def workspace +def dockerFile + +def label = "kubernetes-${UUID.randomUUID().toString()}" +def templateName = "pipeline-worker" + +def steamToken = "steam-token" + +pipeline { + agent { + kubernetes { + yaml functions.podYaml( + repo: repository, + templateName: templateName, + kaniko: true + ) + } + } + + stages { + stage ('Initalize Jenkins') { + steps { + script { + workspace = pwd() + def dockerfile = """ +FROM ${repository}/dockerhub/cm2network/steamcmd:latest + +LABEL org.opencontainers.image.authors="The_Spider " +LABEL org.opencontainers.image.title="projectzomboid" + +ARG STEAM_TOKEN + +EXPOSE 16261/udp +EXPOSE 27015/udp + +RUN /home/steam/steamcmd/steamcmd.sh +quit && \\ + /home/steam/steamcmd/steamcmd.sh +force_install_dir /home/steam/ProjectZomboid +sv_setsteamaccount "\${STEAM_TOKEN}" +app_update 380870 validate +quit + +WORKDIR /home/steam/ProjectZomboid + +ENTRYPOINT ["/bin/bash", "-c", "/home/steam/ProjectZomboid/start-server.sh"] +""" + } + } + } + + functions.buildContainer( + repository: repository, + imageDest: "${repository}/library/project-zomboid: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=project-zomboid" + ) + } +} \ No newline at end of file diff --git a/deprecated/build-projectzomboid.jenkins b/deprecated/build-projectzomboid.jenkins deleted file mode 100644 index 716879d..0000000 --- a/deprecated/build-projectzomboid.jenkins +++ /dev/null @@ -1,104 +0,0 @@ -def label = "jenkins-${UUID.randomUUID().toString()}" -def templateName = "pipeline-worker" - -def repository = "registry.c.test-chamber-13.lan" -def kanikoImage = "${repository}/library/kaniko:latest" -def repositoryCreds = "harbor-repository-creds" - -def steamCreds = "steam-credentials" -def steamToken = "steam-token" -def steamTokenName = "ssfn7445013141740368289" - -podTemplate( - label: label, - name: templateName, - yaml: functions.podYaml( - repo: repository, - templateName: templateName, - kaniko: true, - alpine: true - ) -) { - node (label) { - def workspace = pwd() - - stage ("Prepare Kaniko") { - container ("kaniko") { - withCredentials([usernameColonPassword( - credentialsId: repositoryCreds, - variable: "dCreds", - )]) { - def dockerJSON = """{ - "auths": { - "${repository}": { - "auth": "${dcreds.bytes.encodeBase64().toString()}" - } - } - }""" - sh """ - set +x - echo '${dockerJSON}' > /kaniko/.docker/config.json - """ - } - } - } - - stage("Kaniko Build & Push") { - container ("kaniko") { - def dockerfile = """ -FROM ${repository}/dockerhub/cm2network/steamcmd:latest - -LABEL maintainer="The_Spider " - -ARG STEAM_USER -ARG STEAM_PASS -ARG STEAM_TOKEN - -EXPOSE 16261/udp -EXPOSE 27015/udp - -COPY --chown=1000:1000 ./\${STEAM_TOKEN} /home/steam/Steam/\${STEAM_TOKEN} - -RUN /home/steam/steamcmd/steamcmd.sh +quit && \\ - /home/steam/steamcmd/steamcmd.sh +force_install_dir /home/steam/ProjectZomboid +login "\${STEAM_USER}" "\${STEAM_PASS}" +app_update 380870 validate +quit && \\ - rm -f /home/steam/Steam/\${STEAM_TOKEN} - -WORKDIR /home/steam/ProjectZomboid - -ENTRYPOINT ["/bin/bash", "-c", "/home/steam/ProjectZomboid/start-server.sh"] -""" - writeFile(file: workspace + "/Dockerfile", text: dockerfile) - withCredentials([ - usernamePassword( - credentialsId: steamCreds, - usernameVariable: "steamUser", - passwordVariable: "steamPass" - ), - file( - credentialsId: steamToken, - variable: "steamTokenFile" - ) - ]) { - sh "cp " + '${steamTokenFile}' + " ${workspace}/${steamTokenName}" - sh """ - /kaniko/executor \\ - --context "${workspace}" \\ - -f "${workspace}/Dockerfile" \\ - --destination "${repository}/library/projectzomboid-server:latest" \\ - --single-snapshot \\ - --build-arg STEAM_USER="${steamUser}" \\ - --build-arg STEAM_PASS="${steamPass}" \\ - --build-arg STEAM_TOKEN="${steamTokenName}" - """ - } - } - } - - functions.deletePod( - kubeAuth: "rancher-admin-token", - kubeURL: "https://k8s.test-chamber-13.lan:8043", - namespace: "game-servers", - selector: "workload.user.cattle.io/workloadselector=apps.deployment-game-servers-project-zomboid" - ) - } -} \ No newline at end of file