#How can I reference a built container (

1 messages ยท Page 1 of 1 (latest)

timid oasis
#

You can't directly reference something that just exists in the cache, but maybe with some more context I can help you solve it ๐Ÿ™‚

woven hill
#

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.

timid oasis
#

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 ...

woven hill
#

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?

timid oasis
#

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)
}
woven hill
#

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... ๐Ÿ˜›

timid oasis
#

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

woven hill
#

Yeah, I see. But, my goal is what you just gave me with the Publish function.

timid oasis
#

Perfect, yeah if that's all you need then you can add a .Publish() to your existing build function

woven hill
#

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.

timid oasis
#

Sorry yeah I forgot what it was called in the other thread, I was referring to your BuildContainer function that you already had

woven hill
#

No worries! ๐Ÿ™‚

#

How can I tag the image?

timid oasis
#

but with the Directory you could do directory.Build() from there

woven hill
#

The last piece missing.

timid oasis
#

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

woven hill
#

I only need one tag. ๐Ÿ™‚

timid oasis
#

perfect, yeah it'll be in the address passed to Publish

woven hill
#

Getting this:

Error: failed to get value for argument "token": secret env var not found: "dck..."
Run 'dagger call publish --help' for usage.
timid oasis
#

Ah , so to pass *Secrets from the CLI by default they come from your environment, like dagger call publish ... --token DOCKERHUB_TOKEN

woven hill
#

I'm reading about secrets in the docs..

woven hill
#

Got my first container image built and published via Dagger!!!

woven hill
#

Thanks @timid oasis for the great help.

timid oasis
#

Glad you got it working!!

woven hill
#

@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)
}
timid oasis
woven hill
timid oasis
#

Ah, so you're wanting to use the SDK in a Go program instead of the dagger cli and modules/functions?

woven hill
#

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.

timid oasis
#

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

woven hill
#

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....

timid oasis
#

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

woven hill
#

So, as long as that is set, then the client too will know what to connect to?

#

Cool.

timid oasis
#

yup!

woven hill
#

Ok. I'm off for the day. I'll be trying this out tomorrow morning. Thanks Kyle!

timid oasis
#

Good luck! Drop any questions here and I'll help out when I can!