Skip to content

Commit

Permalink
Add version information to binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanay Kothari committed Jan 25, 2025
1 parent 1d2c782 commit 69a9868
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/publish-container-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
images: ${{ matrix.image }}
# Use latest tag on default branch (main), otherwise use the tag
tags: |
type=raw, value=latest, enable={{is_default_branch}}
# type=raw, value=latest, enable={{is_default_branch}}
type=ref, event=tag
flavor: |
latest=false
Expand All @@ -63,6 +63,10 @@ jobs:
with:
context: .
file: ${{ matrix.dockerfile }}
build-args: |
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
GIT_COMMIT=${{ github.sha }}
BUILD_TIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
9 changes: 8 additions & 1 deletion build/images/Dockerfile.alerter
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ RUN tdnf install -y golang ca-certificates
ADD . /code
WORKDIR /code

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/alerter ./cmd/alerter
ARG VERSION GIT_COMMIT BUILD_TIME

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags=" \
-X 'github.com/Azure/adx-mon/pkg/version.Version=${VERSION}' \
-X 'github.com/Azure/adx-mon/pkg/version.GitCommit=${GIT_COMMIT}' \
-X 'github.com/Azure/adx-mon/pkg/version.BuildTime=${BUILD_TIME}' \
" -o ./bin/alerter ./cmd/alerter

FROM mcr.microsoft.com/cbl-mariner/distroless/minimal:2.0

Expand Down
7 changes: 6 additions & 1 deletion build/images/Dockerfile.collector
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ RUN tdnf install -y golang systemd-devel gcc glibc-devel binutils kernel-headers
ADD . /code
WORKDIR /code

RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o ./bin/collector ./cmd/collector
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
-ldflags=" \
-X 'github.com/Azure/adx-mon/pkg/version.Version=${VERSION}' \
-X 'github.com/Azure/adx-mon/pkg/version.GitCommit=${GIT_COMMIT}' \
-X 'github.com/Azure/adx-mon/pkg/version.BuildTime=${BUILD_TIME}' \
" -o ./bin/collector ./cmd/collector

# Install systemd lib to get libsystemd.so
FROM mcr.microsoft.com/cbl-mariner/base/core:2.0 AS libsystemdsource
Expand Down
7 changes: 6 additions & 1 deletion build/images/Dockerfile.ingestor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ RUN tdnf install -y golang ca-certificates
ADD . /code
WORKDIR /code

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/ingestor ./cmd/ingestor
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags=" \
-X 'github.com/Azure/adx-mon/pkg/version.Version=${VERSION}' \
-X 'github.com/Azure/adx-mon/pkg/version.GitCommit=${GIT_COMMIT}' \
-X 'github.com/Azure/adx-mon/pkg/version.BuildTime=${BUILD_TIME}' \
" -o ./bin/ingestor ./cmd/ingestor

FROM mcr.microsoft.com/cbl-mariner/distroless/minimal:2.0

Expand Down
4 changes: 4 additions & 0 deletions cmd/alerter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Azure/adx-mon/alerter"
alertrulev1 "github.com/Azure/adx-mon/api/v1"
"github.com/Azure/adx-mon/pkg/logger"
"github.com/Azure/adx-mon/pkg/version"
"github.com/urfave/cli/v2" // imports as package "cli"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -40,6 +41,7 @@ func main() {
Commands: []*cli.Command{
NewLintCommand(),
},
Version: version.String(),
}

if err := app.Run(os.Args); err != nil {
Expand All @@ -48,6 +50,8 @@ func main() {
}

func realMain(ctx *cli.Context) error {
logger.Infof("alerter version:%s", version.String())

endpoints := make(map[string]string)
endpointsArg := ctx.StringSlice("kusto-endpoint")
for _, v := range endpointsArg {
Expand Down
5 changes: 5 additions & 0 deletions cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/Azure/adx-mon/pkg/k8s"
"github.com/Azure/adx-mon/pkg/logger"
"github.com/Azure/adx-mon/pkg/remote"
"github.com/Azure/adx-mon/pkg/version"
"github.com/Azure/adx-mon/schema"
"github.com/Azure/adx-mon/storage"
"github.com/pelletier/go-toml/v2"
Expand Down Expand Up @@ -68,6 +69,8 @@ func main() {
Action: func(ctx *cli.Context) error {
return realMain(ctx)
},

Version: version.String(),
}

if err := app.Run(os.Args); err != nil {
Expand All @@ -76,6 +79,8 @@ func main() {
}

func realMain(ctx *cli.Context) error {
logger.Infof("collector version:%s", version.String())

runtime.MemProfileRate = 4096
runtime.SetBlockProfileRate(int(1 * time.Second))
runtime.SetMutexProfileFraction(1)
Expand Down
5 changes: 5 additions & 0 deletions cmd/ingestor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/Azure/adx-mon/pkg/limiter"
"github.com/Azure/adx-mon/pkg/logger"
"github.com/Azure/adx-mon/pkg/tls"
"github.com/Azure/adx-mon/pkg/version"
"github.com/Azure/adx-mon/schema"
"github.com/Azure/azure-kusto-go/kusto"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -85,6 +86,8 @@ func main() {
Action: func(ctx *cli.Context) error {
return realMain(ctx)
},

Version: version.String(),
}

if err := app.Run(os.Args); err != nil {
Expand All @@ -93,6 +96,8 @@ func main() {
}

func realMain(ctx *cli.Context) error {
logger.Infof("ingestor version:%s", version.String())

svcCtx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down
13 changes: 13 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package version

import "fmt"

var (
GitCommit string
BuildTime string
Version string
)

func String() string {
return fmt.Sprintf("%s, Commit:%s, Build-time:%s", Version, GitCommit, BuildTime)
}

0 comments on commit 69a9868

Please sign in to comment.