mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CI: move grabpl build-frontend from grabpl to grafana (#53073)
* move grabpl build-frontend
This commit is contained in:
38
pkg/build/cmd/buildfrontend.go
Normal file
38
pkg/build/cmd/buildfrontend.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/build/errutil"
|
||||
"github.com/grafana/grafana/pkg/build/frontend"
|
||||
"github.com/grafana/grafana/pkg/build/syncutil"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func BuildFrontend(c *cli.Context) error {
|
||||
version := ""
|
||||
if c.NArg() == 1 {
|
||||
version = strings.TrimPrefix(c.Args().Get(0), "v")
|
||||
}
|
||||
|
||||
cfg, mode, err := frontend.GetConfig(c, version)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p := syncutil.NewWorkerPool(cfg.NumWorkers)
|
||||
defer p.Close()
|
||||
|
||||
g, _ := errutil.GroupWithContext(c.Context)
|
||||
if err := frontend.Build(mode, frontend.GrafanaDir, p, g); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.Wait(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("Successfully built Grafana front-end!")
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -25,6 +25,17 @@ func main() {
|
||||
&buildIDFlag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "build-frontend",
|
||||
Usage: "Build front-end artifacts",
|
||||
ArgsUsage: "[version]",
|
||||
Action: ArgCountWrapper(1, BuildFrontend),
|
||||
Flags: []cli.Flag{
|
||||
&jobsFlag,
|
||||
&editionFlag,
|
||||
&buildIDFlag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "build-docker",
|
||||
Usage: "Build Grafana Docker images",
|
||||
|
||||
42
pkg/build/frontend/build.go
Normal file
42
pkg/build/frontend/build.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package frontend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/grafana/grafana/pkg/build/config"
|
||||
"github.com/grafana/grafana/pkg/build/errutil"
|
||||
"github.com/grafana/grafana/pkg/build/syncutil"
|
||||
)
|
||||
|
||||
// Build builds the Grafana front-end
|
||||
func Build(edition config.Edition, grafanaDir string, p syncutil.WorkerPool, g *errutil.Group) error {
|
||||
log.Printf("Building %s frontend in %q", edition, grafanaDir)
|
||||
grafanaDir, err := filepath.Abs(grafanaDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, dpath := range []string{"tmp", "public_gen", "public/build"} {
|
||||
dpath = filepath.Join(grafanaDir, dpath)
|
||||
if err := os.RemoveAll(dpath); err != nil {
|
||||
return fmt.Errorf("failed to remove %q: %w", dpath, err)
|
||||
}
|
||||
}
|
||||
|
||||
p.Schedule(g.Wrap(func() error {
|
||||
cmd := exec.Command("yarn", "run", "build")
|
||||
cmd.Dir = grafanaDir
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("failed to build %s frontend with webpack: %s", edition, output)
|
||||
}
|
||||
|
||||
log.Printf("Finished building %s frontend", edition)
|
||||
return nil
|
||||
}))
|
||||
|
||||
return nil
|
||||
}
|
||||
30
pkg/build/frontend/config.go
Normal file
30
pkg/build/frontend/config.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package frontend
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/build/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
const GrafanaDir = "."
|
||||
|
||||
func GetConfig(c *cli.Context, version string) (config.Config, config.Edition, error) {
|
||||
cfg := config.Config{
|
||||
NumWorkers: c.Int("jobs"),
|
||||
GitHubToken: c.String("github-token"),
|
||||
PackageVersion: version,
|
||||
}
|
||||
|
||||
mode := config.Edition(c.String("edition"))
|
||||
|
||||
if version == "" {
|
||||
buildID := c.String("build-id")
|
||||
var err error
|
||||
version, err = config.GetGrafanaVersion(buildID, GrafanaDir)
|
||||
cfg.PackageVersion = version
|
||||
if err != nil {
|
||||
return config.Config{}, config.EditionOSS, cli.Exit(err.Error(), 1)
|
||||
}
|
||||
}
|
||||
|
||||
return cfg, mode, nil
|
||||
}
|
||||
Reference in New Issue
Block a user