Skip to content

Commit

Permalink
Merge pull request #35 from grafana/use-catalog-from-k6registry
Browse files Browse the repository at this point in the history
update k6catalog
  • Loading branch information
pablochacin authored Sep 9, 2024
2 parents 5b30579 + f7538b1 commit d6b91f5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ k6build server -e GOPROXY=http://localhost:80

```
--cache-url string cache server url (default "http://localhost:9000")
-c, --catalog string dependencies catalog (default "catalog.json")
-c, --catalog string dependencies catalog. Can be path to a local file or an URL (default "https://registry.k6.io/catalog.json")
-g, --copy-go-env copy go environment (default true)
-e, --env stringToString build environment variables (default [])
-h, --help help for server
Expand Down
9 changes: 8 additions & 1 deletion cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/grafana/k6build"
"github.com/grafana/k6build/pkg/local"
server "github.com/grafana/k6build/pkg/server"
"github.com/grafana/k6catalog"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -86,7 +87,13 @@ func New() *cobra.Command {
},
}

cmd.Flags().StringVarP(&config.Catalog, "catalog", "c", "catalog.json", "dependencies catalog")
cmd.Flags().StringVarP(
&config.Catalog,
"catalog",
"c",
k6catalog.DefaultCatalogURL,
"dependencies catalog. Can be path to a local file or an URL",
)
cmd.Flags().StringVar(&config.CacheURL, "cache-url", "http://localhost:9000", "cache server url")
cmd.Flags().BoolVarP(&config.Verbose, "verbose", "v", false, "print build process output")
cmd.Flags().BoolVarP(&config.CopyGoEnv, "copy-go-env", "g", true, "copy go environment")
Expand Down
2 changes: 2 additions & 0 deletions examples/kubernetes/deployment/k6build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ spec:
- "http://cachesrv:9000/cache"
- "-e"
- "CGO_ENABLED=1"
- "--catalog"
- "catalog.json"
volumeMounts:
- mountPath: "/home/k6build"
name: catalog
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ go 1.22.2

require (
github.com/grafana/clireadme v0.1.0
github.com/grafana/k6catalog v0.1.0
github.com/grafana/k6catalog v0.2.3
github.com/grafana/k6foundry v0.2.0
github.com/spf13/cobra v1.8.1
)

require github.com/Masterminds/semver/v3 v3.3.0 // indirect

require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/google/go-cmp v0.6.0
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/grafana/clireadme v0.1.0 h1:KYEYSnYdSzmHf3bufaK6fQZ5j4dzvM/T+G6Ba+qNnAM=
github.com/grafana/clireadme v0.1.0/go.mod h1:Wy4KIG2ZBGMYAYyF9l7qAy+yoJVasqk/txsRgoRI3gc=
github.com/grafana/k6catalog v0.1.0 h1:jLmbmB3EUJ+zyQG3hWy6dWbtMjvTkvJNx1d4LX8it6I=
github.com/grafana/k6catalog v0.1.0/go.mod h1:8R9eXAh2nb69+drkj0rZ4aemso0jcwCbPP6Q3E5LqCw=
github.com/grafana/k6catalog v0.2.3 h1:Gol46qra9yjPYSrxLj6CDKcdY/DUEprM4Xd4TCNPkfA=
github.com/grafana/k6catalog v0.2.3/go.mod h1:ozCf9+KBw63lNrRiZtp7CvzA7V0ATQuOQN2IoG2irw4=
github.com/grafana/k6foundry v0.2.0 h1:+aE5wuCP0XNGNsxM7UiPj9hyw4RdWeW929PuGwLWIlg=
github.com/grafana/k6foundry v0.2.0/go.mod h1:b6n4InFgXl+3yPobmlyJfcJmLozU9CI9IIUuq8YqEiM=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down
6 changes: 3 additions & 3 deletions pkg/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type BuildServiceConfig struct {
// Set build environment variables
// Can be used for setting (or overriding, if CopyGoEnv is true) go environment variables
BuildEnv map[string]string
// path to catalog's json file
// path to catalog's json file. Can be a file path or a URL
Catalog string
// url to remote cache service
CacheURL string
Expand All @@ -48,9 +48,9 @@ type localBuildSrv struct {

// NewBuildService creates a local build service using the given configuration
func NewBuildService(ctx context.Context, config BuildServiceConfig) (k6build.BuildService, error) {
catalog, err := k6catalog.NewCatalogFromJSON(config.Catalog)
catalog, err := k6catalog.NewCatalog(ctx, config.Catalog)
if err != nil {
return nil, fmt.Errorf("creating catalog %w", err)
return nil, fmt.Errorf("getting catalog %w", err)
}

builderOpts := k6foundry.NativeBuilderOpts{
Expand Down
2 changes: 1 addition & 1 deletion pkg/local/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func SetupTestLocalBuildService(t *testing.T) (k6build.BuildService, error) {
return nil, fmt.Errorf("setting up test builder %w", err)
}

catalog, err := k6catalog.NewCatalogFromJSON("testdata/catalog.json")
catalog, err := k6catalog.NewCatalogFromFile("testdata/catalog.json")
if err != nil {
return nil, fmt.Errorf("setting up test builder %w", err)
}
Expand Down

0 comments on commit d6b91f5

Please sign in to comment.