use build from global functions
This commit is contained in:
parent
9eaa88b309
commit
c3a9d21cdb
75
Jenkinsfile
vendored
75
Jenkinsfile
vendored
@ -6,6 +6,37 @@ def repositoryCreds = "harbor-repository-creds"
|
|||||||
def label = "kubernetes-${UUID.randomUUID().toString()}"
|
def label = "kubernetes-${UUID.randomUUID().toString()}"
|
||||||
def templateName = "pipeline-worker"
|
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(
|
podTemplate(
|
||||||
label: label,
|
label: label,
|
||||||
name: templateName,
|
name: templateName,
|
||||||
@ -113,44 +144,12 @@ sonar.go.coverage.reportPaths=cover.out
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage ("Build Container") {
|
functions.buildContainer(
|
||||||
def DF = """
|
repository: repository,
|
||||||
FROM ${repository}/library/alpine:latest as certHost
|
imageDest: "${repository}/library/emonesp-exporter:latest",
|
||||||
|
dockerFile: dockerFile,
|
||||||
FROM ${repository}/dockerhub/library/golang:alpine as builder
|
repoCreds: repositoryCreds
|
||||||
|
)
|
||||||
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"
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Delete Running Pod') {
|
stage('Delete Running Pod') {
|
||||||
functions.deletePod(
|
functions.deletePod(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user