Add version to controller info response
This change adds the GARM server version to the controller info response. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
dcee09281b
commit
42ae3c52d1
10 changed files with 43 additions and 16 deletions
|
|
@ -19,7 +19,7 @@ RUN git clone https://github.com/cloudbase/garm-provider-equinix /build/garm-pro
|
||||||
|
|
||||||
RUN cd /build/garm && go build -o /bin/garm \
|
RUN cd /build/garm && go build -o /bin/garm \
|
||||||
-tags osusergo,netgo,sqlite_omit_load_extension \
|
-tags osusergo,netgo,sqlite_omit_load_extension \
|
||||||
-ldflags "-linkmode external -extldflags '-static' -s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" \
|
-ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" \
|
||||||
/build/garm/cmd/garm && upx /bin/garm
|
/build/garm/cmd/garm && upx /bin/garm
|
||||||
RUN mkdir -p /opt/garm/providers.d
|
RUN mkdir -p /opt/garm/providers.d
|
||||||
RUN cd /build/garm-provider-azure && go build -ldflags="-linkmode external -extldflags '-static' -s -w" -o /opt/garm/providers.d/garm-provider-azure . && upx /opt/garm/providers.d/garm-provider-azure
|
RUN cd /build/garm-provider-azure && go build -ldflags="-linkmode external -extldflags '-static' -s -w" -o /opt/garm/providers.d/garm-provider-azure . && upx /opt/garm/providers.d/garm-provider-azure
|
||||||
|
|
|
||||||
4
Makefile
4
Makefile
|
|
@ -44,8 +44,8 @@ clean: ## Clean up build artifacts
|
||||||
build: ## Build garm
|
build: ## Build garm
|
||||||
@echo Building garm ${VERSION}
|
@echo Building garm ${VERSION}
|
||||||
$(shell mkdir -p ./bin)
|
$(shell mkdir -p ./bin)
|
||||||
@$(GO) build -ldflags "-s -w -X main.Version=${VERSION}" -tags osusergo,netgo,sqlite_omit_load_extension -o bin/garm ./cmd/garm
|
@$(GO) build -ldflags "-s -w -X github.com/cloudbase/garm/util/appdefaults.Version=${VERSION}" -tags osusergo,netgo,sqlite_omit_load_extension -o bin/garm ./cmd/garm
|
||||||
@$(GO) build -ldflags "-s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=${VERSION}" -tags osusergo,netgo,sqlite_omit_load_extension -o bin/garm-cli ./cmd/garm-cli
|
@$(GO) build -ldflags "-s -w -X github.com/cloudbase/garm/util/appdefaults.Version=${VERSION}" -tags osusergo,netgo,sqlite_omit_load_extension -o bin/garm-cli ./cmd/garm-cli
|
||||||
@echo Binaries are available in $(PWD)/bin
|
@echo Binaries are available in $(PWD)/bin
|
||||||
|
|
||||||
test: verify go-test ## Run tests
|
test: verify go-test ## Run tests
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,10 @@ func renderControllerInfoTable(info params.ControllerInfo) string {
|
||||||
if info.ControllerWebhookURL == "" {
|
if info.ControllerWebhookURL == "" {
|
||||||
info.ControllerWebhookURL = "N/A"
|
info.ControllerWebhookURL = "N/A"
|
||||||
}
|
}
|
||||||
|
serverVersion := "v0.0.0-unknown"
|
||||||
|
if info.Version != "" {
|
||||||
|
serverVersion = info.Version
|
||||||
|
}
|
||||||
t.AppendHeader(header)
|
t.AppendHeader(header)
|
||||||
t.AppendRow(table.Row{"Controller ID", info.ControllerID})
|
t.AppendRow(table.Row{"Controller ID", info.ControllerID})
|
||||||
if info.Hostname != "" {
|
if info.Hostname != "" {
|
||||||
|
|
@ -156,6 +159,7 @@ func renderControllerInfoTable(info params.ControllerInfo) string {
|
||||||
t.AppendRow(table.Row{"Webhook Base URL", info.WebhookURL})
|
t.AppendRow(table.Row{"Webhook Base URL", info.WebhookURL})
|
||||||
t.AppendRow(table.Row{"Controller Webhook URL", info.ControllerWebhookURL})
|
t.AppendRow(table.Row{"Controller Webhook URL", info.ControllerWebhookURL})
|
||||||
t.AppendRow(table.Row{"Minimum Job Age Backoff", info.MinimumJobAgeBackoff})
|
t.AppendRow(table.Row{"Minimum Job Age Backoff", info.MinimumJobAgeBackoff})
|
||||||
|
t.AppendRow(table.Row{"Version", serverVersion})
|
||||||
return t.Render()
|
return t.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,6 @@ import (
|
||||||
"github.com/cloudbase/garm/params"
|
"github.com/cloudbase/garm/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version string
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cfg *config.Config
|
cfg *config.Config
|
||||||
mgr config.Manager
|
mgr config.Manager
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
apiClientControllerInfo "github.com/cloudbase/garm/client/controller_info"
|
||||||
|
"github.com/cloudbase/garm/util/appdefaults"
|
||||||
)
|
)
|
||||||
|
|
||||||
// runnerCmd represents the runner command
|
// runnerCmd represents the runner command
|
||||||
|
|
@ -26,7 +29,18 @@ var versionCmd = &cobra.Command{
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
Short: "Print version and exit",
|
Short: "Print version and exit",
|
||||||
Run: func(_ *cobra.Command, _ []string) {
|
Run: func(_ *cobra.Command, _ []string) {
|
||||||
fmt.Println(Version)
|
serverVersion := "v0.0.0-unknown"
|
||||||
|
|
||||||
|
if !needsInit {
|
||||||
|
showInfo := apiClientControllerInfo.NewControllerInfoParams()
|
||||||
|
response, err := apiCli.ControllerInfo.ControllerInfo(showInfo, authToken)
|
||||||
|
if err == nil {
|
||||||
|
serverVersion = response.Payload.Version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("garm-cli: %s\n", appdefaults.GetVersion())
|
||||||
|
fmt.Printf("garm server: %s\n", serverVersion)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,6 @@ var (
|
||||||
version = flag.Bool("version", false, "prints version")
|
version = flag.Bool("version", false, "prints version")
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version string
|
|
||||||
|
|
||||||
var signals = []os.Signal{
|
var signals = []os.Signal{
|
||||||
os.Interrupt,
|
os.Interrupt,
|
||||||
syscall.SIGTERM,
|
syscall.SIGTERM,
|
||||||
|
|
@ -179,7 +177,7 @@ func maybeUpdateURLsFromConfig(cfg config.Config, store common.Store) error {
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *version {
|
if *version {
|
||||||
fmt.Println(Version)
|
fmt.Println(appdefaults.GetVersion())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx, stop := signal.NotifyContext(context.Background(), signals...)
|
ctx, stop := signal.NotifyContext(context.Background(), signals...)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
runnerErrors "github.com/cloudbase/garm-provider-common/errors"
|
runnerErrors "github.com/cloudbase/garm-provider-common/errors"
|
||||||
"github.com/cloudbase/garm/database/common"
|
"github.com/cloudbase/garm/database/common"
|
||||||
"github.com/cloudbase/garm/params"
|
"github.com/cloudbase/garm/params"
|
||||||
|
"github.com/cloudbase/garm/util/appdefaults"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dbControllerToCommonController(dbInfo ControllerInfo) (params.ControllerInfo, error) {
|
func dbControllerToCommonController(dbInfo ControllerInfo) (params.ControllerInfo, error) {
|
||||||
|
|
@ -39,6 +40,7 @@ func dbControllerToCommonController(dbInfo ControllerInfo) (params.ControllerInf
|
||||||
ControllerWebhookURL: url,
|
ControllerWebhookURL: url,
|
||||||
CallbackURL: dbInfo.CallbackURL,
|
CallbackURL: dbInfo.CallbackURL,
|
||||||
MinimumJobAgeBackoff: dbInfo.MinimumJobAgeBackoff,
|
MinimumJobAgeBackoff: dbInfo.MinimumJobAgeBackoff,
|
||||||
|
Version: appdefaults.GetVersion(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -594,6 +594,8 @@ type ControllerInfo struct {
|
||||||
// runners to pick up the job before GARM attempts to allocate a new runner, thus avoiding
|
// runners to pick up the job before GARM attempts to allocate a new runner, thus avoiding
|
||||||
// the need to potentially scale down runners later.
|
// the need to potentially scale down runners later.
|
||||||
MinimumJobAgeBackoff uint `json:"minimum_job_age_backoff"`
|
MinimumJobAgeBackoff uint `json:"minimum_job_age_backoff"`
|
||||||
|
// Version is the version of the GARM controller.
|
||||||
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GithubCredentials struct {
|
type GithubCredentials struct {
|
||||||
|
|
|
||||||
|
|
@ -30,18 +30,18 @@ cd $GARM_SOURCE/cmd/garm
|
||||||
GOOS=linux GOARCH=amd64 go build -mod vendor \
|
GOOS=linux GOARCH=amd64 go build -mod vendor \
|
||||||
-o $BUILD_DIR/linux/amd64/garm \
|
-o $BUILD_DIR/linux/amd64/garm \
|
||||||
-tags osusergo,netgo,sqlite_omit_load_extension \
|
-tags osusergo,netgo,sqlite_omit_load_extension \
|
||||||
-ldflags "-extldflags '-static' -s -w -X main.Version=$VERSION" .
|
-ldflags "-extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$VERSION" .
|
||||||
GOOS=linux GOARCH=arm64 CC=aarch64-linux-musl-gcc go build \
|
GOOS=linux GOARCH=arm64 CC=aarch64-linux-musl-gcc go build \
|
||||||
-mod vendor \
|
-mod vendor \
|
||||||
-o $BUILD_DIR/linux/arm64/garm \
|
-o $BUILD_DIR/linux/arm64/garm \
|
||||||
-tags osusergo,netgo,sqlite_omit_load_extension \
|
-tags osusergo,netgo,sqlite_omit_load_extension \
|
||||||
-ldflags "-extldflags '-static' -s -w -X main.Version=$VERSION" .
|
-ldflags "-extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$VERSION" .
|
||||||
|
|
||||||
# Windows
|
# Windows
|
||||||
GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-cc go build -mod vendor \
|
GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-cc go build -mod vendor \
|
||||||
-o $BUILD_DIR/windows/amd64/garm.exe \
|
-o $BUILD_DIR/windows/amd64/garm.exe \
|
||||||
-tags osusergo,netgo,sqlite_omit_load_extension \
|
-tags osusergo,netgo,sqlite_omit_load_extension \
|
||||||
-ldflags "-s -w -X main.Version=$VERSION" .
|
-ldflags "-s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$VERSION" .
|
||||||
|
|
||||||
# garm-cli
|
# garm-cli
|
||||||
cd $GARM_SOURCE/cmd/garm-cli
|
cd $GARM_SOURCE/cmd/garm-cli
|
||||||
|
|
@ -50,17 +50,17 @@ cd $GARM_SOURCE/cmd/garm-cli
|
||||||
GOOS=linux GOARCH=amd64 go build -mod vendor \
|
GOOS=linux GOARCH=amd64 go build -mod vendor \
|
||||||
-o $BUILD_DIR/linux/amd64/garm-cli \
|
-o $BUILD_DIR/linux/amd64/garm-cli \
|
||||||
-tags osusergo,netgo,sqlite_omit_load_extension \
|
-tags osusergo,netgo,sqlite_omit_load_extension \
|
||||||
-ldflags "-extldflags '-static' -s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=$VERSION" .
|
-ldflags "-extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$VERSION" .
|
||||||
GOOS=linux GOARCH=arm64 CC=aarch64-linux-musl-gcc go build -mod vendor \
|
GOOS=linux GOARCH=arm64 CC=aarch64-linux-musl-gcc go build -mod vendor \
|
||||||
-o $BUILD_DIR/linux/arm64/garm-cli \
|
-o $BUILD_DIR/linux/arm64/garm-cli \
|
||||||
-tags osusergo,netgo,sqlite_omit_load_extension \
|
-tags osusergo,netgo,sqlite_omit_load_extension \
|
||||||
-ldflags "-extldflags '-static' -s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=$VERSION" .
|
-ldflags "-extldflags '-static' -s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$VERSION" .
|
||||||
|
|
||||||
# Windows
|
# Windows
|
||||||
GOOS=windows GOARCH=amd64 go build -mod vendor \
|
GOOS=windows GOARCH=amd64 go build -mod vendor \
|
||||||
-o $BUILD_DIR/windows/amd64/garm-cli.exe \
|
-o $BUILD_DIR/windows/amd64/garm-cli.exe \
|
||||||
-tags osusergo,netgo,sqlite_omit_load_extension \
|
-tags osusergo,netgo,sqlite_omit_load_extension \
|
||||||
-ldflags "-s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=$VERSION" .
|
-ldflags "-s -w -X github.com/cloudbase/garm/util/appdefaults.Version=$VERSION" .
|
||||||
|
|
||||||
|
|
||||||
git checkout $CURRENT_BRANCH || true
|
git checkout $CURRENT_BRANCH || true
|
||||||
|
|
|
||||||
|
|
@ -31,3 +31,12 @@ const (
|
||||||
// metrics data update interval
|
// metrics data update interval
|
||||||
DefaultMetricsUpdateInterval = 60 * time.Second
|
DefaultMetricsUpdateInterval = 60 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var Version string
|
||||||
|
|
||||||
|
func GetVersion() string {
|
||||||
|
if Version == "" {
|
||||||
|
Version = "v0.0.0-unknown"
|
||||||
|
}
|
||||||
|
return Version
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue