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:
parent
20bf272746
commit
38359e20e9
5 changed files with 35 additions and 21 deletions
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/resource"
|
"github.com/Gleipnir-Technology/nidus-sync/resource"
|
||||||
|
"github.com/Gleipnir-Technology/nidus-sync/version"
|
||||||
//"github.com/gorilla/mux"
|
//"github.com/gorilla/mux"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
@ -276,7 +277,7 @@ type about struct {
|
||||||
Environment string `json:"environment"`
|
Environment string `json:"environment"`
|
||||||
SentryDSN string `json:"sentry_dsn"`
|
SentryDSN string `json:"sentry_dsn"`
|
||||||
Tegola tegolaURLs `json:"tegola"`
|
Tegola tegolaURLs `json:"tegola"`
|
||||||
Version string `json:"version"`
|
Version version.VersionInfo `json:"version"`
|
||||||
}
|
}
|
||||||
type tegolaURLs struct {
|
type tegolaURLs struct {
|
||||||
Nidus string `json:"nidus"`
|
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) {
|
func getRoot(ctx context.Context, r *http.Request, q resource.QueryParams) (*about, *nhttp.ErrorWithStatus) {
|
||||||
|
v := version.Get()
|
||||||
return &about{
|
return &about{
|
||||||
Environment: config.Environment,
|
Environment: config.Environment,
|
||||||
SentryDSN: config.SentryDSNFrontend,
|
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}"),
|
Nidus: config.MakeURLTegola("/maps/nidus/{z}/{x}/{y}?id={organization_id}"),
|
||||||
RMO: config.MakeURLTegola("/maps/rmo/{z}/{x}/{y}"),
|
RMO: config.MakeURLTegola("/maps/rmo/{z}/{x}/{y}"),
|
||||||
},
|
},
|
||||||
Version: version,
|
Version: v,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
api/event.go
31
api/event.go
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||||
|
"github.com/Gleipnir-Technology/nidus-sync/version"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
@ -27,6 +28,13 @@ type Message struct {
|
||||||
URI string `json:"uri"`
|
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 {
|
func (c *ConnectionSSE) SendEvent(w http.ResponseWriter, m platform.Event) error {
|
||||||
return send(w, Message{
|
return send(w, Message{
|
||||||
Resource: m.Resource,
|
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 {
|
func send[T any](w http.ResponseWriter, msg T) error {
|
||||||
jsonData, err := json.Marshal(msg)
|
jsonData, err := json.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -91,6 +94,8 @@ func streamEvents(w http.ResponseWriter, r *http.Request, u platform.User) {
|
||||||
uid, err := uuid.NewUUID()
|
uid, err := uuid.NewUUID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to create uuid")
|
log.Error().Err(err).Msg("failed to create uuid")
|
||||||
|
http.Error(w, "failed to create uuid", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
connection := ConnectionSSE{
|
connection := ConnectionSSE{
|
||||||
chanEvent: make(chan platform.Event),
|
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")
|
log.Debug().Int32("org", u.Organization.ID).Int("user", u.ID).Str("id", uid.String()).Msg("connected SSE client")
|
||||||
|
|
||||||
// Send an initial connected event
|
// 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()
|
w.(http.Flusher).Flush()
|
||||||
|
|
||||||
// Keep the connection open with a ticker sending periodic events
|
// Keep the connection open with a ticker sending periodic events
|
||||||
|
|
|
||||||
7
main.go
7
main.go
|
|
@ -19,9 +19,9 @@ import (
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/llm"
|
"github.com/Gleipnir-Technology/nidus-sync/llm"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/middleware"
|
"github.com/Gleipnir-Technology/nidus-sync/middleware"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/resource"
|
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/rmo"
|
"github.com/Gleipnir-Technology/nidus-sync/rmo"
|
||||||
nidussync "github.com/Gleipnir-Technology/nidus-sync/sync"
|
nidussync "github.com/Gleipnir-Technology/nidus-sync/sync"
|
||||||
|
"github.com/Gleipnir-Technology/nidus-sync/version"
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
sentryhttp "github.com/getsentry/sentry-go/http"
|
sentryhttp "github.com/getsentry/sentry-go/http"
|
||||||
"github.com/getsentry/sentry-go/zerolog"
|
"github.com/getsentry/sentry-go/zerolog"
|
||||||
|
|
@ -43,7 +43,8 @@ func main() {
|
||||||
log.Warn().Msg("Forcing production mode for testing templates")
|
log.Warn().Msg("Forcing production mode for testing templates")
|
||||||
config.Environment = "PRODUCTION"
|
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{
|
err = sentry.Init(sentry.ClientOptions{
|
||||||
Debug: false, //!config.IsProductionEnvironment(),
|
Debug: false, //!config.IsProductionEnvironment(),
|
||||||
Dsn: config.SentryDSN,
|
Dsn: config.SentryDSN,
|
||||||
|
|
@ -157,8 +158,6 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
chan_envelope := make(chan platform.Envelope, 10)
|
chan_envelope := make(chan platform.Envelope, 10)
|
||||||
api.SetVersion(Version)
|
|
||||||
resource.SetVersion(Version)
|
|
||||||
platform.SetEventChannel(chan_envelope)
|
platform.SetEventChannel(chan_envelope)
|
||||||
api.SetEventChannel(chan_envelope)
|
api.SetEventChannel(chan_envelope)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,9 +116,3 @@ func (res *sessionR) Get(ctx context.Context, r *http.Request, user platform.Use
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var version string = "unknown"
|
|
||||||
|
|
||||||
func SetVersion(v string) {
|
|
||||||
version = v
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue