1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/Dockerfile
Florian Wilhelm 485faed812
Reduce go binary size by updating to go 1.15 (#1968)
* Update go to 1.15 to reduce binary size

Go made improvements to reduce binary size, cf https://golang.org/doc/go1.15

> Go 1.15 reduces typical binary sizes by around 5% compared to Go 1.14 by eliminating certain types of GC metadata and more aggressively eliminating unused type metadata.

In my test, this equates to about 3 mb diff between Go 1.13 and Go 1.15:

-rwxr-xr-x 1 root root 36M Aug 31 14:43 piper-go-113
-rwxr-xr-x 1 root root 33M Aug 31 14:44 piper-go-115

* Go Generate

* go mod tidy

Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-09-17 08:44:42 +02:00

24 lines
835 B
Docker

FROM golang:1.15 AS build-env
COPY . /build
WORKDIR /build
# execute tests
RUN go test ./... -cover
## ONLY tests so far, building to be added later
# execute build
# with `-tags release` we ensure that shared test utilities won't end up in the binary
RUN export GIT_COMMIT=$(git rev-parse HEAD) && \
export GIT_REPOSITORY=$(git config --get remote.origin.url) && \
CGO_ENABLED=0 go build \
-ldflags \
"-X github.com/SAP/jenkins-library/cmd.GitCommit=${GIT_COMMIT} \
-X github.com/SAP/jenkins-library/pkg/log.LibraryRepository=${GIT_REPOSITORY} \
-X github.com/SAP/jenkins-library/pkg/telemetry.LibraryRepository=${GIT_REPOSITORY}" \
-tags release \
-o piper
# FROM gcr.io/distroless/base:latest
# COPY --from=build-env /build/piper /piper
# ENTRYPOINT ["/piper"]