Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs/howto: Use a custom registry with the Go API #190

Open
jpluscplusm opened this issue Jan 3, 2025 · 0 comments
Open

docs/howto: Use a custom registry with the Go API #190

jpluscplusm opened this issue Jan 3, 2025 · 0 comments

Comments

@jpluscplusm
Copy link
Collaborator

We don't currently cover the use of a custom module registry with the Go API either on https://cuelang.org/docs/tutorial/using-modules-with-go-api/ or https://cuelang.org/docs/tutorial/working-with-a-custom-module-registry/.

We should address this -- possibly by including an example on the latter page, although that page is already quite long.

Original Discord thread that contains some useful pointers:

https://discord.com/channels/1238032673109311508/1324707977126608969/1324707977126608969

go api with custom registry
[11:56] 
OP
 Viacheslav Terdunov: There's example of using Go API with the Central modules registry https://cuelang.org/docs/tutorial/using-modules-with-go-api/#step-7

Could you please help me understand how to work with a custom registry?
I'm not sure if this is the correct way to build a modregistry.Registry instance
How can I configure the registry address and pathEncoding: "hashAsTag" (I'm using AWS ECR as an OCI repo)

I've tried something like this
resolver, _ := modconfig.NewResolver(nil)
client := modregistry.NewClientWithResolver(resolver)
reg, _ := modcache.New(client, "")

# then load
buildInstances := load.Instances(cuesFiles, &load.Config{
    Dir:      ".",
    Registry: reg,
})
 
[12:54]mvdan: have you seen https://pkg.go.dev/cuelang.org/go/cue/load#example-package-ExternalModules ?
[12:56]mvdan: cuelang.org should have a little bit of content about using the Go API with custom registries. https://cuelang.org/docs/tutorial/using-modules-with-go-api/ covers the Go API, and https://cuelang.org/docs/tutorial/working-with-a-custom-module-registry/ covers custom registries, but we don't have a combination of both. I think a small example in the latter page makes sense.
[13:57]mvdan: I also think we should nudge cue/load users towards setting CUE_REGISTRY in load.Config.Env; even though it's a stringy API, it's much higher level and easier to use than chaining modconfig, modcache, and modregistry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant