2022-09-23 11:49:07 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
|
2022-12-14 05:32:45 -06:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
2022-09-23 11:49:07 -05:00
|
|
|
"github.com/grafana/grafana/pkg/build/config"
|
|
|
|
"github.com/grafana/grafana/pkg/build/gpg"
|
|
|
|
"github.com/grafana/grafana/pkg/build/packaging"
|
|
|
|
"github.com/grafana/grafana/pkg/build/syncutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Package(c *cli.Context) error {
|
|
|
|
metadata, err := GenerateMetadata(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
edition := config.Edition(c.String("edition"))
|
|
|
|
|
|
|
|
releaseMode, err := metadata.GetReleaseMode()
|
|
|
|
if err != nil {
|
2022-12-14 05:32:45 -06:00
|
|
|
return cli.Exit(err.Error(), 1)
|
2022-09-23 11:49:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
releaseModeConfig, err := config.GetBuildConfig(metadata.ReleaseMode.Mode)
|
|
|
|
if err != nil {
|
2022-12-14 05:32:45 -06:00
|
|
|
return cli.Exit(err.Error(), 1)
|
2022-09-23 11:49:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
cfg := config.Config{
|
2022-11-22 10:53:43 -06:00
|
|
|
NumWorkers: c.Int("jobs"),
|
|
|
|
SignPackages: c.Bool("sign"),
|
2022-09-23 11:49:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
variantStrs := strings.Split(c.String("variants"), ",")
|
|
|
|
variants := []config.Variant{}
|
|
|
|
for _, varStr := range variantStrs {
|
|
|
|
if varStr == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
variants = append(variants, config.Variant(varStr))
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(variants) == 0 {
|
|
|
|
variants = config.AllVariants
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Packaging Grafana version %q, version mode %s, %s edition, variants %s", metadata.GrafanaVersion, releaseMode.Mode,
|
|
|
|
edition, strings.Join(variantStrs, ","))
|
|
|
|
|
2022-11-22 10:53:43 -06:00
|
|
|
if cfg.SignPackages {
|
|
|
|
if err := gpg.LoadGPGKeys(&cfg); err != nil {
|
|
|
|
return cli.Exit(err, 1)
|
|
|
|
}
|
|
|
|
defer gpg.RemoveGPGFiles(cfg)
|
|
|
|
if err := gpg.Import(cfg); err != nil {
|
|
|
|
return cli.Exit(err, 1)
|
|
|
|
}
|
2022-09-23 11:49:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
p := syncutil.NewWorkerPool(cfg.NumWorkers)
|
|
|
|
defer p.Close()
|
|
|
|
|
|
|
|
if err := packaging.PackageGrafana(ctx, metadata.GrafanaVersion, ".", cfg, edition, variants, releaseModeConfig.PluginSignature.Sign, p); err != nil {
|
|
|
|
return cli.Exit(err, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Successfully packaged Grafana!")
|
|
|
|
return nil
|
|
|
|
}
|