diff --git a/README.md b/README.md index 3ec4743..10a2486 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmd/server/server.go b/cmd/server/server.go index 59f89d2..807f5ac 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -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" ) @@ -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") diff --git a/examples/kubernetes/deployment/k6build.yaml b/examples/kubernetes/deployment/k6build.yaml index d0182bb..9dd5513 100644 --- a/examples/kubernetes/deployment/k6build.yaml +++ b/examples/kubernetes/deployment/k6build.yaml @@ -45,6 +45,8 @@ spec: - "http://cachesrv:9000/cache" - "-e" - "CGO_ENABLED=1" + - "--catalog" + - "catalog.json" volumeMounts: - mountPath: "/home/k6build" name: catalog diff --git a/go.mod b/go.mod index a70c4b1..452a49b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index be4adae..5c9e7b9 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/local/local.go b/pkg/local/local.go index a4db3e3..5b94893 100644 --- a/pkg/local/local.go +++ b/pkg/local/local.go @@ -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 @@ -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{ diff --git a/pkg/local/testutils.go b/pkg/local/testutils.go index 3f9575b..c976f0e 100644 --- a/pkg/local/testutils.go +++ b/pkg/local/testutils.go @@ -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) }