diff --git a/build-webfinger.jenkins b/build-webfinger.jenkins new file mode 100644 index 0000000..a42ae3c --- /dev/null +++ b/build-webfinger.jenkins @@ -0,0 +1,117 @@ +#!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 + +USER app:app +WORKDIR /app/ + +ENTRYPOINT ["/app/webfinger", "--finger-file", "/home/app/config/fingers.yml"] +""" + } + } + } + + 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 + ], + ], + destination: [ + "${repository}/library/webfinger:latest", + ] + ) + } + } + } + } + } +}