use build from global functions

This commit is contained in:
Hyatt 2022-03-14 14:19:48 -05:00
parent 9eaa88b309
commit c3a9d21cdb
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA

75
Jenkinsfile vendored
View File

@ -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(