CI: Move upload-cdn subcommand from grabpl (#58957)
Move upload-cdn from grabpl
This commit is contained in:
+8
-8
@@ -1569,7 +1569,7 @@ steps:
|
|||||||
repo:
|
repo:
|
||||||
- grafana/grafana
|
- grafana/grafana
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl upload-cdn --edition oss
|
- ./bin/build upload-cdn --edition oss
|
||||||
depends_on:
|
depends_on:
|
||||||
- grafana-server
|
- grafana-server
|
||||||
environment:
|
environment:
|
||||||
@@ -2135,7 +2135,7 @@ steps:
|
|||||||
event:
|
event:
|
||||||
- tag
|
- tag
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl upload-cdn --edition oss
|
- ./bin/build upload-cdn --edition oss
|
||||||
depends_on:
|
depends_on:
|
||||||
- grafana-server
|
- grafana-server
|
||||||
environment:
|
environment:
|
||||||
@@ -2785,7 +2785,7 @@ steps:
|
|||||||
- success
|
- success
|
||||||
- failure
|
- failure
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl upload-cdn --edition enterprise
|
- ./bin/build upload-cdn --edition enterprise
|
||||||
depends_on:
|
depends_on:
|
||||||
- package
|
- package
|
||||||
environment:
|
environment:
|
||||||
@@ -2826,7 +2826,7 @@ steps:
|
|||||||
image: grafana/build-container:1.6.4
|
image: grafana/build-container:1.6.4
|
||||||
name: package-enterprise2
|
name: package-enterprise2
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl upload-cdn --edition enterprise2
|
- ./bin/build upload-cdn --edition enterprise2
|
||||||
depends_on:
|
depends_on:
|
||||||
- package-enterprise2
|
- package-enterprise2
|
||||||
environment:
|
environment:
|
||||||
@@ -4156,7 +4156,7 @@ steps:
|
|||||||
include:
|
include:
|
||||||
- packages/grafana-ui/**
|
- packages/grafana-ui/**
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl upload-cdn --edition oss
|
- ./bin/build upload-cdn --edition oss
|
||||||
depends_on:
|
depends_on:
|
||||||
- grafana-server
|
- grafana-server
|
||||||
environment:
|
environment:
|
||||||
@@ -4764,7 +4764,7 @@ steps:
|
|||||||
- success
|
- success
|
||||||
- failure
|
- failure
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl upload-cdn --edition enterprise
|
- ./bin/build upload-cdn --edition enterprise
|
||||||
depends_on:
|
depends_on:
|
||||||
- package
|
- package
|
||||||
environment:
|
environment:
|
||||||
@@ -4812,7 +4812,7 @@ steps:
|
|||||||
image: grafana/build-container:1.6.4
|
image: grafana/build-container:1.6.4
|
||||||
name: package-enterprise2
|
name: package-enterprise2
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl upload-cdn --edition enterprise2
|
- ./bin/build upload-cdn --edition enterprise2
|
||||||
depends_on:
|
depends_on:
|
||||||
- package-enterprise2
|
- package-enterprise2
|
||||||
environment:
|
environment:
|
||||||
@@ -5512,6 +5512,6 @@ kind: secret
|
|||||||
name: packages_secret_access_key
|
name: packages_secret_access_key
|
||||||
---
|
---
|
||||||
kind: signature
|
kind: signature
|
||||||
hmac: 77ae647c9addfcd9966d462ca9967b85a87e18adfe0e9e0a2c6b1cf5d7f42493
|
hmac: bdde811590573d22162d8305ced15080e8b20f2180b7491891c461427810a4b3
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|||||||
@@ -96,6 +96,14 @@ func main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "upload-cdn",
|
||||||
|
Usage: "Upload public/* to a cdn bucket",
|
||||||
|
Action: UploadCDN,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&editionFlag,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "shellcheck",
|
Name: "shellcheck",
|
||||||
Usage: "Run shellcheck on shell scripts",
|
Usage: "Run shellcheck on shell scripts",
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/build/config"
|
||||||
|
"github.com/grafana/grafana/pkg/build/gcloud/storage"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UploadCDN implements the sub-command "upload-cdn".
|
||||||
|
func UploadCDN(c *cli.Context) error {
|
||||||
|
if c.NArg() > 0 {
|
||||||
|
if err := cli.ShowSubcommandHelp(c); err != nil {
|
||||||
|
return cli.NewExitError(err.Error(), 1)
|
||||||
|
}
|
||||||
|
return cli.NewExitError("", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata, err := GenerateMetadata(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
version := metadata.GrafanaVersion
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err.Error(), 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
buildConfig, err := config.GetBuildConfig(metadata.ReleaseMode.Mode)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
edition := os.Getenv("EDITION")
|
||||||
|
log.Printf("Uploading Grafana CDN Assets, version %s, %s edition...", version, edition)
|
||||||
|
|
||||||
|
editionPath := ""
|
||||||
|
|
||||||
|
switch config.Edition(edition) {
|
||||||
|
case config.EditionOSS:
|
||||||
|
editionPath = "grafana-oss"
|
||||||
|
case config.EditionEnterprise:
|
||||||
|
editionPath = "grafana"
|
||||||
|
case config.EditionEnterprise2:
|
||||||
|
editionPath = os.Getenv("ENTERPRISE2_CDN_PATH")
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unrecognized edition %q", edition))
|
||||||
|
}
|
||||||
|
|
||||||
|
gcs, err := storage.New()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bucket := gcs.Bucket(buildConfig.Buckets.CDNAssets)
|
||||||
|
srcPath := buildConfig.Buckets.CDNAssetsDir
|
||||||
|
srcPath = filepath.Join(srcPath, editionPath, version)
|
||||||
|
|
||||||
|
if err := gcs.DeleteDir(c.Context, bucket, srcPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Printf("Successfully cleaned source: %s/%s\n", buildConfig.Buckets.CDNAssets, srcPath)
|
||||||
|
|
||||||
|
if err := gcs.CopyLocalDir(c.Context, "./public", bucket, srcPath, false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Successfully uploaded cdn static assets to: %s/%s!\n", buildConfig.Buckets.CDNAssets, srcPath)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -354,7 +354,7 @@ def upload_cdn_step(edition, ver_mode, trigger=None):
|
|||||||
'PRERELEASE_BUCKET': from_secret(prerelease_bucket)
|
'PRERELEASE_BUCKET': from_secret(prerelease_bucket)
|
||||||
},
|
},
|
||||||
'commands': [
|
'commands': [
|
||||||
'./bin/grabpl upload-cdn --edition {}'.format(edition),
|
'./bin/build upload-cdn --edition {}'.format(edition),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
if trigger and ver_mode in ("release-branch", "main"):
|
if trigger and ver_mode in ("release-branch", "main"):
|
||||||
|
|||||||
Reference in New Issue
Block a user