#!groovy def label = PodTemplates.podLabel() def repositoryCreds = "harbor-repository-creds" podTemplate( label: label, name: "pipeline-worker", yaml: podTemplates.podYaml( 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("Download RCON") { container("alpine") { sh """ apk add --no-cache curl jq VER="\$(curl --silent "https://api.github.com/repos/gorcon/rcon-cli/releases/latest" | jq -r '.tag_name' | sed -r 's/v//')" curl --silent \\ --location \\ "https://github.com/gorcon/rcon-cli/releases/download/v\${VER}/rcon-\${VER}-amd64_linux.tar.gz" \\ | \\ tar -z -x -C /tmp -f - cp /tmp/rcon-\${VER}-amd64_linux/rcon "${workspace}/rcon" """ } } stage("Build Image") { container("kaniko") { def DF = """FROM ${repository}/library/alpine:latest RUN addgroup -S -g 1000 rcon && \\ adduser --disabled-password -G rcon --gecos "rcon" --home "/home/rcon" --shell "/sbin/nologin" --uid 1000 rcon COPY --chown=rcon:rcon ./rcon /home/rcon/rcon USER rcon:rcon WORKDIR /home/rcon ENTRYPOINT ["/bin/sh"] """ writeFile(file: workspace + "/Dockerfile", text: DF) sh "/kaniko/executor --context \"${workspace}\" -f \"${workspace}/Dockerfile\" --destination \"${repository}/library/rcon:latest\" --single-snapshot" } } } }