[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:
co-authored by
Dan Cech
parent
d3a33de503
commit
e7c8704090
@@ -75,9 +75,13 @@ func PackageGrafana(
|
||||
if err := packageGrafana(ctx, edition, version, grafanaDir, variants, shouldSign, p); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := signRPMPackages(edition, cfg, grafanaDir); err != nil {
|
||||
return err
|
||||
|
||||
if cfg.SignPackages {
|
||||
if err := signRPMPackages(edition, cfg, grafanaDir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := checksumPackages(grafanaDir, edition); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -282,6 +286,7 @@ func shaFile(fpath string) error {
|
||||
|
||||
// createPackage creates a Linux package.
|
||||
func createPackage(srcDir string, options linuxPackageOptions) error {
|
||||
binary := "grafana"
|
||||
cliBinary := "grafana-cli"
|
||||
serverBinary := "grafana-server"
|
||||
|
||||
@@ -310,10 +315,15 @@ func createPackage(srcDir string, options linuxPackageOptions) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := fs.CopyFile(options.cliBinaryWrapperSrc, filepath.Join(packageRoot, "usr", "sbin", cliBinary)); err != nil {
|
||||
if err := fs.CopyFile(filepath.Join(options.wrapperFilePath, binary),
|
||||
filepath.Join(packageRoot, "usr", "sbin", binary)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := fs.CopyFile(filepath.Join(srcDir, "bin", serverBinary),
|
||||
if err := fs.CopyFile(filepath.Join(options.wrapperFilePath, cliBinary),
|
||||
filepath.Join(packageRoot, "usr", "sbin", cliBinary)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := fs.CopyFile(filepath.Join(options.wrapperFilePath, serverBinary),
|
||||
filepath.Join(packageRoot, "usr", "sbin", serverBinary)); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -329,20 +339,6 @@ func createPackage(srcDir string, options linuxPackageOptions) error {
|
||||
if err := fs.CopyRecursive(srcDir, filepath.Join(packageRoot, options.homeDir)); err != nil {
|
||||
return err
|
||||
}
|
||||
homeBinDir := filepath.Join(packageRoot, options.homeBinDir)
|
||||
if err := os.RemoveAll(homeBinDir); err != nil {
|
||||
return fmt.Errorf("failed to remove %q: %w", homeBinDir, err)
|
||||
}
|
||||
//nolint
|
||||
if err := os.MkdirAll(homeBinDir, 0o755); err != nil {
|
||||
return fmt.Errorf("failed to make directory %q: %w", homeBinDir, err)
|
||||
}
|
||||
// The grafana-cli binary is exposed through a wrapper to ensure a proper
|
||||
// configuration is in place. To enable that, we need to store the original
|
||||
// binary in a separate location to avoid conflicts.
|
||||
if err := fs.CopyFile(filepath.Join(srcDir, "bin", cliBinary), filepath.Join(homeBinDir, cliBinary)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := executeFPM(options, packageRoot, srcDir); err != nil {
|
||||
return err
|
||||
@@ -476,43 +472,6 @@ func copyBinaries(grafanaDir, tmpDir string, args grafana.BuildArgs, edition con
|
||||
return nil
|
||||
}
|
||||
|
||||
// copyScripts copies scripts from grafanaDir into tmpDir.
|
||||
func copyScripts(grafanaDir, tmpDir string) error {
|
||||
//nolint
|
||||
if err := os.MkdirAll(filepath.Join(tmpDir, "scripts"), 0o755); err != nil {
|
||||
return fmt.Errorf("failed to create dir %q: %w", filepath.Join(tmpDir, "scripts"), err)
|
||||
}
|
||||
scriptsDir := filepath.Join(grafanaDir, "scripts")
|
||||
infos, err := os.ReadDir(scriptsDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list files in %q: %w", scriptsDir, err)
|
||||
}
|
||||
for _, file := range infos {
|
||||
info, err := file.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
if info.Mode()&os.ModeSymlink != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
path := ""
|
||||
|
||||
path = filepath.Join(scriptsDir, info.Name())
|
||||
|
||||
if err := fs.CopyFile(path, filepath.Join(tmpDir, "scripts", info.Name())); err != nil {
|
||||
return fmt.Errorf("failed to copy %q to %q: %w", path, tmpDir, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// copyConfFiles copies configuration files from grafanaDir into tmpDir.
|
||||
func copyConfFiles(grafanaDir, tmpDir string) error {
|
||||
//nolint:gosec
|
||||
@@ -718,9 +677,6 @@ func realPackageVariant(ctx context.Context, v config.Variant, edition config.Ed
|
||||
if err := copyBinaries(grafanaDir, tmpDir, args, edition); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := copyScripts(grafanaDir, tmpDir); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := copyConfFiles(grafanaDir, tmpDir); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -774,7 +730,7 @@ func realPackageVariant(ctx context.Context, v config.Variant, edition config.Ed
|
||||
initdScriptSrc: filepath.Join(grafanaDir, "packaging", "deb", "init.d", "grafana-server"),
|
||||
defaultFileSrc: filepath.Join(grafanaDir, "packaging", "deb", "default", "grafana-server"),
|
||||
systemdFileSrc: filepath.Join(grafanaDir, "packaging", "deb", "systemd", "grafana-server.service"),
|
||||
cliBinaryWrapperSrc: filepath.Join(grafanaDir, "packaging", "wrappers", "grafana-cli"),
|
||||
wrapperFilePath: filepath.Join(grafanaDir, "packaging", "wrappers"),
|
||||
depends: []string{"adduser", "libfontconfig1"},
|
||||
}); err != nil {
|
||||
return err
|
||||
@@ -808,7 +764,7 @@ func realPackageVariant(ctx context.Context, v config.Variant, edition config.Ed
|
||||
initdScriptSrc: filepath.Join(grafanaDir, "packaging", "rpm", "init.d", "grafana-server"),
|
||||
defaultFileSrc: filepath.Join(grafanaDir, "packaging", "rpm", "sysconfig", "grafana-server"),
|
||||
systemdFileSrc: filepath.Join(grafanaDir, "packaging", "rpm", "systemd", "grafana-server.service"),
|
||||
cliBinaryWrapperSrc: filepath.Join(grafanaDir, "packaging", "wrappers", "grafana-cli"),
|
||||
wrapperFilePath: filepath.Join(grafanaDir, "packaging", "wrappers"),
|
||||
// chkconfig is depended on since our systemd service wraps a SysV init script, and that requires chkconfig
|
||||
depends: []string{"/sbin/service", "chkconfig", "fontconfig", "freetype", "urw-fonts"},
|
||||
}); err != nil {
|
||||
@@ -890,7 +846,7 @@ type linuxPackageOptions struct {
|
||||
initdScriptSrc string
|
||||
defaultFileSrc string
|
||||
systemdFileSrc string
|
||||
cliBinaryWrapperSrc string
|
||||
wrapperFilePath string
|
||||
|
||||
depends []string
|
||||
}
|
||||
@@ -930,7 +886,7 @@ func createZip(srcDir, version, variantStr, sfx, grafanaDir string) error {
|
||||
return fmt.Errorf("failed to create %q: %w", fpath, err)
|
||||
}
|
||||
defer func() {
|
||||
if err := tgt.Close(); err != nil {
|
||||
if err := tgt.Close(); err != nil && !errors.Is(err, os.ErrClosed) {
|
||||
log.Println(err)
|
||||
}
|
||||
}()
|
||||
@@ -1046,7 +1002,7 @@ func createTarball(srcDir, version, variantStr, sfx, grafanaDir string) error {
|
||||
return fmt.Errorf("failed to create %q: %w", fpath, err)
|
||||
}
|
||||
defer func() {
|
||||
if err := tgt.Close(); err != nil {
|
||||
if err := tgt.Close(); err != nil && !errors.Is(err, os.ErrClosed) {
|
||||
log.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user