Server: Switch from separate server & cli to a unified grafana binary (#58286)

* avoid the need for a second bulky binary for grafana-cli

* look for grafana-server in $PATH as well as same directory

* implement unified "grafana" command

* update dockerfiles, fix grafana-cli -v

* update packaging to work with single binary

- add wrapper scripts for grafana and grafana-server
- update and sync package files
- implement --sign flag of build package command
- stop packaging scripts folder, they are not useful for end users
- add support for --configOverrides in server command
- remove unused nfpm.yaml config file

* windows support
This commit is contained in:
Dan Cech
2022-11-22 11:53:43 -05:00
committed by GitHub
parent 824a562b03
commit de99ce139c
28 changed files with 480 additions and 330 deletions

View File

@ -1,11 +1,9 @@
package commands
import (
"fmt"
"os"
"runtime"
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
@ -13,18 +11,10 @@ import (
)
// RunCLI is the entrypoint for the grafana-cli command. It returns the exit code for the grafana-cli program.
func RunCLI(version string) int {
setupLogging()
app := &cli.App{
Name: "Grafana CLI",
Authors: []*cli.Author{
{
Name: "Grafana Project",
Email: "hello@grafana.com",
},
},
Version: version,
func CLICommand(version string) *cli.Command {
return &cli.Command{
Name: "cli",
Usage: "run the grafana cli",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "pluginsDir",
@ -64,39 +54,19 @@ func RunCLI(version string) int {
Name: "config",
Usage: "Path to config file",
},
cli.VersionFlag,
},
Commands: Commands,
CommandNotFound: cmdNotFound,
}
Subcommands: Commands,
Before: func(c *cli.Context) error {
// backward-compatible handling for cli version flag
if c.Bool("version") {
cli.ShowVersion(c)
os.Exit(0)
}
app.Before = func(c *cli.Context) error {
services.Init(version, c.Bool("insecure"), c.Bool("debug"))
return nil
}
if err := app.Run(os.Args); err != nil {
logger.Errorf("%s: %s %s\n", color.RedString("Error"), color.RedString("✗"), err)
return 1
}
return 0
}
func setupLogging() {
for _, f := range os.Args {
if f == "-d" || f == "--debug" || f == "-debug" {
logger.SetDebug(true)
}
logger.SetDebug(c.Bool("debug"))
services.Init(version, c.Bool("insecure"), c.Bool("debug"))
return nil
},
}
}
func cmdNotFound(c *cli.Context, command string) {
fmt.Printf(
"%s: '%s' is not a %s command. See '%s --help'.\n",
c.App.Name,
command,
c.App.Name,
os.Args[0],
)
os.Exit(1)
}