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:
parent
435aaf81d2
commit
d117689aea
20
.drone.yml
20
.drone.yml
@ -317,8 +317,9 @@ steps:
|
||||
image: grafana/build-container:1.5.9
|
||||
name: build-backend
|
||||
- commands:
|
||||
- ./bin/grabpl build-frontend --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||
- ./bin/build build-frontend --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||
depends_on:
|
||||
- compile-build-cmd
|
||||
- gen-version
|
||||
- yarn-install
|
||||
environment:
|
||||
@ -1109,8 +1110,9 @@ steps:
|
||||
image: grafana/build-container:1.5.9
|
||||
name: build-backend
|
||||
- commands:
|
||||
- ./bin/grabpl build-frontend --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||
- ./bin/build build-frontend --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||
depends_on:
|
||||
- compile-build-cmd
|
||||
- gen-version
|
||||
- yarn-install
|
||||
environment:
|
||||
@ -1818,8 +1820,9 @@ steps:
|
||||
image: grafana/build-container:1.5.9
|
||||
name: build-backend
|
||||
- commands:
|
||||
- ./bin/grabpl build-frontend --jobs 8 --edition oss ${DRONE_TAG}
|
||||
- ./bin/build build-frontend --jobs 8 --edition oss ${DRONE_TAG}
|
||||
depends_on:
|
||||
- compile-build-cmd
|
||||
- gen-version
|
||||
- yarn-install
|
||||
environment:
|
||||
@ -2458,8 +2461,9 @@ steps:
|
||||
image: grafana/build-container:1.5.9
|
||||
name: build-backend
|
||||
- commands:
|
||||
- ./bin/grabpl build-frontend --jobs 8 --edition enterprise ${DRONE_TAG}
|
||||
- ./bin/build build-frontend --jobs 8 --edition enterprise ${DRONE_TAG}
|
||||
depends_on:
|
||||
- compile-build-cmd
|
||||
- gen-version
|
||||
- yarn-install
|
||||
environment:
|
||||
@ -3768,8 +3772,9 @@ steps:
|
||||
image: grafana/build-container:1.5.9
|
||||
name: build-backend
|
||||
- commands:
|
||||
- ./bin/grabpl build-frontend --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||
- ./bin/build build-frontend --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||
depends_on:
|
||||
- compile-build-cmd
|
||||
- gen-version
|
||||
- yarn-install
|
||||
environment:
|
||||
@ -4353,8 +4358,9 @@ steps:
|
||||
image: grafana/build-container:1.5.9
|
||||
name: build-backend
|
||||
- commands:
|
||||
- ./bin/grabpl build-frontend --jobs 8 --edition enterprise --build-id ${DRONE_BUILD_NUMBER}
|
||||
- ./bin/build build-frontend --jobs 8 --edition enterprise --build-id ${DRONE_BUILD_NUMBER}
|
||||
depends_on:
|
||||
- compile-build-cmd
|
||||
- gen-version
|
||||
- yarn-install
|
||||
environment:
|
||||
@ -5146,6 +5152,6 @@ kind: secret
|
||||
name: gcp_upload_artifacts_key
|
||||
---
|
||||
kind: signature
|
||||
hmac: a6fff8b3e3e8664ef3e98e3acb2c68aaecdd2eb44fa40bd73ded8322564fb2fa
|
||||
hmac: eac88e68cfaee99bc5569b7af5d8c7ebeeac691e5ea3b9f3b9b18e4327d87b21
|
||||
|
||||
...
|
||||
|
2
go.mod
2
go.mod
@ -244,7 +244,9 @@ require (
|
||||
github.com/blugelabs/bluge v0.1.9
|
||||
github.com/blugelabs/bluge_segment_api v0.2.0
|
||||
github.com/getkin/kin-openapi v0.94.0
|
||||
github.com/go-git/go-git v4.7.0+incompatible
|
||||
github.com/golang-migrate/migrate/v4 v4.7.0
|
||||
github.com/google/go-github/v31 v31.0.0
|
||||
github.com/google/go-github/v45 v45.2.0
|
||||
github.com/grafana/dskit v0.0.0-20211011144203-3a88ec0b675f
|
||||
github.com/grafana/thema v0.0.0-20220726124731-b8017e278cc1
|
||||
|
4
go.sum
4
go.sum
@ -872,6 +872,8 @@ github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4u
|
||||
github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
|
||||
github.com/go-git/go-billy/v5 v5.3.1 h1:CPiOUAzKtMRvolEKw+bG1PLRpT7D3LIs3/3ey4Aiu34=
|
||||
github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
|
||||
github.com/go-git/go-git v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA=
|
||||
github.com/go-git/go-git v4.7.0+incompatible/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.2.1 h1:n9gGL1Ct/yIw+nfsfr8s4+sbhT+Ncu2SubfXjIWgci8=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.2.1/go.mod h1:K8zd3kDUAykwTdDCr+I0per6Y6vMiRR/nnVTBtavnB0=
|
||||
github.com/go-git/go-git/v5 v5.4.2 h1:BXyZu9t0VkbiHtqrsvdq39UDhGJTl1h55VW6CSC4aY4=
|
||||
@ -1213,6 +1215,8 @@ github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||
github.com/google/go-github/v31 v31.0.0 h1:JJUxlP9lFK+ziXKimTCprajMApV1ecWD4NB6CCb0plo=
|
||||
github.com/google/go-github/v31 v31.0.0/go.mod h1:NQPZol8/1sMoWYGN2yaALIBytu17gAWfhbweiEed3pM=
|
||||
github.com/google/go-github/v45 v45.2.0 h1:5oRLszbrkvxDDqBCNj2hjDZMKmvexaZ1xw/FCD+K3FI=
|
||||
github.com/google/go-github/v45 v45.2.0/go.mod h1:FObaZJEDSTa/WGCzZ2Z3eoCDXWJKMenWWTrd8jrta28=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
|
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
|
||||
}
|
@ -406,12 +406,12 @@ def build_frontend_step(edition, ver_mode):
|
||||
# TODO: Use percentage for num jobs
|
||||
if ver_mode == 'release':
|
||||
cmds = [
|
||||
'./bin/grabpl build-frontend --jobs 8 ' + \
|
||||
'./bin/build build-frontend --jobs 8 ' + \
|
||||
'--edition {} ${{DRONE_TAG}}'.format(edition),
|
||||
]
|
||||
else:
|
||||
cmds = [
|
||||
'./bin/grabpl build-frontend --jobs 8 --edition {} '.format(edition) + \
|
||||
'./bin/build build-frontend --jobs 8 --edition {} '.format(edition) + \
|
||||
'--build-id {}'.format(build_no),
|
||||
]
|
||||
|
||||
@ -422,6 +422,7 @@ def build_frontend_step(edition, ver_mode):
|
||||
'NODE_OPTIONS': '--max_old_space_size=8192',
|
||||
},
|
||||
'depends_on': [
|
||||
'compile-build-cmd',
|
||||
'gen-version',
|
||||
'yarn-install',
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user