#!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" pipeline { agent { kubernetes { yaml functions.podYaml( repo: repository, templateName: templateName, kaniko: true, alpine: true ) } } stages { stage ('Initalize Jenkins') { steps { script { workspace = pwd() dockerFile = """ FROM ${repository}/library/alpine:latest AS certHost FROM ${repository}/dockerhub/library/golang:alpine AS builder LABEL org.opencontainers.image.authors="The_Spider " LABEL org.opencontainers.image.title="go-finger" LABEL org.opencontainers.image.description="Docker container for the go-webfinger server" ENV ENV_DOCKER=true COPY go-finger/. /go/src/app/ WORKDIR /go/src/app RUN if ! command -v git; then apk add --no-cache git; fi; \ git config --global --add safe.directory /go/src/app && \ addgroup -S -g 1000 app && \ adduser --disabled-password -G app --gecos "application account" --home "/home/app" --shell "/sbin/nologin" --no-create-home --uid 1000 app && \ GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -tags timetzdata -o webfinger ./main.go FROM scratch COPY --from=certHost /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /etc/passwd /etc/group /etc/ COPY --from=builder --chown=app:app /go/src/app/webfinger /app/webfinger COPY --from=builder --chown=app:app /go/src/app/urns.yml /home/app/urns.yaml USER app:app WORKDIR /app/ ENTRYPOINT ["/app/webfinger", "serve", "--urn-file", "/home/app/urns.yaml", "--host", "0.0.0.0", "--port", "8080", "--finger-file", "/home/app/finger.yaml"] """ } } } stage ("Pull Source") { steps { script { dir("go-finger") { checkout ([ $class: "GitSCM", branches: [ [ name: "refs/heads/main", ], ], userRemoteConfigs: [ [ url: "https://github.com/Maronato/go-finger.git", ], ], extensions: [ [ $class: "CloneOption", shallow: true, ], [ $class: "CheckoutOption", timeout: 2, ], ], ]) } } } } stage ('Build & Push') { steps { container ('kaniko') { script { declarativeFunctions.buildContainerMultipleDestinations( dockerFile: dockerFile, repositoryAccess: [ [ repository: repository, credentials: repositoryCreds ], [ repository: "https://index.docker.io/v1/", credentials: "dockerhub-repository-creds" ], ], destination: [ "index.docker.io/thespider/webfinger:latest", "${repository}/library/webfinger:latest", ] ) } } } } } }