#How can I reference a built container (
1 messages ยท Page 1 of 1 (latest)
You can't directly reference something that just exists in the cache, but maybe with some more context I can help you solve it ๐
If you don't mind reading my "Noob ahoy" thread. ๐ You can get an idea of what I'm trying to do.
In the end, I'm trying to build a container and publish it to Docker Hub with an access token.
I think what you're looking for is this part #1225725578628300802 message
So if your function dagger call build ... returns a Container, you can chain on container related things just like in the SDK. So you could say dagger call build ... publish --address dockerhub.io/scott/foo for example. For authentication, you can either docker login before running the dagger command, or use with-registry-auth like dagger call build ... with-registry-auth ... publish --address ...
Ah. I remember seeing something on chaining function calls. Ok.
The only thing I'm not getting is the with-registry-auth? Is there something I can read about that?
You can also do it in code if you wanted to do that instead, like
func (m *MyModule) Publish(context *Directory, address string, token *Secret) (string, error) {
return m.Build(context).WithRegistryAuth( ... token ...).Publish(address)
}
Here's the godocs for withregistryauth: https://pkg.go.dev/dagger.io/dagger#Container.WithRegistryAuth
I'll see if I can find a good cli example
That looks like it builds and publishes. So, theoretically, I wouldn't need the build function. ๐ค
So, no chaining needed.
C'mon... that's too easy... ๐
Yeah if publishing is a common workflow, I'd totally write a function for it like that. Typically if I end up chaining the same things on a function frequently, it's a sign to me that it should be a new function
the cool thing with having one that just does a build and returns a container is that from the cli you could do lots of things like publish, run it, run more commands, enter a shell, etc
Yeah, I see. But, my goal is what you just gave me with the Publish function.
Perfect, yeah if that's all you need then you can add a .Publish() to your existing build function
This is what I came up with.
func (m *ZeusCi) Publish(
ctx context.Context,
directory *Directory,
imageName string,
address string,
username string,
token *Secret) (string, error) {
return m.BuildImage(ctx, imageName, directory).WithRegistryAuth( address, username, token).Publish(ctx, address)
}
m.Build doesn't seem to exist.
Sorry yeah I forgot what it was called in the other thread, I was referring to your BuildContainer function that you already had
but with the Directory you could do directory.Build() from there
The last piece missing.
The tag will go in the publish address. I don't think there's a way to do multiple tags in one publish at the moment unless I'm forgetting something
I only need one tag. ๐
perfect, yeah it'll be in the address passed to Publish
Getting this:
Error: failed to get value for argument "token": secret env var not found: "dck..."
Run 'dagger call publish --help' for usage.
Ah , so to pass *Secrets from the CLI by default they come from your environment, like dagger call publish ... --token DOCKERHUB_TOKEN
I'm reading about secrets in the docs..
Thanks @timid oasis for the great help.
Glad you got it working!!
@timid oasis - I'm hoping you can point me in a direction. How would I use the client to get something done similar to this function?
func (m *MyModule) Publish(
ctx context.Context,
directory *Directory,
imageName string,
address string,
username string,
token *Secret) (string, error) {
return m.BuildImage(ctx, imageName, directory).WithRegistryAuth(address, username, token).Publish(ctx, address)
}
Hey sorry not sure what you mean, can you elaborate on what you want to do?
I'm wanting to not use the CLI, but rather have a higher level program to run Dagger functionality. Basically, calling Dagger to do its thing programmatically. One of the things/ tasks is the above publishing functionality.
Ah, so you're wanting to use the SDK in a Go program instead of the dagger cli and modules/functions?
Yes. I'm just not getting the cross-over. There is one or more pieces of the puzzle on what is going on in Dagger for me to understand the difference between "using the SDK" and using a function via dagger call.
Understood! The code would look roughly like this: https://archive.docs.dagger.io/0.9/cookbook#publish-image-to-registry
The actual sdk functions look the same either way, the difference is if you're using the dagger cli and functions, the dagger session is managed for you. So if you're using the SDK in a Go program, you have to create an instance of the client, handle inputs/outputs in your code, etc
Filesystem
Ok. I was looking at that example. But, I was thinking it is no longer valid because the new docs and the new Dagger function/ CLI way of doing things. Let me run with this. Theoretically, if I just run that example code as a go application and I set the client up correctly, then the same work will be accomplished by Dagger, right?
Now to figure out how to set up the client to work with the Dagger Engine running in my k8s cluster....
Yes exactly! The archived docs are still valid, just not everything has been brought forward to the new docs yet. When we released modules/functions we did a hard cut in the docs to modules/functions even though the previous way is still valid
the environment variables should be the same, i.e. _EXPERIMENTAL_DAGGER_RUNNER_HOST
yup!
Ok. I'm off for the day. I'll be trying this out tomorrow morning. Thanks Kyle!
Good luck! Drop any questions here and I'll help out when I can!