diff --git a/.go-version b/.go-version index 1a31d39..ce2dd53 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.18.8 +1.21.5 diff --git a/Dockerfile b/Dockerfile index cec7fda..08961e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,9 @@ FROM golang:1.21 as build WORKDIR /go/artifactory_exporter ADD . /go/artifactory_exporter -RUN go get -d -v ./... +# cache deps before building and copying source so that we don't need to re-download as much +# and so that source changes don't invalidate our downloaded layer +RUN go mod download ARG VERSION ARG SOURCE_COMMIT @@ -11,17 +13,19 @@ ARG SOURCE_BRANCH ARG BUILD_DATE ARG BUILD_USER -RUN GOOS=linux GOARCH=amd64 go build -o /go/bin/artifactory_exporter -ldflags " \ +RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -o /go/bin/artifactory_exporter -ldflags " \ -X github.com/prometheus/common/version.Version=${VERSION} \ -X github.com/prometheus/common/version.Revision=${SOURCE_COMMIT} \ -X github.com/prometheus/common/version.Branch=${SOURCE_BRANCH} \ -X github.com/prometheus/common/version.BuildDate=${BUILD_DATE} \ -X github.com/prometheus/common/version.BuildUser=${BUILD_USER}" -FROM gcr.io/distroless/base-debian11 +# Use distroless as minimal base image +# Refer to https://github.com/GoogleContainerTools/distroless for more details. +FROM gcr.io/distroless/static:nonroot COPY --from=build /go/bin/artifactory_exporter / -USER nobody +USER 65532:65532 EXPOSE 9531 -ENTRYPOINT ["./artifactory_exporter"] +ENTRYPOINT ["/artifactory_exporter"] diff --git a/go.mod b/go.mod index 05ce591..caa4f0d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/peimanja/artifactory_exporter go 1.21 require ( - github.com/go-kit/log v0.1.0 github.com/kelseyhightower/envconfig v1.4.0 github.com/prometheus/client_golang v1.11.1 github.com/prometheus/client_model v0.2.0 @@ -16,10 +15,8 @@ require ( github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.1.1 // indirect - github.com/go-logfmt/logfmt v0.5.0 // indirect github.com/golang/protobuf v1.4.3 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/procfs v0.6.0 // indirect golang.org/x/sys v0.2.0 // indirect google.golang.org/protobuf v1.26.0-rc.1 // indirect diff --git a/go.sum b/go.sum index ea519df..07fe5d0 100644 --- a/go.sum +++ b/go.sum @@ -17,13 +17,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/log v0.1.0 h1:DGJh0Sm43HbOeYDNnVZFl8BvcYVvjD5bqYJvp0REbwQ= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -68,7 +65,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=