-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Kevin Minehart <[email protected]>
- Loading branch information
1 parent
425950f
commit 13a0119
Showing
11 changed files
with
199 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ var app = &cli.App{ | |
ZipCommand, | ||
ValidateCommand, | ||
ProImageCommand, | ||
StorybookCommand, | ||
}, | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/grafana/grafana-build/pipelines" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var StorybookCommand = &cli.Command{ | ||
Name: "storybook", | ||
Action: PipelineActionWithPackageInput(pipelines.Storybook), | ||
Usage: "Using a grafana.tar.gz as input (ideally one built using the 'package' command), take the storybook files and upload them to the destination. This can be used to put Grafana's storybook assets into a bucket for external use.", | ||
Flags: JoinFlagsWithDefault( | ||
PackageInputFlags, | ||
PublishFlags, | ||
GCPFlags, | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package containers | ||
|
||
import ( | ||
"dagger.io/dagger" | ||
) | ||
|
||
// Storybook returns a dagger.Directory which contains the built storybook server. | ||
func Storybook(d *dagger.Client, src *dagger.Directory, opts *YarnCacheOpts, version, nodeVersion string) *dagger.Directory { | ||
c := NodeContainer(d, NodeImage(nodeVersion)). | ||
WithMountedDirectory("/src", src). | ||
WithWorkdir("/src") | ||
|
||
c = WithYarnCache(c, opts) | ||
|
||
c = c.WithExec([]string{"yarn", "install", "--immutable"}). | ||
WithExec([]string{"yarn", "run", "storybook:build"}) | ||
|
||
return c.Directory("./packages/grafana-ui/dist/storybook") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package pipelines | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"dagger.io/dagger" | ||
"github.com/grafana/grafana-build/containers" | ||
) | ||
|
||
func Storybook(ctx context.Context, d *dagger.Client, args PipelineArgs) error { | ||
packages, err := containers.GetPackages(ctx, d, args.PackageInputOpts, args.GCPOpts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Extract the package(s) | ||
for i, v := range args.PackageInputOpts.Packages { | ||
var ( | ||
name = ReplaceExt(v, "") | ||
targz = packages[i] | ||
) | ||
|
||
// We can't use path.Join here because publishopts.Destination might have a URL scheme which will get santizied, and we can't use filepath.Join because Windows would use \\ filepath separators. | ||
dst := strings.Join([]string{args.PublishOpts.Destination, name, "storybook"}, "/") | ||
|
||
log.Println("Copying storybook assets for", name, "to", dst) | ||
folder := fmt.Sprintf("/src/%s", name) | ||
|
||
// gcloud rsync the storybook folder to ['dst']/storybook | ||
storybook := d.Container().From("busybox"). | ||
WithFile("/src/grafana.tar.gz", targz). | ||
WithExec([]string{"mkdir", "-p", folder}). | ||
WithExec([]string{"tar", "--strip-components=1", "-xzf", "/src/grafana.tar.gz", "-C", folder}). | ||
Directory(folder + "/storybook") | ||
|
||
dst, err := containers.PublishDirectory(ctx, d, storybook, args.GCPOpts, dst) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Fprintln(os.Stdout, dst) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"sort" | ||
"testing" | ||
) | ||
|
||
var storybookMapping = []m{ | ||
{ | ||
input: "gs://bucket/tag/grafana_v1.2.3_102_linux_amd64/storybook", | ||
output: []string{ | ||
"artifacts/storybook/v1.2.3", | ||
}, | ||
}, | ||
{ | ||
input: "gs://bucket/tag/grafana-enterprise_v1.2.3_102_linux_amd64/storybook", | ||
output: []string{ | ||
"artifacts/storybook/v1.2.3", | ||
}, | ||
}, | ||
{ | ||
input: "gs://bucket/tag/grafana-pro_v1.2.3_102_linux_amd64/storybook", | ||
output: []string{ | ||
"artifacts/storybook/v1.2.3", | ||
}, | ||
}, | ||
} | ||
|
||
func TestMoveStorybook(t *testing.T) { | ||
for _, v := range storybookMapping { | ||
out := StorybookHandler(v.input) | ||
|
||
if len(out) != len(v.output) { | ||
t.Errorf("expected %d in output but received %d\nexpected: %v\nreceived: %v", len(v.output), len(out), v.output, out) | ||
continue | ||
} | ||
sort.Strings(out) | ||
exp := v.output | ||
sort.Strings(exp) | ||
|
||
for i := range out { | ||
got := out[i] | ||
expect := exp[i] | ||
if expect != got { | ||
t.Errorf("\nExpected %s\nReceived %s", expect, got) | ||
} | ||
} | ||
} | ||
} |