add build-time version metadata (#70)

This commit is contained in:
Michael Quigley 2022-11-02 15:07:43 -04:00
parent 1938896dd5
commit e062a9f61f
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
6 changed files with 24 additions and 8 deletions

View File

@ -1,9 +1,9 @@
name: Go package
name: Core Build
on: [push]
jobs:
build:
ubuntu-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@ -27,7 +27,7 @@ jobs:
CI: ""
- name: go build
run: go build -v ./...
run: go build -ldflags "-X github.com/openziti-test-kitchen/zrok/build.Version=${{ github.ref }} -X github.com/openziti-test-kitchen/zrok/build.Hash=${{ github.sha }}" ./...
- name: test
run: go test -v ./...

14
build/metadata.go Normal file
View File

@ -0,0 +1,14 @@
package build
import "fmt"
var Version string
var Hash string
func String() string {
if Version != "" {
return fmt.Sprintf("%v [%v]", Version, Hash)
} else {
return "<developer_build>"
}
}

View File

@ -16,8 +16,6 @@ var str *store.Store
var mtr *metricsAgent
var idb influxdb2.Client
const version = "v0.2.0"
func Run(inCfg *Config) error {
cfg = inCfg

View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/build"
"github.com/openziti-test-kitchen/zrok/controller/store"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/identity"
@ -165,7 +166,7 @@ func (self *enableHandler) createEdgeRouterPolicy(id string, edge *rest_manageme
func (self *enableHandler) zrokTags() *rest_model_edge.Tags {
return &rest_model_edge.Tags{
SubTags: map[string]interface{}{
"zrok": version,
"zrok": build.String(),
},
}
}

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/build"
"github.com/openziti-test-kitchen/zrok/controller/store"
"github.com/openziti-test-kitchen/zrok/model"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
@ -264,7 +265,7 @@ func (self *tunnelHandler) proxyUrl(svcName string) string {
func (self *tunnelHandler) zrokTags(svcName string) *rest_model.Tags {
return &rest_model.Tags{
SubTags: map[string]interface{}{
"zrok": version,
"zrok": build.String(),
"zrok-service-name": svcName,
},
}

View File

@ -2,9 +2,11 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/build"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/metadata"
)
func versionHandler(_ metadata.VersionParams) middleware.Responder {
return metadata.NewVersionOK().WithPayload(version)
return metadata.NewVersionOK().WithPayload(rest_model_zrok.Version(build.String()))
}