From 9aa2941513db403379a993094fd1946d2fbc4e2b Mon Sep 17 00:00:00 2001 From: The_Spider Date: Sun, 30 Jan 2022 14:04:12 -0600 Subject: [PATCH] adds sidecar injector --- build-sidecer-injector.jenkinsfile | 96 ++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 build-sidecer-injector.jenkinsfile diff --git a/build-sidecer-injector.jenkinsfile b/build-sidecer-injector.jenkinsfile new file mode 100644 index 0000000..a766a79 --- /dev/null +++ b/build-sidecer-injector.jenkinsfile @@ -0,0 +1,96 @@ +#!groovy + +def repository = "registry.c.test-chamber-13.lan" +def repositoryCreds = "harbor-repository-creds" + +def dockerFile = """ +# Certificate Container +FROM registry.c.test-chamber-13.lan/library/alpine:latest as certHost + +# Build Container +FROM registry.c.test-chamber-13.lan/dockerhub/library/golang:latest AS build + +COPY generic-sidecar-injector/ /go/src/app/ + +WORKDIR /go/src/app + +RUN apk add --no-cache git upx && \\ + 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 && \\ + go mod download && \\ + GIT_HASH=\$(git rev-parse --short HEAD) && GIT_TAG=\$(git tag | tail -1) && \\ + CGO_ENABLED=0 \\ + GOOS=linux && \\ + GOARCH=amd64 && \\ + go build \\ + -v \\ + -tags timetzdata \\ + -ldflags="-s -w -X 'github.com/salesforce/generic-sidecar-injector/pkg/metrics.gitHash=\${GIT_HASH}' -X 'github.com/salesforce/generic-sidecar-injector/pkg/metrics.gitTag=\${GIT_TAG}'" \\ + -installsuffix cgo \\ + -o sidecarinjector \\ + ./cmd/sidecarinjector && \\ + upx --lzma sidecarinjector + +# Build Image from Scratch +FROM scratch + +LABEL maintainer="The_Spider " + +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/sidecarinjector /app/sidecarinjector + +USER app:app +WORKDIR /app/ + +ENTRYPOINT ["/app/sidecarinjector"] +""" + +def label = "kubernetes-${UUID.randomUUID().toString()}" +def templateName = "pipeline-worker" +podTemplate( + label: label, + name: templateName, + yaml: functions.podYaml( + repo: repository, + templateName: templateName, + kaniko: true + ) +) { + node (label) { + stage ("Pull generic-sidecar-injector source") { + dir("generic-sidecar-injector") { + checkout ([ + $class: "GitSCM", + branches: [ + [ + name: "refs/heads/master", + ], + ], + userRemoteConfigs: [ + [ + url: "https://github.com/salesforce/generic-sidecar-injector.git", + ], + ], + extensions: [ + [ + $class: "CloneOption", + shallow: true, + ], + [ + $class: "CheckoutOption", + timeout: 2, + ], + ], + ]) + } + } + + functions.buildContainer( + repository: repository, + imageDest: "${repository}/library/generic-sidecar-injector:latest", + dockerFile: dockerFile, + repoCreds: repositoryCreds, + ) + } +}