From 1cb07edf9d0366c42a7690cc2865d01620b765e8 Mon Sep 17 00:00:00 2001 From: Peiman Jafari <18074432+peimanja@users.noreply.github.com> Date: Mon, 23 May 2022 13:09:57 -0700 Subject: [PATCH] Add --version flag (#77) --- .github/workflows/publish-image.yml | 1 + .github/workflows/release.yml | 5 ++++- Dockerfile | 4 +++- README.md | 5 +++-- config/config.go | 2 ++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml index cf9f409..af1ef75 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yml @@ -99,3 +99,4 @@ jobs: SOURCE_COMMIT=${{ github.sha }} SOURCE_BRANCH=${{ github.ref }} BUILD_DATE=${{ steps.date.outputs.value }} + BUILD_USER=github-actions diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b923551..022ca01 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,6 +17,8 @@ jobs: goos: darwin steps: - uses: actions/checkout@v2 + - id: date + run: echo "::set-output name=value::$(date +%FT%TZ)" - uses: wangyoucao577/go-release-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -27,4 +29,5 @@ jobs: -X github.com/prometheus/common/version.Version=${{ github.event.release.tag_name }} -X github.com/prometheus/common/version.Revision=${{ github.sha }} -X github.com/prometheus/common/version.Branch=${{ github.ref }} - -X github.com/prometheus/common/version.BuildDate=${{ github.event.release.created_at }} + -X github.com/prometheus/common/version.BuildDate=${{ steps.date.outputs.value }} + -X github.com/prometheus/common/version.BuildUser=github-actions diff --git a/Dockerfile b/Dockerfile index 24c4bf7..2dea597 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,12 +9,14 @@ ARG VERSION ARG SOURCE_COMMIT ARG SOURCE_BRANCH ARG BUILD_DATE +ARG BUILD_USER RUN GOOS=linux GOARCH=amd64 go build -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.BuildDate=${BUILD_DATE} \ + -X github.com/prometheus/common/version.BuildUser=${BUILD_USER}" FROM gcr.io/distroless/base-debian11 COPY --from=build /go/bin/artifactory_exporter / diff --git a/README.md b/README.md index a1f2409..5ada3fd 100755 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# JFrog Artifactory Exporter +# JFrog Artifactory Exporter [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/peimanja/artifactory_exporter/Build)](https://github.com/peimanja/artifactory_exporter/actions) [![Docker Build](https://img.shields.io/docker/cloud/build/peimanja/artifactory_exporter)](https://hub.docker.com/r/peimanja/artifactory_exporter/builds) [![Go Report Card](https://goreportcard.com/badge/github.com/peimanja/artifactory_exporter)](https://goreportcard.com/report/github.com/peimanja/artifactory_exporter) -A [Prometheus](https://prometheus.io) exporter for [JFrog Artifactory](https://jfrog.com/artifactory) stats. +A [Prometheus](https://prometheus.io) exporter for [JFrog Artifactory](https://jfrog.com/artifactory) stats. ## Note @@ -117,6 +117,7 @@ Flags: --artifactory.timeout=5s Timeout for trying to get stats from JFrog Artifactory. --log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error] --log.format=logfmt Output format of log messages. One of: [logfmt, json] + --version Show application version. ``` | Flag / Environment Variable | Required | Default | Description | diff --git a/config/config.go b/config/config.go index d4bf77b..b5dc51b 100644 --- a/config/config.go +++ b/config/config.go @@ -9,6 +9,7 @@ import ( "github.com/kelseyhightower/envconfig" "github.com/prometheus/common/promlog" "github.com/prometheus/common/promlog/flag" + "github.com/prometheus/common/version" "gopkg.in/alecthomas/kingpin.v2" ) @@ -46,6 +47,7 @@ func NewConfig() (*Config, error) { promlogConfig := &promlog.Config{} flag.AddFlags(kingpin.CommandLine, promlogConfig) kingpin.HelpFlag.Short('h') + kingpin.Version(version.Info() + " " + version.BuildContext()) kingpin.Parse() logger := promlog.New(promlogConfig)