Skip to content

Commit 136ffc5

Browse files
committed
Add flag for print version
1 parent 4ede0a3 commit 136ffc5

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ COPY go.sum .
66
RUN go mod download
77
COPY . .
88
ARG VERSION=unknown
9-
RUN CGO_ENABLED=1 go build -mod=readonly -ldflags "-X main.version=$VERSION" -o coroot-node-agent .
9+
RUN CGO_ENABLED=1 go build -mod=readonly -ldflags "-X 'github.com/coroot/coroot-node-agent/flags.Version=${VERSION}'" -o coroot-node-agent .
1010

1111
FROM registry.access.redhat.com/ubi9/ubi
1212

flags/flags.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package flags
22

33
import (
4+
"fmt"
45
"os"
56
"strings"
67

@@ -39,6 +40,9 @@ var (
3940

4041
ScrapeInterval = kingpin.Flag("scrape-interval", "How often to gather metrics from the agent").Default("15s").Envar("SCRAPE_INTERVAL").Duration()
4142
WalDir = kingpin.Flag("wal-dir", "Path to where the agent stores data (e.g. the metrics Write-Ahead Log)").Default("/tmp/coroot-node-agent").Envar("WAL_DIR").String()
43+
44+
agentVersion = kingpin.Flag("version", "Print version and exit").Default("false").Bool()
45+
Version = "unknown"
4246
)
4347

4448
func GetString(fl *string) string {
@@ -56,6 +60,11 @@ func init() {
5660
kingpin.HelpFlag.Short('h').Hidden()
5761
kingpin.Parse()
5862

63+
if *agentVersion {
64+
fmt.Println("Version:", Version)
65+
os.Exit(0)
66+
}
67+
5968
if *CollectorEndpoint != nil {
6069
u := *CollectorEndpoint
6170
if *MetricsEndpoint == nil {

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
var (
29-
version = "unknown"
29+
version = flags.Version
3030
)
3131

3232
const minSupportedKernelVersion = "4.16"

0 commit comments

Comments
 (0)