[v9.3.x] Server: Switch from separate server & cli to a unified grafana binary (#62443)

* 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

(cherry picked from commit de99ce139c)

* Build: don't remove grafana-server and grafana-cli binaries from deb and rpm packages (#59890)

* don't remove grafana-server and grafana-cli binaries from /usr/share/grafana/bin in deb and rpm packages

* don't add config overrides in /usr/sbin/grafana-server

---------

Co-authored-by: Dan Cech <dcech@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2023-02-02 10:41:18 +02:00
committed by GitHub
co-authored by Dan Cech
parent d3a33de503
commit e7c8704090
28 changed files with 447 additions and 331 deletions
+16 -46
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)
}
+2 -1
View File
@@ -78,7 +78,8 @@ func initCfg(cmd *utils.ContextCommandLine) (*setting.Cfg, error) {
cfg, err := setting.NewCfgFromArgs(setting.CommandLineArgs{
Config: cmd.ConfigFile(),
HomePath: cmd.HomePath(),
Args: append(configOptions, cmd.Args().Slice()...), // tailing arguments have precedence over the options string
// tailing arguments have precedence over the options string
Args: append(configOptions, cmd.Args().Slice()...),
})
if err != nil {
+2 -5
View File
@@ -3,12 +3,9 @@ package main
import (
"os"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands"
"github.com/grafana/grafana/pkg/util/cmd"
)
// Version is overridden by build flags
var version = "main"
func main() {
os.Exit(commands.RunCLI(version))
os.Exit(cmd.RunGrafanaCmd("cli"))
}