Skip to content

Commit

Permalink
fix(version): use version info for gateway from version command (#191)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Feb 14, 2024
1 parent 50827db commit d9ea4c2
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 54 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ GORELEASER_BUILD_VARS := \
-X github.com/akash-network/provider/version.Version=$(RELEASE_TAG) \
-X github.com/akash-network/provider/version.Commit=$(GIT_HEAD_COMMIT_LONG)

ldflags = -linkmode=$(GO_LINKMODE) -X github.com/akash-network/provider/version.Name=provider-services \
ldflags = -linkmode=$(GO_LINKMODE) \
-X github.com/akash-network/provider/version.Name=provider-services \
-X github.com/akash-network/provider/version.AppName=provider-services \
-X github.com/akash-network/provider/version.BuildTags="$(BUILD_TAGS)" \
-X github.com/akash-network/provider/version.Version=$(shell git describe --tags | sed 's/^v//') \
-X github.com/akash-network/provider/version.Version=$(shell git describe --tags) \
-X github.com/akash-network/provider/version.Commit=$(GIT_HEAD_COMMIT_LONG)

# check for nostrip option
Expand Down
2 changes: 1 addition & 1 deletion _run/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export AP_CHAIN_ID = $(AKASH_CHAIN_ID)
export AP_YES = $(AKASH_YES)
export AP_GAS_PRICES = $(AKASH_GAS_PRICES)
export AP_GAS = $(AKASH_GAS)
export AP_NODE = $(AKASH_GAS)
export AP_NODE = $(AKASH_NODE)

AKASH_INIT := $(AP_RUN_DIR)/.akash-init

Expand Down
4 changes: 1 addition & 3 deletions _run/kube/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ KUBE_SSH_NODES := kind
KUSTOMIZE_INSTALLS ?= \
akash-operator-hostname \
akash-operator-inventory \
akash-operator-ip \
akash-node \
akash-provider
akash-operator-ip

include ../common.mk
include ../common-commands.mk
Expand Down
2 changes: 2 additions & 0 deletions cmd/provider-services/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,8 @@ func createClusterClient(ctx context.Context, log log.Logger, _ *cobra.Command)

func showErrorToUser(err error) error {
// If the error has a complete message associated with it then show it
// terr := &gwrest.ClientResponseError{}
// errors.As(err, terr)
clientResponseError, ok := err.(gwrest.ClientResponseError)
if ok && 0 != len(clientResponseError.Message) {
_, _ = fmt.Fprintf(os.Stderr, "provider error messsage:\n%v\n", clientResponseError.Message)
Expand Down
8 changes: 4 additions & 4 deletions gateway/rest/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ import (
cltypes "github.com/akash-network/provider/cluster/types/v1beta3"
cip "github.com/akash-network/provider/cluster/types/v1beta3/clients/ip"
clfromctx "github.com/akash-network/provider/cluster/types/v1beta3/fromctx"
"github.com/akash-network/provider/gateway/utils"
pmanifest "github.com/akash-network/provider/manifest"
"github.com/akash-network/provider/tools/fromctx"
"github.com/akash-network/provider/version"
)

type CtxAuthKey string
Expand Down Expand Up @@ -489,8 +489,8 @@ func createAddressHandler(log log.Logger, providerAddr sdk.Address) http.Handler
}

type versionInfo struct {
Akash utils.AkashVersionInfo `json:"akash"`
Kube *kubeVersion.Info `json:"kube"`
Akash version.Info `json:"akash"`
Kube *kubeVersion.Info `json:"kube"`
}

func createVersionHandler(log log.Logger, pclient provider.Client) http.HandlerFunc {
Expand All @@ -502,7 +502,7 @@ func createVersionHandler(log log.Logger, pclient provider.Client) http.HandlerF
}

writeJSON(log, w, versionInfo{
Akash: utils.NewAkashVersionInfo(),
Akash: version.NewInfo(),
Kube: kube,
})
}
Expand Down
5 changes: 2 additions & 3 deletions gateway/rest/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
kubeVersion "k8s.io/apimachinery/pkg/version"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"

manifestValidation "github.com/akash-network/akash-api/go/manifest/v2beta2"
qmock "github.com/akash-network/akash-api/go/node/client/v1beta2/mocks"
Expand All @@ -34,10 +33,10 @@ import (
clustertypes "github.com/akash-network/provider/cluster/types/v1beta3"
ctypes "github.com/akash-network/provider/cluster/types/v1beta3"
clmocks "github.com/akash-network/provider/cluster/types/v1beta3/mocks"
"github.com/akash-network/provider/gateway/utils"
pmmock "github.com/akash-network/provider/manifest/mocks"
pmock "github.com/akash-network/provider/mocks"
"github.com/akash-network/provider/pkg/apis/akash.network/v2beta2"
"github.com/akash-network/provider/version"
)

const (
Expand Down Expand Up @@ -327,7 +326,7 @@ func TestRouteVersionOK(t *testing.T) {
version.BuildTags = "testTags"

status := versionInfo{
Akash: utils.AkashVersionInfo{
Akash: version.Info{
Version: "akashTest",
GitCommit: "testCommit",
BuildTags: "testTags",
Expand Down
24 changes: 0 additions & 24 deletions gateway/utils/version.go

This file was deleted.

4 changes: 2 additions & 2 deletions operator/common/operator_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/gorilla/mux"

"github.com/akash-network/provider/gateway/utils"
"github.com/akash-network/provider/version"
)

type PrepareFlagFn func()
Expand Down Expand Up @@ -40,7 +40,7 @@ func NewOperatorHTTP() (OperatorHTTP, error) {
_, _ = io.WriteString(rw, "OK")
})

akashVersion := utils.NewAkashVersionInfo()
akashVersion := version.NewInfo()
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
err := enc.Encode(akashVersion)
Expand Down
48 changes: 33 additions & 15 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/tendermint/tendermint/libs/cli"
"gopkg.in/yaml.v3"

"github.com/tendermint/tendermint/libs/cli"
)

var (
Expand Down Expand Up @@ -88,24 +89,26 @@ func NewVersionCommand() *cobra.Command {

// Info defines the application version information.
type Info struct {
Name string `json:"name" yaml:"name"`
AppName string `json:"server_name" yaml:"server_name"`
Version string `json:"version" yaml:"version"`
GitCommit string `json:"commit" yaml:"commit"`
BuildTags string `json:"build_tags" yaml:"build_tags"`
GoVersion string `json:"go" yaml:"go"`
BuildDeps []buildDep `json:"build_deps" yaml:"build_deps"`
Name string `json:"name" yaml:"name"`
AppName string `json:"server_name" yaml:"server_name"`
Version string `json:"version" yaml:"version"`
GitCommit string `json:"commit" yaml:"commit"`
BuildTags string `json:"build_tags" yaml:"build_tags"`
GoVersion string `json:"go" yaml:"go"`
BuildDeps []buildDep `json:"build_deps" yaml:"build_deps"`
CosmosSdkVersion string `json:"cosmos_sdk_version" yaml:"cosmos_sdk_version"`
}

func NewInfo() Info {
return Info{
Name: Name,
AppName: AppName,
Version: Version,
GitCommit: Commit,
BuildTags: BuildTags,
GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
BuildDeps: depsFromBuildInfo(),
Name: Name,
AppName: AppName,
Version: Version,
GitCommit: Commit,
BuildTags: BuildTags,
GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
CosmosSdkVersion: getSDKVersion(),
BuildDeps: depsFromBuildInfo(),
}
}

Expand Down Expand Up @@ -145,3 +148,18 @@ func (d buildDep) String() string {

func (d buildDep) MarshalJSON() ([]byte, error) { return json.Marshal(d.String()) }
func (d buildDep) MarshalYAML() (interface{}, error) { return d.String(), nil }

func getSDKVersion() string {
deps, ok := debug.ReadBuildInfo()
if !ok {
return "unable to read deps"
}
var sdkVersion string
for _, dep := range deps.Deps {
if dep.Path == "github.com/cosmos/cosmos-sdk" {
sdkVersion = dep.Version
}
}

return sdkVersion
}

0 comments on commit d9ea4c2

Please sign in to comment.