diff --git a/Jenkinsfile b/Jenkinsfile index 5760440..e8f760e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,6 +6,37 @@ def repositoryCreds = "harbor-repository-creds" def label = "kubernetes-${UUID.randomUUID().toString()}" def templateName = "pipeline-worker" + +def dockerFile = """ +FROM ${repository}/library/alpine:latest as certHost + +FROM ${repository}/dockerhub/library/golang:alpine as builder + +COPY . /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 get -d -v ./... && \\ + go install -v ./... && \\ + GOOG=linux GOARCH=amd64 CGO_ENABLED=0 go build -v -ldflags="-s -w" -tags timetzdata -o app ./cmd/tpapi && \\ + upx --lzma app + +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/app /app/app + +USER app:app +WORKDIR /app/ + +ENTRYPOINT ["/app/app"] +""" + + podTemplate( label: label, name: templateName, @@ -113,44 +144,12 @@ sonar.go.coverage.reportPaths=cover.out } } - stage ("Build Container") { - def DF = """ -FROM ${repository}/library/alpine:latest as certHost - -FROM ${repository}/dockerhub/library/golang:alpine as builder - -COPY . /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 get -d -v ./... && \\ - go install -v ./... && \\ - GOOG=linux GOARCH=amd64 CGO_ENABLED=0 go build -v -ldflags="-s -w" -tags timetzdata -o app ./cmd/tpapi && \\ - upx --lzma app - -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/app /app/app - -USER app:app -WORKDIR /app/ - -ENTRYPOINT ["/app/app"] -""" - writeFile(file: workspace + "/Dockerfile", text: DF) - sh """ - /kaniko/executor \\ - --cleanup \\ - --context "${workspace}" \\ - -f "${workspace}/Dockerfile" \\ - --destination "${repository}/library/tplink-api:latest" - """ - } + functions.buildContainer( + repository: repository, + imageDest: "${repository}/library/emonesp-exporter:latest", + dockerFile: dockerFile, + repoCreds: repositoryCreds + ) stage('Delete Running Pod') { functions.deletePod(