Skip to content

Commit

Permalink
Remove custom build info script
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin committed Mar 22, 2022
1 parent 715d9ce commit ccf743d
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 117 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,3 @@
# Fossa
.fossa.yml

# Build info
build/info/data.json

1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
before:
hooks:
- go mod download
- ./develop/scripts/create_build_info_data.sh

archives:
- id: default
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ clean-bins:

temporal-server:
@printf $(COLOR) "Build temporal-server with CGO_ENABLED=$(CGO_ENABLED) for $(GOOS)/$(GOARCH)..."
@./develop/scripts/create_build_info_data.sh
go build -o temporal-server ./cmd/server

temporal-cassandra-tool:
Expand Down
31 changes: 0 additions & 31 deletions build/cgo/cgo.go

This file was deleted.

31 changes: 0 additions & 31 deletions build/cgo/nocgo.go

This file was deleted.

Empty file removed build/info/empty
Empty file.
15 changes: 8 additions & 7 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ import (
stdlog "log"
"os"
"path"
"runtime"
"strings"
_ "time/tzdata" // embed tzdata as a fallback

"github.com/urfave/cli/v2"

"go.temporal.io/server/build"
"go.temporal.io/server/common/authorization"
"go.temporal.io/server/common/build"
"go.temporal.io/server/common/config"
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/headers"
Expand Down Expand Up @@ -133,13 +132,15 @@ func buildCLI() *cli.App {
}

logger := log.NewZapLogger(log.BuildZapLogger(cfg.Log))
logger.Info("Build info",
tag.Timestamp(build.InfoData.BuildTime()),
logger.Info("Build info.",
tag.NewTimeTag("git-time", build.InfoData.GitTime),
tag.NewStringTag("git-revision", build.InfoData.GitRevision),
tag.NewStringTag("platform", runtime.GOARCH),
tag.NewStringTag("go-version", runtime.Version()),
tag.NewStringTag("server-version", headers.ServerVersion),
tag.NewBoolTag("git-modified", build.InfoData.GitModified),
tag.NewStringTag("go-arch", build.InfoData.GoArch),
tag.NewStringTag("go-os", build.InfoData.GoOs),
tag.NewStringTag("go-version", build.InfoData.GoVersion),
tag.NewBoolTag("cgo-enabled", build.InfoData.CgoEnabled),
tag.NewStringTag("server-version", headers.ServerVersion),
)

var dynamicConfigClient dynamicconfig.Client
Expand Down
62 changes: 35 additions & 27 deletions build/build.go → common/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,56 @@
package build

import (
"embed"
"encoding/json"
"runtime/debug"
"time"

"go.temporal.io/server/build/cgo"
)

const (
buildInfoDataFile = "info/data.json"
)

type (
Info struct {
// GitRevision is the git revision associated with this build.
GitRevision string
// BuildTimeUnix is the seconds since epoch representing the date this build was created.
BuildTimeUnix int64
Available bool
GoVersion string
GoArch string
GoOs string
// CgoEnabled indicates whether cgo was enabled when this build was created.
CgoEnabled bool

// GitRevision is the git revision associated with this build.
GitRevision string
// GitTime is the git revision time.
GitTime time.Time
GitModified bool
}
)

var (
//go:embed info
buildInfoFs embed.FS
InfoData Info
InfoData Info
)

func init() {
InfoData = Info{
GitRevision: "unknown",
BuildTimeUnix: 0,
CgoEnabled: cgo.Enabled,
}

buildInfoDataJson, err := buildInfoFs.ReadFile(buildInfoDataFile)
if err != nil {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return
}
_ = json.Unmarshal(buildInfoDataJson, &InfoData)
}

func (i Info) BuildTime() time.Time {
return time.Unix(i.BuildTimeUnix, 0)
InfoData.Available = true
InfoData.GoVersion = buildInfo.GoVersion

for _, setting := range buildInfo.Settings {
switch setting.Key {
case "GOARCH":
InfoData.GoArch = setting.Value
case "GOOS":
InfoData.GoOs = setting.Value
case "CGO_ENABLED":
InfoData.CgoEnabled = setting.Value == "1"
case "vcs.revision":
InfoData.GitRevision = setting.Value
case "vcs.time":
if gitTime, err := time.Parse(time.RFC3339, setting.Value); err == nil {
InfoData.GitTime = gitTime
}
case "vcs.modified":
InfoData.GitModified = setting.Value == "true"
}
}
}
10 changes: 5 additions & 5 deletions common/metrics/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"sync/atomic"
"time"

"go.temporal.io/server/build"
"go.temporal.io/server/common/build"
"go.temporal.io/server/common/headers"
"go.temporal.io/server/common/log"
)
Expand Down Expand Up @@ -73,13 +73,13 @@ func NewRuntimeMetricsReporter(
logger: logger,
lastNumGC: memstats.NumGC,
quit: make(chan struct{}),
buildTime: build.InfoData.BuildTime(),
buildTime: build.InfoData.GitTime,
buildInfoScope: scope.Tagged(
map[string]string{
gitRevisionTag: build.InfoData.GitRevision,
buildDateTag: build.InfoData.BuildTime().Format(time.RFC3339),
buildPlatformTag: runtime.GOARCH,
goVersionTag: runtime.Version(),
buildDateTag: build.InfoData.GitTime.Format(time.RFC3339),
buildPlatformTag: build.InfoData.GoArch,
goVersionTag: build.InfoData.GoVersion,
buildVersionTag: headers.ServerVersion,
},
),
Expand Down
11 changes: 0 additions & 11 deletions develop/scripts/create_build_info_data.sh

This file was deleted.

0 comments on commit ccf743d

Please sign in to comment.