Use auto build version info for embedding version information

This is better, integrates with git, gives us more detail, and I don't
have to explicitly pass it around everywhere.
This commit is contained in:
Eli Ribble 2026-04-28 16:36:48 +00:00
parent 20bf272746
commit 38359e20e9
No known key found for this signature in database
5 changed files with 35 additions and 21 deletions

View file

@ -15,6 +15,7 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/platform"
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
"github.com/Gleipnir-Technology/nidus-sync/resource"
"github.com/Gleipnir-Technology/nidus-sync/version"
//"github.com/gorilla/mux"
"github.com/rs/zerolog/log"
)
@ -276,7 +277,7 @@ type about struct {
Environment string `json:"environment"`
SentryDSN string `json:"sentry_dsn"`
Tegola tegolaURLs `json:"tegola"`
Version string `json:"version"`
Version version.VersionInfo `json:"version"`
}
type tegolaURLs struct {
Nidus string `json:"nidus"`
@ -284,6 +285,7 @@ type tegolaURLs struct {
}
func getRoot(ctx context.Context, r *http.Request, q resource.QueryParams) (*about, *nhttp.ErrorWithStatus) {
v := version.Get()
return &about{
Environment: config.Environment,
SentryDSN: config.SentryDSNFrontend,
@ -291,6 +293,6 @@ func getRoot(ctx context.Context, r *http.Request, q resource.QueryParams) (*abo
Nidus: config.MakeURLTegola("/maps/nidus/{z}/{x}/{y}?id={organization_id}"),
RMO: config.MakeURLTegola("/maps/rmo/{z}/{x}/{y}"),
},
Version: version,
Version: v,
}, nil
}

View file

@ -7,6 +7,7 @@ import (
"time"
"github.com/Gleipnir-Technology/nidus-sync/platform"
"github.com/Gleipnir-Technology/nidus-sync/version"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
)
@ -27,6 +28,13 @@ type Message struct {
URI string `json:"uri"`
}
type Status struct {
BuildTime time.Time `json:"build_time"`
IsModified bool `json:"is_modified"`
Revision string `json:"revision"`
Status string `json:"status"`
}
func (c *ConnectionSSE) SendEvent(w http.ResponseWriter, m platform.Event) error {
return send(w, Message{
Resource: m.Resource,
@ -62,11 +70,6 @@ func SetEventChannel(chan_envelopes <-chan platform.Envelope) {
}()
}
var version string = "unknown"
func SetVersion(v string) {
version = v
}
func send[T any](w http.ResponseWriter, msg T) error {
jsonData, err := json.Marshal(msg)
if err != nil {
@ -91,6 +94,8 @@ func streamEvents(w http.ResponseWriter, r *http.Request, u platform.User) {
uid, err := uuid.NewUUID()
if err != nil {
log.Error().Err(err).Msg("failed to create uuid")
http.Error(w, "failed to create uuid", http.StatusInternalServerError)
return
}
connection := ConnectionSSE{
chanEvent: make(chan platform.Event),
@ -102,7 +107,21 @@ func streamEvents(w http.ResponseWriter, r *http.Request, u platform.User) {
log.Debug().Int32("org", u.Organization.ID).Int("user", u.ID).Str("id", uid.String()).Msg("connected SSE client")
// Send an initial connected event
fmt.Fprintf(w, "event: connected\ndata: {\"status\": \"connected\", \"version\": \"%s\", \"time\": \"%s\"}\n\n", version, time.Now().Format(time.RFC3339))
v := version.Get()
status := Status{
BuildTime: v.BuildTime,
IsModified: v.IsModified,
Revision: v.Revision,
Status: "connected",
}
body, err := json.Marshal(status)
if err != nil {
log.Error().Err(err).Msg("failed to marshal connect status")
http.Error(w, "failed to marshal connect status", http.StatusInternalServerError)
return
}
w.Write(body)
w.(http.Flusher).Flush()
// Keep the connection open with a ticker sending periodic events

View file

@ -19,9 +19,9 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/llm"
"github.com/Gleipnir-Technology/nidus-sync/middleware"
"github.com/Gleipnir-Technology/nidus-sync/platform"
"github.com/Gleipnir-Technology/nidus-sync/resource"
"github.com/Gleipnir-Technology/nidus-sync/rmo"
nidussync "github.com/Gleipnir-Technology/nidus-sync/sync"
"github.com/Gleipnir-Technology/nidus-sync/version"
"github.com/getsentry/sentry-go"
sentryhttp "github.com/getsentry/sentry-go/http"
"github.com/getsentry/sentry-go/zerolog"
@ -43,7 +43,8 @@ func main() {
log.Warn().Msg("Forcing production mode for testing templates")
config.Environment = "PRODUCTION"
}
log.Info().Str("environment", config.Environment).Bool("is-prod", config.IsProductionEnvironment()).Str("version", Version).Str("commit", Commit).Msg("Starting")
v := version.Get()
log.Info().Str("environment", config.Environment).Bool("is-prod", config.IsProductionEnvironment()).Str("revision", v.Revision).Str("build_time", v.BuildTime.String()).Bool("is modified", v.IsModified).Msg("Starting")
err = sentry.Init(sentry.ClientOptions{
Debug: false, //!config.IsProductionEnvironment(),
Dsn: config.SentryDSN,
@ -157,8 +158,6 @@ func main() {
}()
chan_envelope := make(chan platform.Envelope, 10)
api.SetVersion(Version)
resource.SetVersion(Version)
platform.SetEventChannel(chan_envelope)
api.SetEventChannel(chan_envelope)

View file

@ -116,9 +116,3 @@ func (res *sessionR) Get(ctx context.Context, r *http.Request, user platform.Use
},
}, nil
}
var version string = "unknown"
func SetVersion(v string) {
version = v
}