def label = "jenkins-${UUID.randomUUID().toString()}" def repository = "registry.c.test-chamber-13.lan" def kanikoImage = "${repository}/library/kaniko:latest" def repositoryCreds = "harbor-repository-creds" podTemplate( label: label, name: "pipeline-worker", yaml: """--- apiVersion: v1 kind: Pod spec: containers: - name: kaniko image: ${kanikoImage} tty: true command: - /busybox/cat """, ) { node (label) { def workspace = pwd() stage ("Pull VLMCSD Source") { dir("vlmcsd") { checkout ([ $class: "GitSCM", branches: [ [ name: "refs/heads/master", ], ], userRemoteConfigs: [ [ url: "ssh://git@gitea.smoothnet.org:31822/nhyatt/vlmcsd-source.git", credentialsId: "Gitea-Read-Only-Token", ], ], extensions: [ [ $class: "CloneOption", shallow: true, ], [ $class: "CheckoutOption", timeout: 2, ], ], ]) } } 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}/library/alpine:latest as BUILDER RUN apk --no-cache add gcc && \\ cd ${workspace}/vlmcsd && \\ make FROM ${repository}/library/alpine:latest EXPOSE 1688/tcp RUN addgroup -g 1000 -S vlmcsd && \\ adduser -u 1000 -G vlmcsd -S -D -h /home/vlmcsd vlmcsd WORKDIR /home/vlmcsd COPY --from=build --chown=1000:1000 /vlmcsd/bin/vlmcsd /vlmcsd/etc/vlmcsd.kmd /home/vlmcsd/ ENTRYPOINT ["/bin/sh" "-c" "./vlmcsd -L 0.0.0.0:1688 -m 5 -t 5 -e -N1 -B1 -r1 -C 1033 -R 1w -A 1h -H 36446 -v -D -j ./vlmcsd.kmd"] """ writeFile (file: workspace + "/Dockerfile", text: dockerfile) sh "/kaniko/executor --context \"${workspace}\" -f \"${workspace}/Dockerfile\" --destination \"${repository}/library/statafactory-server:latest\"" } } } }